Home

Resizing a Bootable Linux Partition Containing Grub

If you dual-boot Linux like I do, then the chances are that you might want to either expand or contract your Linux partition. I had some problems when I had my first go at it, so here’s how I expanded my partition with some notes on the problems. The set of procedures expands a partion while preserving its data.

Programs Used

  1. Linux
  2. gparted
  3. fdisk
  4. grub-install

The Procedure

I expanded a Linux partion by taking space from a Windows partition.

A = Linux partition I wanted to expand

B = Partition I can take space from

X = Device identifier

Y = Partition number

  1. I booted into a Linux with gparted through another medium, since I could not use the partition (A) I wanted to resize. Partition A must be unmounted.
  2. Through gparted, I unmounted the target partition and disabled the swap.
  3. I shrunk an partition B with MiB alignment. I then had a chunk of unallocated memory ready to be moved or used.
  4. I expanded A by adding the unallocated memory to it and hit apply. I hit the first roadblock here; If gparted throws an error about libparted stopping because of overlapping partitions, redo this step with the alignment set to cylinder [1].
  5. At this point, the partitions have been resized, but the data for booting are in different locations on the physical disk. GRUB could not find that data, and I could not boot into the Linux on partition A, which is normal. I open a terminal session to reinstall GRUB.
  6. I commanded “sudo fdisk -l” to list and confirm the existing partitions [2].
  7. I commanded “sudo mount /dev/sdXY /mnt” to mount partition A to /mnt. I got the name /dev/sdXY, the name of Partition A, from the previous step of listing partitions [2].
  8. I commanded “sudo grub-install --boot-directory=/mnt/boot /dev/sdX” to reinstall grub onto /dev/sdX. The boot directory specifies where GRUB is to be installed on the mounted target partition. Do not use /dev/sdXY in place of /dev/sdX. /dev/sdX is the name of the device you are targeting [2].
  9. I ran disk check on my Windows partition to make sure things were ok.

Notes

Written on the 19th of March in 2014

References

  1. http://ubuntuforums.org/showthread.php?t=1980664 Post #8 and #9
  2. https://help.ubuntu.com/community/Grub2/Installing#via_the_LiveCD_terminal