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:
- First of all, add the storage in you hypervisor.
- Next, you want to tell the kernel that to rescan the bulk device:
echo 1 > /sys/class/block/sda/device/rescanfdisk are now able to “see” the expanded disk, in this case
- 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:
- Just to make sure, check the partinion by selecting
p, if the disk looks like it should, you may continue
- Delete the partition by pressing
nto create a new partinion
pto chose “Primary Partition”
1to chose the partition number 1
- 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.
- !The following actions will write the changes to disk!
Now, in order to make is real, press
win 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.
- Now, run
partprobe(you have to install
partedfor this to work). If you are using an older kernel, you maybe would need to reboot if the
partprobetask did not work.
- Now, we just need to expand the filesystem itself in order to actually use the newly added space:
resize2fs -p /dev/sda1
You should be able to see the new size now.