Sometimes you need to resize a filesystem because it grows out of it’s available space. With virtual machines this is quite easy, just resize the disk. But…. how do you make Linux know the disk has been resized?
In my case I have a virtual machine which is running inside of Proxmox, but the “trick” works the same in other hypervisors as well.
First step is to go to the hypervisor and resize the actual disk. The steps you need to take here depend on the hypervisor, but most of the time it’s just looking up the disk and click in a GUI to grow it.
The disk has no been resized, but Linux is probably not aware the disk has increased. Reboot? Of course not!
Within Linux we can tell the disk driver to rescan the disk and by doing that it will determine the size actually changed. So how do we tell the kernel / driver to do a rescan?
Simply go to the folder /sys/block/sdb/device. In our case device sdb will be resized. Now execute echo "1" > rescan this will tell the kernel / driver to perform a rescan of the device. When this is successful you will see an entry in the syslog similar to the one below:
kernel: [17001376.526196] sd 2:0:0:1: Capacity data has changed kernel: [17001376.529583] sd 2:0:0:1: [sdb] 274726912 512-byte logical blocks: (141 GB/131 GiB) kernel: [17001376.530582] sdb: detected capacity change from 129922760704 to 140660178944
Because the kernel knows of the new capacity we can actually resize the filesystem / LVM volume to make use of the added capacity. Easy !