Make a Linux disk size bigger without having to reboot

edit 2016-10-25: You can only have 4 primary partitions per disk. If you want a no-brainer execution for making a Linux disk bigger in a virtual machine, just add a new virtual disk instead of expanding an existing one. It’s just another file stored along with the other VM files anyways

You *MUST* be able to increase disk space without having to reboot. Imagine your application has blown up and your production database servers are filling up disk space with binary logs. It’d be unacceptable to have to reboot your DB servers just to add more space.

Here’s how to do it without having to reboot:

1. Add another disk – physical disk virtual disk… just add another one (don’t extend an existing virtual disk – you’d have to reboot to see that extra space).

2. fdisk -l
Tell CentOS to rescan for disks:
echo "- - -" > /sys/class/scsi_host/host0/scan
-then check to see if it found a new disk –
fdisk -l
(you should see a new device in the output when compared to the first time you ran fdisk -l… if not, rescan on different “host” numbers, e.g.
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
echo "- - -" > /sys/class/scsi_host/host3/scan)

3. fdisk /dev/sdb
"enter" "enter" "enter" to use all space

1 (this may be auto-selected… it’ll say)
8e (this is default CentOS 6.5)

4. pvcreate /dev/sdb1 (the “1” is really the number you selected in the previous step)

5. vgextend /dev/vg_centos6 /dev/sdb1 (the vg_centos6 is the default virtual group with CentOS 6.5 install. Use “vgdisplay” to show all your virtual groups if your setup is different)

6. lvextend -l +100%FREE /dev/vg_centos6/lv_root (“lv_root” is from default CentOS install. use “lvdisplay” to see all your logical volumes in case you have a different setup)

7. Now resize the filesystem to fill the space on the newly-expanded logical volume:
resize2fs /dev/vg_centos6/lv_root

I’ve copied and pasted in these steps on several servers now (including production MySQL-Percona DB servers, and it just works). I’ve read this method of adding an additional disk and then adding that to an existing virtual group is the recommended way to expand disk space on Oracle installs, so I’m assuming performance is perfectly fine. You could take a snapshot of your VM just before doing this, just in case… though I’m not sure if there might be issues with the new disk… try it on some test VM before doing it to your prod machines).