Create 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]
/dev/ram1 [ 64.00 MiB]
/dev/vda1 [ 40.00 GiB]
/dev/ram2 [ 64.00 MiB]
/dev/ram3 [ 64.00 MiB]
/dev/ram4 [ 64.00 MiB]
/dev/ram5 [ 64.00 MiB]
/dev/ram6 [ 64.00 MiB]
/dev/ram7 [ 64.00 MiB]
/dev/ram8 [ 64.00 MiB]
/dev/ram9 [ 64.00 MiB]
/dev/ram10 [ 64.00 MiB]
/dev/ram11 [ 64.00 MiB]
/dev/ram12 [ 64.00 MiB]
/dev/ram13 [ 64.00 MiB]
/dev/ram14 [ 64.00 MiB]
/dev/ram15 [ 64.00 MiB]
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, 11239424

    Allocating 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

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

About SoCRaT

Software 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 )

Google+ photo

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

Connecting to %s