Setting Up LVM Partition On Linux Server

Setting Up LVM Partition On Linux Server

Think about this situation, you have a Ubuntu server and with your home videos or movies, books and other important files that are worth having a backup. You don’t have enough space on your laptop and also on your server the available space is almost gone. You go to a shop and buy a new HDD to make more space on your server but, when you connect it and you run lsbk you see two different discs on your system and you can’t have for examples home videos1 and home videos2 because you want to get them organized properly.
Today I will show you how to create an LVM partition and let you know some advantages and disadvantages of LVM over normal partitions.

LVM -Logical Volume Management

Logical volume management provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions. This gives the system administrator much more flexibility in allocating storage to applications and users.In other words, we can say that LVM allows multiple disks to show as one and help to maintain your information.

Advantages

  • No total disk space limit
  • You can create disk mirror for redundancy in case one disk fails
  • Volume snapshots
  • Easy backups and restores using snapshots
  • Easy to allocate data
  • Resize of disks without reformatting the disk

Setting Up An LVM Partition

On this tutorial, we will assume that the first disk is already full and you need more space to store more files. Both disks are 10GB in size but can have any size and don’t need to have the same size for this to work.

1. Displaying LVM

The image below shows a disk (sda5) with an LVM partition named redflag-vg with a root and swap file and for us to be able to see if we can run it with $ lsblk.
displaying lvm partitions

The picture below shows a second disk added. The disk is formatted and contains no information.
lsblk show lvm linux partitions

To display LVM physical volume you can run the command below –
$ sudo pvs
Note that this command only shows LVM volumes and not all volumes on your server or desktop.
linux pvs command

If you need to see more detailed information about your partition you can run –
$ sudo pvdisplay
pvdisplay linux command

2.Adding new physical volume to your LVM

Now starts the fun part. We are about to extend our LVM partition. Our second disk is called sdb and is located in /dev so to add the disk to lvm we can run –
$ sudo pvcreate dev/sdb
Note that we ran lsblk before just to make sure the disk we are adding is the correct one because the disks are wiped when added to LVM.
lsblk linux command

After creating you can view the volume added to LVM.
pvscan linux command for lvm partition

3. Extending the LVM

To make the disk extendable in the LVM run the command –
$ sudo vgextend redflag /dev/sdb
pvs command

At this point the LVM is not extended, you still need to attach this new LVM to root with the below command –
$ sudo lvm lvextend -l +100%FREE /dev/redflag-vg/root
lvextend extends lvm partition

Nice! Everything seems to be working like a charm. My new partition is resized to 18.52 GB. What if I run df -h command?
create lvm partition

It seems my LVM partition didn’t change. To solve it we need to enlarge our partition with resize2fs command –
$ sudo resize2fs -p /dev/mapper/redflag–vg-root
resize2fs linux partitioning command

Now if you run a new df -h you can see that the partition has been extended. This is the last step in creating an LVM partition.

Conclusion

LVM partitions are a good way to keep your information well organized but also has some disadvantages like if one disk is damaged you would lose all your information. Most of the big organizations use LVM to control information because of its capacity of extending information on servers.What about you? Do you use LVM? Leave your thought below.

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More