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:
-
sudo pvcreate /dev/sda Physical volume "/dev/sda" successfully created
-
sudo vgcreate vgData /dev/sda Volume group "vgData" successfully created
-
sudo lvcreate -l 100%FREE -n lvData1 vgData Logical volume "lvData1" created.
-
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
-
sudo mkdir /mnt/webdata
-
sudo mount /dev/vgData/lvData1 /mnt/webdata
- 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)
-
sudo pvcreate /dev/sdc
-
sudo vgextend vgData /dev/sdc
-
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: