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.
Be sure to take a backup first!
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:
If you are using LVM, read until 12, and skip 13.
- 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
df -h or
Steps for if you are using LVM
I assume that you have done step 1-12 in the previous section.
- First, expand your physical volume:
- Then, we will proceed with expanding the Logical volume, replace “X1” with the Logical Volume you want to extend:
lvextend --extents +100%FREE /dev/vg0/X1
- After that is done, we have to expand the filesystem, again – replace “X1” with the Logical Volume you want to extend
df -h or
You should be able to see the new size now.