Blog PROJECTS, TIPS, TRICKS, AND HOW-TOS

Intro

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.

The Process

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).

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.

Next, I used the unallocated space to create a partition using parted.

Listing 4

$ 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.

Listing 5

$ 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.

Listing 6

$ sudo pvcreate /dev/sda3

In order to add the physical volume to the volume group, I needed to find the volume group’s name.

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.

Listing 8

$ 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 root, not swap.

Conclusion

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.