Actually, I want to just and easily tell about such a wonderful thing as Logical Volume Management or Logical Volume Management.
Since I’ve been using LVM for a long time, I’ll tell you what it means for me, not looking at manuals and pulling quotes from wiki in my own words so that it is clear to those who don’t know anything about it. I will try not to immediately talk about all sorts of "advanced" functions such as stripes, snapshots, etc.
LVM is an additional layer of abstraction from iron, which allows you to collect heaps of dissimilar disks into one, and then again to break this one exactly as we want.
There are 3 levels of abstraction:
1. PV (Physical Volume) - physical volumes (these can be partitions or whole "non-broken" disks)
2. VG (Volume Group) - a group of volumes (we unite the physical volumes (PV) into a group, we create a single disk, which we will further break as we like)
3. LV (Logical Volume) - logical partitions, the actual partition of our new “single disk” aka Group of Volumes, which we then format and use as a normal partition, a regular hard disk.
this is probably the whole theory. :) now practice:
To work, you need lvm2 packages and the ability to work with root privileges, therefore:
$ sudo bash
# apt-get install lvm2
Let's say we have a 40GB hard drive in our computer and we managed to scrape together some money and finally buy a TERRAIN DAY! :))) The system is already up and running, and the first disk is broken into one partition (/ dev / sda1 as /), the second one is the largest one we just connected - not / dev / sdb at all ...
I suggest that you unload the root disk a little bit, and at the same time speed up (the new disk is faster than the old one) and “secure” the system using lvm.
You can create partitions on the second disk and add them to volume groups (if we need several volume groups),
but you can not do partitions on the disk at all and make the whole device a physical partition (PV)
')
root @ ws: ~ # pvcreate / dev / sdb
Physical volume "/ dev / sdb" successfully created
We create a volume group with a talking name, for example, by the name of the machine “ws”, so that when we drag this disk to another machine there are no conflicts with the names of the volume groups:
root @ ws: ~ # vgcreate ws / dev / sdb
Volume group "vg0" successfully created
It is advisable to make folders such as / usr / var / tmp / home from the root partition in order not to defragment the root partition once again and in no case overflow it, so we create partitions:
root @ ws: ~ # lvcreate -n usr -L10G ws # here we create a partition called “usr”, 10Gb in size
Logical volume "usr" created
by analogy, we do the same for / var, / tmp, / home:
root @ ws: ~ # lvcreate -n var -L10G ws
root @ ws: ~ # lvcreate -n tmp -L2G ws
root @ ws: ~ # lvcreate -n home -L500G ws
we still have some free space in the volume group (for example, for a future backup section)
see how much you can command:
root @ ws: ~ # vgdisplay
information on created logical volumes
root @ ws: ~ # lvdisplay
information on physical volumes
root @ ws: ~ # pvdisplay
the sections that we created will appear in the / dev / [vg_name] / folder, or rather there will be links to files,
lrwxrwxrwx 1 root root 22 2009-08-10 18:35 swap -> / dev / mapper / ws-swap
lrwxrwxrwx 1 root root 21 2009-08-10 18:35 tmp -> / dev / mapper / ws-tmp
lrwxrwxrwx 1 root root 21 2009-08-10 18:35 usr -> / dev / mapper / ws-usr
lrwxrwxrwx 1 root root 21 2009-08-10 18:35 var -> / dev / mapper / ws-var
etc…
Then lvm is almost ending ... we format our partitions into favorite file systems:
root @ ws: ~ # mkfs.ext2 -L tmp / dev / ws / tmp
root @ ws: ~ # mkfs.ext4 -L usr / dev / ws / usr
root @ ws: ~ # mkfs.ext4 -L var / dev / ws / var
root @ ws: ~ # mkfs.ext4 -L home / dev / ws / home
By the way, it would not be bad to do a swap partition:
root @ ws: ~ # lvcreate -n swap -L2G ws
root @ ws: ~ # mkswap -L swap / dev / ws / swap
root @ ws: ~ # swapon / dev / ws / swap
create a folder and connect the newly formed volumes in turn, copy the necessary contents into them:
root @ ws: ~ # mkdir / mnt / target
root @ ws: ~ # mount / dev / ws / home / mnt / target
copy everything from the / home folder to your favorite file manager (with the same permissions), for example;):
root @ ws: ~ # cp -a / home / * / mnt / target /
root @ ws: ~ # umount / mnt / target /
By the way, for the temp folder you only need to correct the rights, copy something there is not necessary:
root @ ws: ~ # mount / dev / ws / tmp / mnt / target && chmod -R a + rwx / mnt / target && umount / mnt / target /
add the necessary lines in / etc / fstab, for example:
/ dev / mapper / ws-home / home ext4 relatime 0 2
/ dev / mapper / ws-tmp / tmp ext2 noatime 0 2
/ dev / mapper / ws-swap none swap sw 0 0
and reboot ... (advanced gentlemen can do without rebooting;))
On tasty, I want to offer a more advanced thing:
Suppose we have a system with a partition on LVM, and the hard disk began to fail, then we can move the entire system to another hard disk / partition without rebooting:
# On-line adding / removing hard drives using LVM (example)
root @ ws: ~ # pvcreate / dev / sda1 # our bad disk emulator
Physical volume "/ dev / sda1" successfully created
root @ ws: ~ # pvcreate / dev / sdb1 # our rescue disk emulator
Physical volume "/ dev / sdb1" successfully created
root @ ws: ~ # vgcreate vg0 / dev / sda1 # create a volume group vg0
Volume group "vg0" successfully created
root @ ws: ~ # lvcreate -n test -L10G vg0 # create a partition for "important" information
Logical volume "test" created
root @ ws: ~ # mkfs.ext2 / dev / vg0 / test # create a file system on a partition
root @ ws: ~ # mount / dev / mapper / vg0-test / mnt / tmp / # mount partition
... # I fill it with information, open several files on it, etc.
root @ ws: ~ # vgextend vg0 / dev / sdb1 # expand our volume group to a rescue disk
Volume group "vg0" successfully extended
root @ work: ~ # pvmove / dev / sda1 / dev / sdb1 # move the contents from the dying disk to the rescue
/ dev / sda1: Moved: 0.9%
/ dev / sda1: Moved: 1.8%
...
/ dev / sda1: Moved: 99.7%
/ dev / sda1: Moved: 100.0%
root @ work: ~ # vgreduce vg0 / dev / sda1 # remove the "dying" disk from the volume group.
Removed "/ dev / sda1" from volume group "vg0"
Total:
I created a logical partition, formatted it, mounted it and filled it with the necessary data, then moved it from one device to another, while the section remained mounted and the data remained available all the time!
Likewise, I managed to transfer the entire system from a dying disk to a reed array without rebooting. :)
And this is my favorite link on LVM:
xgu.ru/wiki/LVMPS Please forgive me for typos, I was constantly distracted =))
PPS Oh yes !!! The most important and biggest LVM minus is that it is not readable by grub.
therefore, the / boot partition must be outside LVM on a separate hard disk partition,
otherwise the system will not boot.