2010-01-06 23:41

Before doing anything: backup your sensible data!

To extend a partition and it’s filesystem, you have to:

  1. Extend the partition
  2. Extend the filesystem

To shrink a partition and it’s filesystem, you have to:

  1. Shrink the filesystem
  2. Shrink the partition

For an ext3 partition, simply use parted:

parted /dev/sdx
print
resize N

Parted doesn’t support ext4 (yet?). For an ext4 partition or if parted refuses to resize your ext3 partition (Error: File system has an incompatible feature enabled.), use resize2fs:

To extend:

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.

Notes:

  • If your partition is over LVM, you can use the lvresize or lvextend or lvreduce commands 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.

Links :

2010-01-06 23:41 · Tags: , , , , , , , ,