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: , , , , , , , ,

8 Comments

  1. Thanks for the article, it shed some light much better than other posts I found on the net. I was able to resize my partition with no error ! I will be back for more…

    Reply

  2. dear sir,

    in ubuntu server, to reduce the ext4 filesytem size from 1T, i run the “resize2fs /dev/mapper/ispconfig-root 500G” and got the below output to the console:

    Filesystem at /dev/mapper/ispconfig-root is mounted on /; on-line resizing required
    On-line shrinking from 267809792 to 131072000 not supported.

    it is much appreciated if you can help to email the resolution to my email address qiubosu@gmail.com.

    thanks.

    Reply

  3. Dear David su, asking for a PM just means leaving others with your same problem in the dark. Since this is not a private matter (nothing confidential is passed on) wouldn’t it be better to let everyone know?

    What the system is saying is that you have to do the resize on an unmounted partition. Filesystem operations like resizing, checking and so on should always be done offline.

    You just have to keep a live cd at hand.

    Reply

  4. Will this LOOSE my data ? I need to resise an ext4 /home partition (/dev/sda9) to make space for something else but I don’t want to loose the data I have inside it.
    I can boot and go directly to console as root so I can unmount /home, but then how can I resize it without loosing data inside? For some reasons I can’t go to the gui with no /home so I can’t use gparted.

    Reply

  5. to Antonello,

    It should not loose your data. Of course, it’s *always* a smart idea to have a current backup before you start! (-;

    Rick

    Reply

  6. Tim Miller Dyck

    Hi, a note to check the starting sector before recreating the partition and ensure the new partition starts at the same sector. When I used cfdisk, it created the partition starting at sector 34. I had used fdisk to create the original partition and it created the partition starting at sector 2048. Starting the partition at a different disk location than before, of course, resulted in a partition with no valid file system. I used fdisk again to create the new (larger) partition and all was fine.

    Reply

  7. Hi Tim,
    Yes, you’re right : it’s better to use fdisk to be sure that the partition keeps the same start.

    Reply

  8. Thank you!!! Just saved my ass! I have an encrypted partition over LVM whose filesystem was too small, and parted didn’t work. Kudos to whoever made e2fsprogs!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>