Create/Modify LVM Physical Volumes, Volume Groups and Logical Volumes on Ubuntu 16.04

It’s pretty straight-forward, but before you start, you need to check for block devices that can be used to create physical volumes:

sudo lvmdiskscan

You will see a result that looks like this:

/dev/ram0 [ 64.00 MiB]
/dev/sda [ 50.00 GiB]

1 disk

Just ignore all the /dev/ram* and notice the /dev/sda drive, this is the one that you will need.

Afterwards, you need to do the following, I will assume I have one block device, then will create one physical volume, one logical volume (taking all free space) and one volume group:

  1. sudo pvcreate /dev/sda
    
    Physical volume "/dev/sda" successfully created
  2. sudo vgcreate vgData /dev/sda
    
    Volume group "vgData" successfully created
  3. sudo lvcreate -l 100%FREE -n lvData1 vgData
    
    Logical volume "lvData1" created.
  4. sudo mkfs.ext4 /dev/vgData/lvData1
    
    mke2fs 1.42.13 (17-May-2015)
    
    Discarding device blocks: done
    
    Creating filesystem with 13106176 4k blocks and 3276800 inodes
    
    Filesystem UUID: e2ce00dd-236a-474d-b773-033e1cb7cb55
    
    Superblock backups stored on blocks:
    
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    
    4096000, 7962624, 11239424Allocating group tables: done
    
    Writing inode tables: done
    
    Creating journal (32768 blocks): done
    
    Writing superblocks and filesystem accounting information: done
  5. sudo mkdir /mnt/webdata
  6. sudo mount /dev/vgData/lvData1 /mnt/webdata
  7. To make it permanent on system boot, add the following entry to /etc/fstab:
    /dev/vgData/lvData1 /mnt/webdata ext4 defaults,nofail 0 0

In order to extend an existing VG with additional disks, you need to do the following (assuming sdc is the new disk)

  1. sudo pvcreate /dev/sdc
  2. sudo vgextend vgData /dev/sdc
  3. sudo lvextend -l 100%FREE --resizefs /dev/vgData/lvData1 #to add the pv to the existing lv

Update:

For disks exceeding 2 TB, you have to use GPT, so before doing any of the above steps:

sudo parted /dev/sdc
mklabel gpt
mkpart primary 0GB 100%
q

Then you have a new partition /dev/sdc1 that you need to convert to a physical volume and continue all the steps normally.

That’s it, Enjoy!

Sources:

  1. https://www.digitalocean.com/community/tutorials/an-introduction-to-lvm-concepts-terminology-and-operations
  2. https://www.digitalocean.com/community/tutorials/how-to-use-lvm-to-manage-storage-devices-on-ubuntu-16-04
  3. http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html
  4. https://gist.github.com/holms/7480084

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Linux, linuxmint, Ubuntu, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s