Online resize root filesystem on a GPT partition

This short tutorial shows how to resize a ext4 root filesystem online. Most people use gparted from a recovery system for this task, and I also recommend that for if you are not familiar with the tools used in this guide. Also, make sure you have a backup of the data (I did this myself on a system I just installed, so I would not mind if anything goes wrong). Generally this is not different from doing a manual MBR/fdisk resize, except that we need to treat the unique partition GUID specially since we should maintain it (for boot loaders/boot managers).

So, here is how I resized my ext4 root partition (sda2) using gdisk and resize2fs:

  1. gdisk /dev/sda
  2. Print information (i<enter>2)
    Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
    Partition unique GUID: 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
    First sector: 206848 (at 101.0 MiB)
    Last sector: 109051903 (at 52.0 GiB)
    Partition size: 108845056 sectors (51.9 GiB)
    Attribute flags: 0000000000000000
    Partition name: ''
  3. Delete the partition (d<enter>2<enter>)
    Command (? for help): d
    Partition number (1-4): 2
  4. Recreate a new, large partition (n<enter>2<enter>….)
    on my setup, gdisk guessed the right first sector. The end sector was also guessed right, since I wanted to fill it up all remaining space
    Command (? for help): n
    Partition number (2-128, default 2): 
    First sector (34-500118158, default = 206848) or {+-}size{KMGTP}: 
    Last sector (206848-336072703, default = 336072703) or {+-}size{KMGTP}: 
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300): 
    Changed type of partition to 'Linux filesystem'
  5. Now copy the old Partition unique GUID to the new partition (x<enter>c<enter>2<enter>)
    Expert command (? for help): c
    Partition number (1-4): 2
    Enter the partition's new unique GUID ('R' to randomize): 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
    New GUID is 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
  6. At this point one can verify everything again, after pressing w (to safe the partition), your data might be lost if you did not do this carefully… Just be warned 🙂
  7. Reread your block device partition (sudo blockdev –rereadpt /dev/sda)
    Note: This did not work for me, so I had to reboot the system once. However, I still could resize online afterwards, so no big down-time and no external recovery media required 🙂
  8. sudo resize2fs /dev/sda2
    resize2fs 1.42.8 (20-Jun-2013)
    Filesystem at /dev/sda2 is mounted on /; on-line resizing required
    old_desc_blocks = 4, new_desc_blocks = 11
    The filesystem on /dev/sda2 is now 41983232 blocks long.
  1. Hello,

    thanks for the article. I used a third party prog to resize a btrfs partition which failed to resize the physical partiton (to small). Therefore btrfs was broken. With your acticle I was able to fix gpt table for btrfs partiton. 🙂

  2. Thanks! You saved me a lot of time over the more conservative approach.

  3. [root@c1-prod-app02-iad3 ~]# resize2fs /dev/sdc
    resize2fs 1.41.12 (17-May-2010)
    resize2fs: Device or resource busy while trying to open /dev/sdc
    Couldn’t find valid filesystem superblock.
    [root@c1-prod-app02-iad3 ~]# resize2fs /dev/sdc1
    resize2fs 1.41.12 (17-May-2010)
    resize2fs: Device or resource busy while trying to open /dev/sdc1
    Couldn’t find valid filesystem superblock.

  4. It looks like there is no (valid) file system on /dev/sdc or /dev/sdc1. Check with mount where your file system is actually residing and what type it is. resize2fs works for the ext family of file systems.

Leave a Comment

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