Before doing anything: backup your sensible data!
- Extend the partition
- Extend the filesystem
- Shrink the filesystem
- Shrink the partition
parted /dev/sdx print resize N
cfdisk /dev/sdx # delete the partition and create it again with the desired size resize2fs /dev/sdxY
Without giving any size, resize2fs extends the filesystem to the partition's size.
To shrink, it's almost as simple:
# example if you want a 10G partition # resize filesystem with a size smaller than the desired size resize2fs /dev/sdxY 9G cfdisk /dev/sdx # delete the partition and create it again with the desired size # (a little bigger than the filesystem!!) # then launch resize2fs again resize2fs /dev/sdxY
Doing so we get the good partition size without loosing any space.
- If your partition is over LVM, you can use the
lvreducecommands to resize the partition, instead of deleting/creating the partition with cfdisk.
- The method also works for other filesystems like NTFS. For NTFS, you will use the ntfsresize command, or parted if it works.