Skip to content

Expanding & Resizing an LVS Partition / Group on Ubuntu 14.04 LTS

I have a server dedicated to the purpose of hosting an ownCloud instance. OwnCloud 8 to be exact. It’s an Ubuntu 14.04 LTS virtual machine, on an ESXi 5 hypervisor. This is my own server, and not any sort of revenue generating customer service. It has become a “Dropbox” replacement for myself, and a few select friends and family. Recently, I found the original 1TB I allocated to be filling up quickly. So, I started doing some google searches to see how I could go about resizing, or expanding, an LVM group (like a partition). I found an enormous wealth of information, much of it conflicting. As I started going through a guide, that closely matched my configuration (everything was the same, actually, except the size of the disk), I instantly faced problems with commands not working. It was frustrating. Eventually I navigated through it and successfully expanded the Logical Volume. I figured I would go ahead and document my troubles so that I can make others lives a little easier.

Firstly, you need to run a couple commands to see what you’re working with. These commands are df and fdisk -l. You should see something like this:

mike@cloud:~$ df
Filesystem                  1K-blocks     Used Available Use% Mounted on
/dev/mapper/cloud--vg-root 1048254140 65112056 929870740   7% /
none                                4        0         4   0% /sys/fs/cgroup
udev                          4077252        4   4077248   1% /dev
tmpfs                          817700      524    817176   1% /run
none                             5120        0      5120   0% /run/lock
none                          4088496        0   4088496   0% /run/shm
none                           102400        0    102400   0% /run/user
/dev/sda1                      240972    67164    161367  30% /boot


mike@cloud:~$ sudo fdisk -l
[sudo] password for mike:

Disk /dev/sda: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 cylinders, total 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c9595

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM

Disk /dev/mapper/cloud--vg-root: 1090.7 GB, 1090661646336 bytes
255 heads, 63 sectors/track, 132598 cylinders, total 2130198528 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cloud--vg-root doesn't contain a valid partition table

Disk /dev/mapper/cloud--vg-swap_1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

As you can see, df will give you a high level overview of your partition layout and how much space you’ve used, or have free. Moving on to fdisk -l, you can see your partition layout, according to fdisk, and you probably noticed the errors relating to the partition tables of the LVM groups: “….doesn’t contain a valid partition table.” Since LVM no longer uses a classic fdisk style partition table, you can safely ignore these warnings on your system. If you are running Ubuntu 14.04 and are using LVM, you most definitely will see the same thing. Also, note the size of /dev/sda: 1099.5 GB, and the size of the LVM cloud-vg-root: 1090.7 GB. We will compare this information later on.

Many of the commands were not behaving like I expected, and for sake of not type sudo over and over again, go ahead and run a sudo -i. This will drop you into root, without actually enabling the root account. It will accomplish the same thing. It is an extremely handy command to have in your arsenal.

mike@cloud:~$ sudo -i
[sudo] password for mike:
root@cloud:~#

So, now we are in root, without actually enabling the root account. The best of both worlds. Now, go ahead and increase the size of you VHD (Virtual Hard Disk) in VMWare, or your hypervisor of choice. If you are using VMWare ESXi 5, or a similar version, it should look something like this:

Screen Shot 2015-04-19 at 9.22.00 PM

At this point in many guides, it was said a reboot (on the VM, of course) could be avoided by running the following command, which did NOT work for me.

mike@cloud:~$ echo "- - -" > /sys/class/scsi_host/host0/scan
-bash: /sys/class/scsi_host/host0/scan: Permission denied

You can try it, but I needed to reboot for my Ubuntu 14.04 server to see the newly added space. So, go ahead and reboot unless you know something I don’t.

Now, we have a bunch of space that is not being used in any way, lets add this to our LVM group. Go ahead and run an fdisk -l command again and see what the disk size looks like now. Since I increased the size of my virtual disk from 1TB (or 1024MB) to 1.5TB (or 1500TB), it should look something like this:

root@cloud:~# fdisk -l

Disk /dev/sda: 1649.3 GB, 1649267441664 bytes
255 heads, 63 sectors/track, 200512 cylinders, total 3221225472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c9595

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda3      2147481600  3221225471   536871936   8e  Linux LVM
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM

Disk /dev/mapper/cloud--vg-root: 1090.7 GB, 1090661646336 bytes
255 heads, 63 sectors/track, 132598 cylinders, total 2130198528 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cloud--vg-root doesn't contain a valid partition table

Disk /dev/mapper/cloud--vg-swap_1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cloud--vg-swap_1 doesn't contain a valid partition table
root@cloud:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
root@cloud:~# vgextend VolGroup00 /dev/sda3
  Volume group "VolGroup00" not found

Note the increase in disk size of /dev/sda on the very first line. It is now 1659.4 GB. Also, note the partition table has not changed. Now, would be a good time to run a vgdisplay to see what the actual name of your volume group might be. You will need to know that information to run the correct commands in a minute. I’ll do that on my server now.

root@cloud:~# vgdisplay
  --- Volume group ---
  VG Name               cloud-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1023.76 GiB
  PE Size               4.00 MiB
  Total PE              262082
  Alloc PE / Size       262082 / 1023.76 GiB
  Free  PE / Size       0 / 0
  VG UUID               9COKH3-KG6a-bUnk-PG8D-fuKy-C6cC-2omT02

As you might have gathered, the name of my volume group is cloud-vg, as stated towards the top by “VG Name.” Take note of yours. Now, we need to go into fdisk and create a new partition using the newly added space. You will need to enter fdisk /dev/sda or something along those lines, depending on the drive. If you only have one physical devices, and its a virtual machine, more than likely your command should be the same. Otherwise reference the output from fdisk -l to see the name of yours.

root@cloud:~# fdisk /dev/sda

Now, you will need to select “p” to print your partition table. You can select “m” to get a list of all available options.

Command (m for help): p

Disk /dev/sda: 1649.3 GB, 1649267441664 bytes
255 heads, 63 sectors/track, 200512 cylinders, total 3221225472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c9595

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM

Take close note of the start and end sectors of sda5. Also take note of of the total sectors available at the top. Comparing this information, its obvious that the free space was added starting at sector 2147481600 and it ends at 3221225472. This is one thing I had A LOT of issues with. Most guides suggest accepting the defaults when creating the new partition. This did NOT work for me. I had to manually set the start and end sectors. Don’t worry, its not hard. Just add +1 to the end sector of your highest number partition on your drive; in my case sda5. That will be your first sector in the new partition we create. The last, or end, will be the total sectors listed towards the top. Lets create the partition by selecting “n.” After selecting “n” to create a new partition, you will need to set the partition type. It needs to be primary. So, you can hit enter (the default is primary) or to be safe, select “p” and press enter.

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p

Next, you need to select a partition number. The default should be fine, which was 3 in my case. This has to be an unused number between 1-5.

Select (default p): p
Partition number (1-4, default 3): 3

Now you need to pay close attention to the start and end sectors we noted above. The first sector will be the End sector of your highest numbered partition for this drive, in my case /dev/sda5 2147481599, but you have to add 1 because this partition has to begin on an unused sector. So, I will enter 2147481600 as the First sector. For the Last sector, I’m going to hit enter because by default its going to default to the last available sector, which i my case is 3221225471, which is correct. You can either enter it manually or hit enter when you get to the Last sector prompt.

Partition number (1-4, default 3): 3
First sector (499712-3221225471, default 499712): 2147481600
Last sector, +sectors or +size{K,M,G} (2147481600-3221225471, default 3221225471):
Using default value 3221225471

After you’ve created the new partition, you need to set the partition’s system id so that it’s recognized as an LVM partition. So, select “t.” After selecting “t” you have to select the partition number, which will be the same that you selected above. In my case, I used the default first available, which was 3. The hex code for LVM is 8e, so that is what you will enter when prompted for the Hex code.

Command (m for help): t
Partition number (1-5): 3
Hex code (type L to list codes): 8e

Now, you need to select “p” to make sure you see the newly created partition (in my case /dev/sda3) and that its system id is set to Linux LVM.

Command (m for help): p

Disk /dev/sda: 1649.3 GB, 1649267441664 bytes
255 heads, 63 sectors/track, 200512 cylinders, total 3221225472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c9595

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda3      2147481600  3221225471   536871936   8e  Linux LVM
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM

As you can see, /dev/sda3 is listed with Linux LVM as the system id. Make sure yours is correct for your configuration.

Now, we need to run a pvcreate command to create the physical volume:

root@cloud:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

That was easy. Next, we need to run a vgextend to extend our volume group, using the physical volume we just created. Make sure you change the “cloud-vg” to the name of your Volume Group, which we found above by running the vgdisplay command. Here is how to go about that:

root@cloud:~# vgextend cloud-vg /dev/sda3
  Volume group "cloud-vg" successfully extended

Now, go ahead and run a vgdisplay yourvolumegroup | grep “Free” Be sure to replace yourvolumegroup with the name of your volume group. This will tell us how much free space is now available, exactly.

root@cloud:~# vgdisplay cloud-vg | grep "Free"
  Free  PE / Size       131072 / 512.00 GiB

As you can see, I have exactly 512 GB of free space available to the Volume Group. Note how much you have. Now it’s time to extend the volume group. The exact name of mine is /dev/cloud-vg/root. You need to remember the name of yours above. Then, run this command (be sure to replace the 512G with the amount of freespace you have):

root@cloud:~# lvextend -L+512G /dev/cloud-vg/root
  Extending logical volume root to 1.49 TiB
  Logical volume root successfully resized

Now that the Volume Group has been extended, we need lastly resize the partition, or filesystem. To do this we will run resize2fs (on Ubuntu). On CentOS and other distributions, you might run ext2online. You will once again need to reference the exact Volume Group, as I do:

root@cloud:~# resize2fs /dev/cloud-vg/root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/cloud-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 64, new_desc_blocks = 96
The filesystem on /dev/cloud-vg/root is now 400492544 blocks long.

That’s it! We are done now. You can run a df and fdisk -l to see that your newly added space is available:

root@cloud:~# df
Filesystem                  1K-blocks     Used  Available Use% Mounted on
/dev/mapper/cloud--vg-root 1576701244 65111168 1436849344   5% /
none                                4        0          4   0% /sys/fs/cgroup
udev                          4077252        4    4077248   1% /dev
tmpfs                          817700      528     817172   1% /run
none                             5120        0       5120   0% /run/lock
none                          4088496        0    4088496   0% /run/shm
none                           102400        0     102400   0% /run/user
/dev/sda1                      240972    67164     161367  30% /boot
root@cloud:~# fdisk -l

Disk /dev/sda: 1649.3 GB, 1649267441664 bytes
255 heads, 63 sectors/track, 200512 cylinders, total 3221225472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c9595

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda3      2147481600  3221225471   536871936   8e  Linux LVM
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM

Disk /dev/mapper/cloud--vg-root: 1640.4 GB, 1640417460224 bytes
255 heads, 63 sectors/track, 199436 cylinders, total 3203940352 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cloud--vg-root doesn't contain a valid partition table

Disk /dev/mapper/cloud--vg-swap_1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/cloud--vg-swap_1 doesn't contain a valid partition table

As I said before, ignore the “…. doesn’t contain a valid partition table.” This is normal for LVM on newer systems. Good luck. If you need help, let me know in the comments. Thanks!