GNU Linux is extremely versatile, no one doubts that. But perhaps some users do not know some tools or possibilities that it offers us and that could facilitate our day to day or do incredible things. In this article we will talk about LVM (Logical Volume Manager), a tool that, although initially it was not created for Linux, later it was ported and now Linux users can enjoy its possibilities.
LVM is a logical volume manager as its name suggests, initially it was cCreated by Heinz Mauelshagen in 1998 for the HP-UX operating system, HP's UNIX. But later it would be implemented in the Linux kernel. With it you can resize logical groups, as well as logical volumes, read-only snapshots, manage RAID, etc. But the feature that interests us for this article is to merge several hard drives.
LVM can "see" disk groups and partitions as a whole instead of handling many independent spaces. That is why we can join several partitions as one, expand certain partitions on other different physical disks, play with several disks in RAID mode, add "hot" or "hot swap" hard drives, without forgetting the "snapshot" function to create backups. .
How can you do this? Well, basically thanks to the handling of three concepts:
- PV (Physical Volume): are the physical volumes, that is, hard drives or partitions of a computer.
- VG (Volume Group): volume group, is the area where the PVs and VLs meet.
- LV (Logical Volume): logical volumes or devices where file systems or FS can be created.
To work with LVM, we can work from the terminal with three main tools:
- pvccreate: You can create physical volumes by joining several different hard drives or partitions. For example, let's join the partition / dev / sda3 and / dev / sdb1:
pvcreate /dev/sda3 /dev/sdb1
- vgcreate: You can create volume groups, that is, partitions or physical disks belong to a group. For example, to create a group called "data":
vgcreate datos /dev/sdb1
- lvcreate: defines the logical volumes that will be within the group. For example, imagine that you want to create a volume called "new" within the group "data" and 8GB in size:
lvcreate --name nuevo --size 8G datos
Let's see a practical exampleImagine that you have a computer with an x GB hard drive and you decide to expand the capacity by including another hard drive. In that case, the operating system treats it as such, another new hard drive in which you must create one or more partitions on it to use it. I'm going to be even more specific, imagine that your hard drive is 120GB first and that you have a series of partitions, including / home that occupies 80GB of those 120 and is called / dev / sda3, where / dev / sda1 is the root partition. / and / dev / sda2 the SWAP ...
Now you find your new hard drive with 500GB (/ dev / sdb1) of additional space, but instead of creating another partition, you want your / home to have 580GB. This is possible with LVM, making / dev / sda and / dev / sdb be viewed by the operating system as a single device, a single partition that is physically located on two different hard drives. And this is only a small possibility of the many that LVM allows and it would be done like this:
—BEFORE ANYTHING, MAKE A BACKUP COPY OF / HOME AS IT WILL BE FORMATTED -
sudo -i unmount /dev/sda3 unmount /dev/sdb1 vgcreate lvm /dev/sda3 /dev/sdb1 modprobe dm-mod lvcreate -n home -l 100% VG lvm mkfs.ext4 /dev/lvm/home mount /dev/lvm/home /home
All that remains is to edit the / etc / fstab file So do not mount the pratitions / dev / sda3 and / dev / sdb1 at system startup, failing that, mount / dev / lvm / home / home. If we type the following (use gedit, nano or whatever text editor you want ...):
sudo gedit /etc/fstab
We can see the content to edit it, we will see that there are comments # and other lines to mount the partitions that we currently have in our distro. Be careful, spaces are not normal spaces, when you edit, use TAB to space the content! You will see that you can put something like UUID = XXX-XXX-XXX-XXX, but you can substitute this gibberish for / dev / sdx without problems ... that is, for the name of the partition as is. In our case you would have to remove (or better than delete, put a # at the beginning of the line to make a comment, so if there is a problem or it does not work, we could edit fstab and simply delete our new line and remove the # to return to the previous configuration ...) the two lines corresponding to / dev / sda3 and / dev / sdb1 and add:
/ dev / lvm / home / home ext4 defaults 0 1
Restart and now we would have a / home of 580GB, joining the two hard drives as if they were only one. Of course you can vary the parameters to your liking, use the partitions that you want, the FS you want (here we have used EXT4, but you can use whatever you need), etc. Please, leave your messages, questions, comments, etc..