How to: Use Gparted, VMWare to Increase /dev/sda Partition (LVM)

Dennis Faas's picture

Infopackets Reader Todd G. writes:

" Dear Dennis,

I am using Windows 10 and I have VMWare workstation installed. I have been playing around with a CentOS (Linux) virtual machine for the last few months. When I first created the virtual machine, I selected the default size for the operating system which is 8 gigabytes. However, I'd like to create a larger partition because I am running out of space. I am using the Ext4 file system with a logical volume for my primary partition. I tried using gparted to increase the volume size on /dev/sda, but when I rebooted, the 'df -h' command shows that my 'lv_root' is still the same size. I also increased the size of another virtual drive (/dev/sdb), and that drive resized without any issues. So I am not sure why lv_root has not changed size. Can you help? "

My response:

If you are using the Ext4 file system and /dev/sda is part of an LVM (logical volume), then you will also need to grow the logical volume using the lvextend command after using gparted. I understand most folks getting their feet wet with Linux will most likely want to use Gparted to manage partitions because of its graphical user interface; as such I'll provide the steps below to do just that. I'll also include instructions on using the lvextend for LVM disks after using gparted.

How to Use Gparted, VMWare to Increase /dev/sda Partition (LVM)

Here are the steps I took to grow my logical volume (lv_root) on /dev/sda after using gparted to increase the physical size of the disk:

  1. First, backup your virtual machine before resizing any partitions. To do so: pause or shutdown the machine, then create a snapshot.
     
  2. Next, login to the machine and open up a Bash shell, then use the 'disk file system' command (df) to obtain basic information of your attached disks:

    df -h

    #example output

    file system Size Used Avail Use% Mounted on

    /dev/mapper/xeon3-lv_root 6.5G 4.7G 1.6G 76% /  <=== to increase + 2 GB
    tmpfs 2.0G 4.0K 2.0G 1% /dev/shm
    /dev/sda1 477M 178M 274M 40% /boot
    /dev/sdb1 5.8G 3.1G 2.5G 56% /mnt/db  <=== to increase + 2 GB
    /dev/sdc1 2.9G 1.7G 1.2G 60% /backups  <=== to increase + 2 GB

    In the example above I will increase /dev/mapper/xeon-lv_root (which is mounted to / [root]) and also /dev/sdb1 and /dev/sdc1 by an additional 2 GB.
     
  3. Download gparted live ISO if you have not already done so; there is no need to burn the file to disc - you can leave it in .ISO format as you can mount the .ISO directly to the virtual machine's CD drive.
     
  4. If you are using VMWare workstation, you will need to modify your Linux virtual machine configuration file (*.vmx) so that the BIOS boot delay is set for 5000, otherwise you will not be able to get into the virtual machine's BIOS to change the boot order so that the gparted disc boots first (and not the hard drive). To do so: power off the virtual machine, then open your *.vmx virtual machine configuration file and add the following line near the top:

    bios.bootDelay = "5000"

    Next, go to the VMWare Workstation main page, then right click your virtual machine and select Settings. The "Virtual Machine Settings" window should now display; under the Hardware tab, locate your CD drive and left click to select it. On the right of the window, you will see a 'Connection' heading; under that, click the button that says "Use ISO Image file", then click browse and select the gparted.iso you downloaded in Step #3, and click OK.
     
  5. Now it's time to adjust the virtual machine's disk size. To do so: right click the virtual machine and select Settings from the dialogue menu. Under the Virtual Machine Settings Hardware tab, select your primary hard disk - usually labeled as 'Hard Disk (SCSI)', then click the Utilities pull down button and select Expand. Adjust the size of the drive accordingly. In my example I'm going to increase all my drives by 2 gigabytes.
     
  6. Now it's time to power on the machine. You will need to click inside of the virtual machine window and repeatedly tap the F2 key so that you can access the virtual machine BIOS. Once you're in there, go to the Boot menu and change the boot sequence so that the CD ROM boots before the hard drive. You can do this by navigating to the CD ROM drive with the arrow keys, then once it is highlighted, press the plus key (+) to move the CD ROM drive higher in the list until it is above the hard drive. Next, navigate to the Exit menu and then select "Exit saving changes".
     
  7. The virtual machine should now be boot from the gparted live disc; choose the first option from the grub boot menu. Eventually you will be prompted for the 'package configuration' screen; keep pressing Enter to select all the defaults until you make your way to the gparted desktop. Once you're there, gparted should launch automatically.
     
  8. Inside gparted, select each disk you want to resize using the pull down menu at the top right - it will say '/dev/sda/ x GiB' or such. Next, click the yellow bar representing '/dev/sda2', and then click the green 'Resize/Move' icon from the menu at the top. A new window will appear; drag the yellow bar all the way to the right, then click the Resize button. Repeat this step if you have multiple partitions to adjust. Finally, click the green 'Apply' check mark icon near the top to apply all changes, then exit gparted and restart the virtual machine.
     
  9. As the virtual machine reboots, press F2 repeatedly until you get into the BIOS. Once there, go to the Boot menu and adjust the boot sequence so that the hard drive boots first (and not the CD ROM drive). When complete, go to the Exit menu and save changes.
     
  10. The virtual machine should restart and should now boot into CentOS (or whichever Linux distribution you're using). Once it finishes booting, open up a Bash shell and enter in the 'df -h' command again to see if the partition size(s) have changed. In my example, I increased 3 drive partitions. Notice that the 'lv_root' below has not changed. That is because we need to run the lvextend command (described further down).

    df -h

    #sample output

    file system Size Used Avail Use% Mounted on
    /dev/mapper/xeon3-lv_root 6.5G 4.7G 1.6G 76% /  <=== did not increase yet
    tmpfs 2.0G 4.0K 2.0G 1% /dev/shm
    /dev/sda1 477M 178M 274M 40% /boot
    /dev/sdb1 7.8G 2.7G 4.7G 37% /mnt/db  <=== increased +2GB (not part of an LVM)
    /dev/sdc1 4.9G 6.1M 4.7G 1% /backups  <=== increased +2GB (not part of an LVM)
     
  11. Now it's time to enter in the command 'pvdisplay' so you can see which drive has the lv_root mounted to it, then we'll use lvextend to extend the volume. In the example below, /dev/sda2 comes up as the 'PV Name'; also I know that /dev/sdb and /dev/sdc were resized successfully, so I know that /dev/sda2 is the drive that needs the lvextend.

    pvdisplay

    #sample output

    --- Physical volume ---
    PV Name /dev/sda2  <=== this drive contains /lv_root
    VG Name xeon3
    PV Size 9.51 GiB / not usable 2.00 MiB
    Allocatable yes (but full)
    PE Size 4.00 MiB
    Total PE 2434
    Free PE 0
    Allocated PE 2434
    PV UUID L5DY67-7x7H-zMor-njik-x0UC-3tVb-qTZzEw
     
  12. You can obtain the full path of the 'lv_root' volume by entering the 'lvscan' command. We will use this info in part of Step #12 below.

    lvscan

    #sample output

    ACTIVE '/dev/xeon3/lv_root' [8.71 GiB] inherit
    ACTIVE '/dev/xeon3/lv_swap' [816.00 MiB] inherit
     
  13. Now it's time to use the lvextend command. In my example I'm increasing the size +2GB. As such, refer to the command below:

    lvextend -r -L +2G /dev/mapper/xeon3-lv_root /dev/sda2

    #sample output

    Size of logical volume xeon3/lv_root changed from 6.71 GiB (1718 extents) to 8.71 GiB (2230 extents).
    Logical volume lv_root successfully resized
    resize2fs 1.41.12 (17-May-2010)
    file system at /dev/mapper/xeon3-lv_root is mounted on /; on-line resizing required
    old desc_blocks = 1, new_desc_blocks = 1
    Performing an on-line resize of /dev/mapper/xeon3-lv_root to 2283520 (4k) blocks.
    The file system on /dev/mapper/xeon3-lv_root is now 2283520 blocks long.
     
  14. Hopefully you had similar output as to my sample output above. You can then run the 'df -h' command and you will see the lv_root has been extended.

    df -h

    #sample output

    file system Size Used Avail Use% Mounted on
    /dev/mapper/xeon3-lv_root 8.5G 4.6G 3.5G 57% /  <=== now increased +2GB
    tmpfs 2.0G 4.0K 2.0G 1% /dev/shm
    /dev/sda1 477M 178M 274M 40% /boot
    /dev/sdb1 7.8G 2.7G 4.7G 37% /mnt/db
    /dev/sdc1 4.9G 6.1M 4.7G 1% /backups

That's it!

Got a Computer Question or Problem? Ask Dennis!

I need more computer questions. If you have a computer question - or even a computer problem that needs fixing - please email me with your question so that I can write more articles like this one. I can't promise I'll respond to all the messages I receive (depending on the volume), but I'll do my best.

About the author: Dennis Faas is the owner and operator of Infopackets.com. With over 30 years of computing experience, Dennis' areas of expertise are a broad range and include PC hardware, Microsoft Windows, Linux, network administration, and virtualization. Dennis holds a Bachelors degree in Computer Science (1999) and has authored 6 books on the topics of MS Windows and PC Security. If you like the advice you received on this page, please up-vote / Like this page and share it with friends. For technical support inquiries, Dennis can be reached via Live chat online this site using the Zopim Chat service (currently located at the bottom left of the screen); optionally, you can contact Dennis through the website contact form.

Rate this article: 
Average: 5 (8 votes)

Comments

RadiologyKen's picture

I downloaded a precompiled Linux VM. The drive is only 20 gig. I want add drivers for me and that 20 gig will be gone in no time. In VM Workstation, I expanded to 500gig. I tried using gparted live iso and boot into that. It never boots up to the actual GUI no matter what other settings I use.

Any other options to expand this drive?