Resizing the Ubuntu Root Partition

I needed to expand my KVM virtual machine. After doing some searching, I eventually found a blog entry that was exactly what I needed to do. Here’s my summary of Brian Christner’s post

  1. Check to see how much space you have left
    df -k /

    You can replace / with any directory or mount point that is most appropriate

  2. Check the current state of of the physical volume
    sudo pvdisplay
  3. Check to see what free space you currently have
    lsblk

    This will show you what free space you currently have available. Take note of the disk id that you will use in the next step

  4. Create a new partition using up your free space
    sudo fdisk /dev/sd[disk id]

    I used most of the default settings here. I used a primary partition type, selected the default partition number as well as the first and last sector values. Take note of the new partition number you created as you’ll use it in Step 6

  5. Reboot the machine for Ubuntu to recognize the change
    sudo reboot now
  6. Create a new physical volume
    sudo pvcreate /dev/sd[new disk partition number]
  7. Identify which Volume Group you are looking to extend
    vgs
  8. Identify the filesystem name of the Logical Volume
    df -k

    Should look like /dev/mapper/

  9. Add newly created partition to the Volume Group
    sudo vgextend [Volume Group Name] /dev/sd[new disk partition number]
  10. Extend the Logical Volume
    sudo lvextend -L +[size required] /dev/mapper/[logical volume filesystem name]
  11. Extend the Filesystem to fill the Logical Volume
    sudo resize2fs /dev/mapper/[logical volume filesystem name]
  12. Reboot the server for good measure 🙂