This section is based on the "recipe" from the LVM HOWTO at http://www.tldp.org/HOWTO/LVM-HOWTO/recipethreescsi.html. It covers setting up a LVM system spanning two physical hard disks.
The device node /dev/mapper/control is not created automatically under Debian Woody, although it may be present under other environments. To create it yourself you must first create the directory /dev/mapper using the mkdir command:
mkdir /dev/mapper
Create the device node using the mknod command:
mknod /dev/mapper/control c 10 63
Run pvcreate on each of the hard disks (physical volumes) you want to use with LVM. This will destroy all data on the disk! For example:
holly:/# pvcreate /dev/sda {{{ No physical volume label read from /dev/sda Physical volume "/dev/sda" successfully created holly:/# pvcreate /dev/sdb No physical volume label read from /dev/sdb Physical volume "/dev/sdb" successfully created
Run vgcreate to add the physical volumes you prepared to a volume group. For example:
holly:/# vgcreate vol_grp1 /dev/sda /dev/sdb Volume group "vol_grp1" successfully created
You can now use the vgdisplay command to display information about your volume group. The information shown will of course differ on your system, depending on its specifcation:
holly:/# vgdisplay --- Volume group --- VG Name vol_grp1 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 256 Cur LV 0 Open LV 0 Max PV 256 Cur PV 1 Act PV 1 VG Size 68.50 GB PE Size 4.00 MB Total PE 17537 Alloc PE / Size 0 / 0 Free PE / Size 17537 / 68.50 GB VG UUID [[TwfyDg]]-[[QDmI]]-GEzl-fYBx-b01P-8Y9a-[[Mv4lYt]]
Use the lvcreate command to create a logical volume on top of the volume group. You have to specify a size for the logical volume using the -L option and the name for the logical volume with the -n option. In this example, I will make the logical volume occupy all the space available in the volume group. I will use the 68.50 GB figure from the vgdisplay command above:
lvcreate -L68.50G -nlog_vol1 vol_grp1 Logical volume "log_vol1" created
You can view information about your newly created logical volume using the lvdisplay command:
holly:/# lvdisplay --- Logical volume --- LV Name /dev/vol_grp1/log_vol1 VG Name vol_grp1 LV UUID 9dErU7-YDsg-YDbh-SEWR-yVo6-Wc!0-[[RBqXke]] LV Write Access read/write LV Status available # open 0 LV Size 68.50 GB Current LE 17536 Segments 1 Allocation next free (default) Read ahead sectors 0 Block device 254:0
- Now it's time to create a filesystem on the logical volume (analogous to formatting a hard disk partition.) This example creates an ext3 filesystem using the standard Linux commands:
holly:/# mke2fs /dev/vol_grp1/log_vol1 mke2fs 1.27 (8-Mar-2002) Filesystem label= OS type: Linux Block size=4096 (log=2)
Fragment size=4096 (log=2) 8978432 inodes, 17956864 blocks 897843 blocks (5.00%) reserved for the super user First data block=0 548 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, 1605632, 2654208, 4096000, 7962624, 11239424
Writing inode tables: done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. holly:/# tune2fs -j /dev/vol_grp1/log_vol1 tune2fs 1.27 (8-Mar-2002) Creating journal inode: done This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. }}}
Now it remains to mount and test the new filesystem. This is done by using the standard mount command:
holly:/# mount /dev/vol_grp1/log_vol1 /mnt
Your new filesystem should now be mounted and ready to have data written to it. You can, of course, mount the filesystem in some other location such as /home and you can add a line to /etc/fstab to have it mounted automatically on system boot. For example, this line will mount the logical volume at /home automatically on system boot:
/dev/vol_grp1/log_vol1 /home ext3 defaults 0 2