|
|
  Logical Volume Manager (LVM) allows you to combine disks and create a single volume that can be mounted like a regular partition. It also allows you to add and remove storage. Make sure that you have the support for LVM compiled into your kernel. We set CONFIG_BLK_DEV_LVM=y on ours, and that worked well. [Note: Before you do anything involving your partitions or volumes, make a complete backup. Make sure to set up a test system with the same kernel and distribution to see how this stuff works. This article was written using our lab box. Read our terms of use. Note that this article was written using a Fedora RC 1 distribution and a generic 2.4.24 kernel.] The first step is to figure out what drives you can use. The lvmdiskscan command will list all disks:
[root@srv-2 /]# lvmdiskscan
lvmdiskscan -- reading all disks / partitions (this may take a while...)
lvmdiskscan -- /dev/sda1 [ 3.75 GB] Primary
LINUX native partition [0x83]
lvmdiskscan -- /dev/sda2 [ 250.98 MB] Primary
LINUX swap partition [0x82]
lvmdiskscan -- /dev/sdb1 [ 4 GB] Primary
LINUX native partition [0x83]
lvmdiskscan -- /dev/sdc1 [ 4 GB] Primary
LINUX native partition [0x83]
lvmdiskscan -- /dev/sdd1 [ 4 GB] Primary
LINUX native partition [0x83]
lvmdiskscan -- /dev/sde [ 4 GB] free whole disk
lvmdiskscan -- /dev/sdf [ 4 GB] free whole disk
lvmdiskscan -- /dev/sdg [ 4 GB] free whole disk
lvmdiskscan -- /dev/sdh [ 4 GB] free whole disk
lvmdiskscan -- 8 disks
lvmdiskscan -- 4 whole disks
lvmdiskscan -- 0 loop devices
lvmdiskscan -- 0 multiple devices
lvmdiskscan -- 0 network block devices
lvmdiskscan -- 5 partitions
lvmdiskscan -- 0 LVM physical volume partitions
[root@srv-2 /]#
|
OK. So we can use sde, sdf, sdg, and sdh for our new volume. Let's create a volume of three disks to start with. First let's prepare the disks:
[root@srv-2 root]# pvcreate /dev/sde
pvcreate -- physical volume "/dev/sde" successfully created
[root@srv-2 root]# pvcreate /dev/sdf
pvcreate -- physical volume "/dev/sdf" successfully created
[root@srv-2 root]# pvcreate /dev/sdg
pvcreate -- physical volume "/dev/sdg" successfully created
[root@srv-2 root]#
|
Now, we need to create a volume group:
[root@srv-2 root]# vgcreate volgroup /dev/sde /dev/sdf /dev/sdg
vgcreate -- INFO: using default physical extent size 4 MB
vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
vgcreate -- doing automatic backup of volume group "volgroup"
vgcreate -- volume group "volgroup" successfully created and activated
[root@srv-2 root]#
|
Let's display our volume group information:
[root@srv-2 root]# vgdisplay
--- Volume group ---
VG Name volgroup
VG Access read/write
VG Status available/resizable
VG # 0
MAX LV 256
Cur LV 0
Open LV 0
MAX LV Size 255.99 GB
Max PV 256
Cur PV 3
Act PV 3
VG Size 11.98 GB
PE Size 4 MB
Total PE 3066
Alloc PE / Size 0 / 0
Free PE / Size 3066 / 11.98 GB
VG UUID FHGe16-ATie-2TsY-CkCo-R2PO-0kv2-VpUvUG
[root@srv-2 root]#
|
Looks good. We currently have 11.98 GB in our volume group named volgroup. Let's create a logical volume of 5 GB in size:
[root@srv-2 root]# lvcreate -L5G -nlogicalvol volgroup
lvcreate -- doing automatic backup of "volgroup"
lvcreate -- logical volume "/dev/volgroup/logicalvol" successfully created
[root@srv-2 root]#
|
Now, let's create a filesystem:
[root@srv-2 root]# mkfs.ext3 /dev/volgroup/logicalvol
mke2fs 1.34 (25-Jul-2003)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@srv-2 root]#
|
Let's mount the filesystem:
[root@srv-2 root]# mount /dev/volgroup/logicalvol /mnt
[root@srv-2 root]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 3874108 1611620 2065692 44% /
none 3874108 1611620 2065692 44% /dev/pts
/dev/sdb1 4127076 235028 3682404 6% /opt
/dev/sdc1 4127076 278644 3638788 8% /usr/src
/dev/sdd1 4127076 32828 3884604 1% /usr/local
/dev/volgroup/logicalvol
5160576 32828 4865604 1% /mnt
[root@srv-2 root]#
|
Five gigs of space! All is good.
There are six articles in this series:
Setting Up Logical Volume Manager
Extending a Logical Volume
Shrinking a Logical Volume With LVM
Adding a RAID1 Device to a Volume With LVM
Upgrading LVM To Version 2 and Patching The Linux Kernel
Finish Conversion And Expansion to Two RAID1 Devices With LVM
|
|