sudo resizepart device partition length
device
example mmcblk0
partition
length sectors
Tells the kernel about the new size of the specified partition.
Doesn't manipulate partitions on a block device.
sudo resize2fs [ -fFpPMbs ] [ -d debug-flags ] [ -S RAID-stride ] [ -z undo_file ] device [ newSize ]
Resizes ext2, ext3, or ext4 unmounted file system. (Run from directory /etc/init.d
to resize root fs)
Can expand the size even if the filesystem is mounted,
newSize
can be suffixed by s
, K
, M
, or G
, for 512 byte sectors, kilobytes, …,
can not be larger than the size of the partition.
Default: blocksize of the filesystem.
Defaults to the size of the partition.
Does not change the size of the partition.
If using the logical volume manager lvm use lvextend
.
To shrink an ext partition, first use resize2fs
to shrink the size of filesystem(not online).
Then use parted or fdisk
to shrink the size of the partition. Do not make it smaller than the new size of the filesystem!
Attempt to shrink root on raspberry pi buster from 6GB:
sudo resize2fs -F /dev/mmcblk0p2 5500M resize2fs 1.44.5 (15-Dec-2018) Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supportedOn another system:
df # determine where SD card is mounted sudo umount sdc* # sudo e2fsck -f /dev/sdc2 # requested by resize2fs sudo resize2fs -F -d63 -p /dev/sdc2 5500M # Flush buffers, debug flags # get size of new filesystem in sectors #echo `sudo dumpe2fs /dev/sdc2 |grep "Block count" * # size of filesystem in Block size (4096) # plus start sudo parted /dev/sdc print unit s resizepart 2 sssss # From (actually end = size -1 but hey!) sudo parted /dev/sdc print unit Mi resizepart 2 5760 # From resize2fs start + size
sudo fdisk /dev/mmcblk0 F # show Free space sudo parted /dev/mmcblk0 unit GB print resizepart 2 END-Gbytes Where END-Gbytes should be less then the start of the next partition. If omitted current value will be suggested, not what you want ! /bin/df -m / Filesystem 1M-blocks Used Available Use% Mounted on /dev/root 4960 4548 142 97% / sudo fdisk /dev/mmcblk0 Device Boot Start End Sectors Size Id Type /dev/mmcblk0p2 98304 12551295 12452992 6G 83 Linux 5.93GB why?: sudo resize2fs -d62 -p /dev/mmcblk0p2 #62 =3E all debug flag bits resize2fs 1.44.5 (15-Dec-2018) Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/mmcblk0p2 is now 1556624 (4k) blocks long. /bin/df -m / Filesystem 1M-blocks Used Available Use% Mounted on /dev/root 5921 4548 1064 82% /
-P |
See: dumpe2fs, fdisk, parted, e2fsck, mke2fs, lvm, lvextend addpart, delpart, partprobe, partx