An LVM structure is build as follows:
To use LVM, you need to install the necessary Debian package. If it's a fresh install, and you designated a partition for use as lvm, this is done automatically. If not, do the following:
apt-get install lvm2
This will provide all the necessary startup scripts and tools to use and maintain LVM volumes.
Using the Debian partitioner is the quickest way when doing a fresh install. However, you lose quite a bit of control over the creating process. Whenever possible, the manual way should be preferred, as it harvests some extra configuration options over the Debian partitioner:
In the Debian partitioner, designate a partition as LVM. The necessary tools will be installed automatically. After that, choose to configure LVM. The current partition layout will be applied (so do this as last), and the LVM menu will be shown.
First up, you have to create a VG. For naming convention, name the VG store (although it can be anything you want).
Next, you can create one or more LVs in the created VGs. The big one is usually named data or data1, but can of course be called anything.
When done, return to the partitioner. You'll notice there are now additional partitions available. Designate a file system and mount point like you normally would.
Before you can use a partition as a PV, you need to give it the proper partition type ID. This is done with fdisk:
Next up, we have to write LVM markers to the bare partition. This is called creating a PV, and is done with the pv toolset. To simply create one, simply punch in:
pvcreate /dev/sda6
This will write LVM markers to /dev/sda6, and allows the creation of VGs.
It is possible to set the size to something other than the entire partition, but this is not really recommended.
Almost there. We have to create a VG before we can do anything. Like said before, it's possible for one VG to span multiple PVs.
Creating and maintaining VGs is done with the vg set.
To create a simple VG:
vgcreate store /dev/sda6
This will create a VG called store on /dev/sda6.
To have a VG span across more than one PV, do the following:
vgcreate store /dev/sda6 /dev/sdb6 /dev/sdc6
The VG store will now span across /dev/sda6, /dev/sdb6 and /dev/sdc6. If the partitions were of the same size, we would have tripled the total capacity of our LVM.
Unlike VG, when creating an LV, you always have to specify the extents (size) the LV will have. Therefore, before creating the LV, we have to check the number of extents that is (left) available in our VG.
By default, a single extent is around 4MB.
vgdisplay store
This will display some information. The fields we need are:
To create a simple LV, we do something like this:
lvcreate -n data1 -l 1024 store
This would create an LV named data1, stored in the VG store, with a PE of 1024.
Or, you could specify the size in a more human readable format:
lvcreate -n data2 -L 8G store
This would create an LV named data2, stored in VG store, and is 8GB in size.
When creating LVs, udev takes care of the device nodes.
There are two ways to approach an LVM:
Creating a file system works like any other partition:
mke2fs -j /dev/store/data1 would create a file system on LV data1 of VG store.
Note that if you're planning on resizing LVs in the future, you need to mind the file system you use: not all file systems can be resized!!! Read the About linux filesystems page for more information (scroll down to the LVM bit).
Adding to /etc/fstab is easy:
/dev/mapper/store-data1 /srv/data reiserfs defaults 0 2
This would automount the LV data1 of VG store to mount point /srv/data at boot. The file system we used is reiserfs.
Note that we use the direct dev node, because at boot time, it is unclear whether the symlinks are already present. This should be checked someday.
Removing an LV is easy:
lvremove store/data1
Like an LV:
vgremove store
Note that you can only remove a VG when it doesn't contain any LVs.
Likewise:
pvremove /dev/sda6
Note that removing a PV effectively destroys everything on that PV.
This is probably the most wanted part... There are a few steps you must follow in order to succesfully resize an LV:
Resizing the file system depends on the file system you're using.
To resize an ext2 or ext3 partition, we use resize2fs.
If we were to increase the size from 4GB to 8GB, we would do something like this:
resize2fs /dev/store/data1 8G
To resize a reiser3 partition, there are two ways (just like resizing the LV itself):
To resize, use resize_reiserfs.
In our sample, we grow our file system from 4GB to 8GB.
resize_reiserfs -s +4G /dev/store/data1
Or, like so:
resize_reiserfs -s 8G /dev/store/data1
Note that you cannot resize online: first, you have to unmount the partition.
Resizing the LV can be done in two ways. In our sample below, we want to resize the extents from 1024 (4GB) to 2048 (8GB).
Either, you simply add or deduct the additional extents or space, like so:
lvresize -l +1024 store/data1
or
lvresize -L +4G store/data1
If we needed to decrease space, we would simply change the + to a -.
Alternatively, you can specify the new total amount of extents or space, like so:
lvresize -l 2048 store/data1
or
lvresize -L 8G store/data1
« ‹ | November 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |