This morning, I worked on an Ubuntu Server 14.04 guest who’s disk space has been increased by the VMWare host. LVM was configured on the guest during installation, so that simplified the process of getting the extra space rolled into the original partitioning scheme. Below is a set of instructions that I was able to use on this live server without interruption in service. Your results may vary though. There are GUI tools that you can use for much of this, but I prefer to work in the terminal as the knowledge tends to be more universal. Being able to work without a GUI is also a requirement with many server systems, and in emergency recovery situations as well.
I started off by getting a view of the current disk space available on the server. I knew that the host had increased the size of disk /dev/sda from 20GB to approximately 100GB, so I used parted to output the unallocated space from the command line (Listing 1).
$ sudo parted /dev/sda print free Model: VMware Virtual disk (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 256MB 255MB primary ext2 boot 256MB 257MB 1048kB Free Space 2 257MB 21.5GB 21.2GB extended 5 257MB 21.5GB 21.2GB logical lvm 21.5GB 21.5GB 1049kB Free Space
I didn’t see that extra 80GB of space anywhere. That’s because to I needed to force the Linux kernel to rescan the SCSI drive for changes. This can be done through the
sys virtual file system, which gives access to kernel information, as well as giving some configuration and control access. I used sudo with
bash -c to handle the echo correctly and not get a permission denied error. Also note that the
2:0:0:0 part of the path may be different on your system.
$ sudo bash -c 'echo "1" > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan'
When I ran the parted command from above again, I saw the 80GB (approximately) of additional disk space.
$ sudo parted /dev/sda print free Model: VMware Virtual disk (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 256MB 255MB primary ext2 boot 256MB 257MB 1048kB Free Space 2 257MB 21.5GB 21.2GB extended 5 257MB 21.5GB 21.2GB logical lvm 21.5GB 107GB 85.9GB Free Space
Next, I used the unallocated space to create a partition using
$ sudo parted -- /dev/sda mkpart primary 21.5GiB -1s
The two dashes right after the
parted call keep the
-1s from causing an invalid argument error. It tells parted not to expect any more options.
-1s tells parted to use the rest of the unallocated space for the partition. Otherwise, I’d have to calculate the end of the partition myself.
Once this was done, I went ahead and ran
partprobe to sync the kernel’s partition table with the disk’s. This prevented me from having to reboot the server.
$ sudo partprobe /dev/sda
The next thing to do was use
pvcreate to create a physical volume which can be added into the logical volume group for the drive later. Just make sure that your partition number (the 3 at the end of sda3) matches the partition you just created.
$ sudo pvcreate /dev/sda3
In order to add the physical volume to the volume group, I needed to find the volume group’s name.
$ sudo vgdisplay ...snip... --- Volume group --- VG Name ustest-vg ...snip...
In my case the volume group was
ustest-vg. This will most likely follow the
[hostname]-vg naming convention, so change it appropriately for your server.
I was now ready to extend the logical volume group to include the new physical volume.
$ sudo vgextend ustest-vg /dev/sda3
Next, I had to find the name of the logical volume so I could extend it. Remember that the name of your volume group (
ustest-vg) will vary with the hostname. Also notice that you want the
LV Path that ends in
$ sudo lvdisplay ...snip... --- Logical volume --- LV Path /dev/ustest-vg/root ...snip...
Extending the logical volume has a similar form to extending the volume group.
$ sudo lvextend /dev/ustest-vg/root /dev/sda3
Lastly, before I could start using this new space, the file system needed to be re-sized.
$ sudo resize2fs /dev/ustest-vg/root
df -h should now show the increased space available in that logical volume. In my case this was an increase from about 20GB to approximately 100GB.
$ df -h ...snip... Filesystem Size Used Avail Use% Mounted on /dev/mapper/spwebapps1--vg-root 95G 12G 80G 13% / ...snip...
The process of extending the LVM disk space on a system is involved, but not difficult after you’ve stepped through the process once or twice. LVM also makes this process easier than if you use traditional partitions on your disks.
Have questions, comments, and/or suggestions? Let me know in the comments section below. Also, check out the Resources section for additional reading on this topic.