Ubuntu Extend Disk

After extending the volume in VMware ESXi (shutdown vm, backup/export vm, remove all snapshots, then increased number in disk size, take snapshot of vm again before following the next steps so you can revert mistake/error).

The following example is extending volume on root partition on a system that is already using LVM.

  1. ssh into the system, switch to root and run cfdisk
    # cfdisk
  2. enter image description here
  3. enter image description here
  4. enter image description here
  5. enter image description here
  6. enter image description here
  7. enter image description here
  8. enter image description here
  9. enter image description here
  10. enter image description here
  11. enter image description here
  12. enter image description here
  13. After exiting cfdisk
     # fdisk -l /dev/sda 
     Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
     Disklabel type: dos
     Disk identifier: 0xc8b647ff
    
     Device     Boot    Start      End  Sectors  Size Id Type
     /dev/sda1  *        2048   999423   997376  487M 83 Linux
     /dev/sda2        1001470 16775167 15773698  7.5G  5 Extended
     /dev/sda3       16775168 41943039 25167872   12G 8e Linux LVM (***** See new partition /dev/sda3*****)
     /dev/sda5        1001472 16775167 15773696  7.5G 8e Linux LVM
    
  14. Reboot system before next step (or else you might get Device
    /dev/sda3 not found (or ignored by filtering)
    )

     # shutdown now -r
    
  15. Initialize the new volume
     # pvcreate /dev/sda3
       Physical volume "/dev/sda3" successfully created
    
  16. Get the name of volume to extend
     # vgdisplay
       --- Volume group ---
       VG Name               linuxetc1-vg (***** this is vg i'm extending*****)
       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               7.52 GiB
       PE Size               4.00 MiB
       Total PE              1925
       Alloc PE / Size       1925 / 7.52 GiB
       Free  PE / Size       0 / 0  
       ...
    
  17. Extend volume group
     # vgextend linuxetc1-vg /dev/sda3
       Volume group "linuxetc1-vg" successfully extended
    
  18. Extend root
     # lvextend -l+100%FREE /dev/linuxetc1-vg/root
       Size of logical volume linuxetc1-vg/root changed from 6.52 GiB (1669 extents) to 18.52 GiB (4741 extents).
       Logical volume root successfully resized.
    
    
     Or if you only wanted to give 5 more GB to root
     # lvextend -L +5g /dev/linuxetc1-vg/root
    
  19. Get filesystem name for next step
     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root  6.3G  2.5G  3.5G  42% /            (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000
    
  20. Extend filesystem
     # resize2fs /dev/mapper/linuxetc1--vg-root
     resize2fs 1.42.13 (17-May-2015)
     Filesystem at /dev/mapper/linuxetc1--vg-root is mounted on /; on-line resizing required
     old_desc_blocks = 1, new_desc_blocks = 2
     The filesystem on /dev/mapper/linuxetc1--vg-root is now 4854784 (4k) blocks long.
    
  21. See the increased size
     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root   19G  2.5G   15G  15% /         (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000
    

2. Faster Method Tested in Ubuntu Server 18.04.3 LTS

This method is a little faster than the first. This is due to a new option in the cfdisk menu called “Resize” that saves some steps.

After extending the volume in VMware ESXi (shutdown vm, backup/export vm, remove all snapshots, then increased number in disk size, take snapshot of vm again before following the next steps so you can revert mistake/error).

The following example is extending volume on root partition on a system that is already using LVM.

  1. ssh into the system, switch to root and run cfdisk.
  2. Choose the partition to extend and select “Resize”. enter image description here
  3. Set the “New size”. enter image description here
  4. After pressing enter, you’ll see screen with the following note “Partition [someNumber] resized”: enter image description here
  5. Next you’ll need to “Write” (save) your changes: enter image description here enter image description here enter image description here
  6. Quit cfdisk. When you exit you may see message “syncing disks”. enter image description here enter image description here
  7. I rebooted my system at this point but it may not be necessary. Now you can pickup from step 19 from the first method (repeated below).
  8. (19) Get filesystem name for next step
     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root  6.3G  2.5G  3.5G  42% /            (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000
    
  9. (20) Extend filesystem
     # resize2fs /dev/mapper/linuxetc1--vg-root
     resize2fs 1.42.13 (17-May-2015)
     Filesystem at /dev/mapper/linuxetc1--vg-root is mounted on /; on-line resizing required
     old_desc_blocks = 1, new_desc_blocks = 2
     The filesystem on /dev/mapper/linuxetc1--vg-root is now 4854784 (4k) blocks long.
    
  10. (21) See the increased size
     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root   19G  2.5G   15G  15% /         (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000
    

Articles:
https://wiki.ubuntu.com/Lvm
http://www.geoffstratton.com/expand-hard-disk-ubuntu-lvm

Close Menu