Expanding the drive on a live Linux system

This assumes that you are running your Linuxsystem as a virtual server on VMWare, KVM, XEN or AHV.

It is quite common – for me atleast – that a busy databaseserver is going to use more and more space. And in most cases it is not always that attractive to have to restart the server and resize it with a LiveCD such as gparted live.

Luckily, there is possible to expand the partitions while your machine is running. I will try to guide you with this step to step guide on how you can successfully proceed with it:

  1. First of all, add the storage in you hypervisor.
  2. Next, you want to tell the kernel that to rescan the bulk device: echo 1 > /sys/class/block/sda/device/rescan fdisk are now able to “see” the expanded disk, in this case /dev/sda
  3. Now, we need to do the actual expansion of the partinion, so we need to “delete” the partion and add it again via fdisk – dont worry, we are not going to write the changes to disk while the partinion is deleted: fdisk /dev/sda
  4. Just to make sure, check the partinion by selecting p, if the disk looks like it should, you may continue
  5. Delete the partition by pressing d
  6. Press n to create a new partinion
  7. Press p to chose “Primary Partition”
  8. Press 1 to chose the partition number 1
  9. Press ENTERtwice
  10. And lastly, doublecheck the changes by pressing p, note the difference from the first time you did it. You should see that the partition has been expanded.
  11. !The following actions will write the changes to disk! Now, in order to make is real, press w in order to write the changes to disk, you will see a warning about that the partition table has been changed. Do not worry, it is expected.
  12. Now, run partprobe (you have to install parted for this to work). If you are using an older kernel, you maybe would need to reboot if the partprobe task did not work.
  13. Now, we just need to expand the filesystem itself in order to actually use the newly added space: resize2fs -p /dev/sda1

Verify with df -h

You should be able to see the new size now.