I'm trying to shrink a partition to match the size of another partition on another drive. I heard that I first have to shrink the filesystem to match. I am trying to do this with resize2fs
, but if I use the values in
cat /proc/partitions
major minor #blocks name
202 0 178257920 xvda
202 1 178249871 xvda1
202 32 47185920 xvdc
202 33 47184896 xvdc1
like this
ubuntu@asdf:~$ sudo resize2fs /dev/xvda1 47184896
I get
resize2fs 1.42.13 (17-May-2015)
The containing partition (or device) is only 44562467 (4k) blocks.
You requested a new size of 47184896 blocks.
I have a simliar problem when using parted
.
$ sudo parted /dev/xvda
GNU Parted 3.2
Using /dev/xvda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 1 94371839
Error: The location 94371839 is outside of the device /dev/xvda.
If I try to do resizepart 1 94371839
for '/dev/xvda1' in parted
I get Error: The location 94371839 is outside of the device /dev/xvda1.
when it's clearly within the block range of the device as shown with
sudo fdisk -l
Disk /dev/xvda: 170 GiB, 182536110080 bytes, 356515840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/xvda1 * 16065 356515806 356499742 170G 83 Linux
This is driving me nuts. How do I get the proper values for the filesystem size and partition size to use with resize2fs
and parted
?
resize2fs
doesn't misread the number of blocks. It is just using 4k blocks while /proc/partitions
is reporting 1k blocks.
356499742 x 512B sectors = 178249871 x 1K blocks = 44562467 x 4K blocks
With parted
, you can to configure the unit you want to use. It seems parted
uses MB by default, so you are asking to resize a 170GB partition to 94TB, which it rightly refuses.
Here is one way to do it correctly:
parted /dev/sdb GNU Parted 3.2 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) help unit unit UNIT set the default unit to UNIT UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %, kiB, MiB, GiB, TiB (parted) unit kiB (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 524288kiB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1024kiB 205824kiB 204800kiB primary ext3 2 205824kiB 410624kiB 204800kiB primary ext3 (parted) resizepart 1 200000 Warning: Shrinking a partition can cause data loss, are you sure you want to continue? Yes/No? Yes (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 524288kiB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1024kiB 200000kiB 198977kiB primary ext3 2 205824kiB 410624kiB 204800kiB primary ext3
User contributions licensed under CC BY-SA 3.0