Differences between current version and revision by previous author of LVMNotes.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 17 | Last edited on Monday, March 5, 2007 10:54:24 am | by CraigBox | |
Older page: | version 15 | Last edited on Friday, December 23, 2005 7:51:43 pm | by BenCorley | Revert |
@@ -1,5 +1,5 @@
-!!Setting up [LVM] under Linux on a single drive
+!
!!Setting up [LVM] under Linux on a single drive
You will want to make sure Multi device support ([RAID] and [LVM]) is enabled and LVM support is compiled into your kernel. You could build it as a module and load it from your initrd, but you don't really need to go to the effort.
!!Scenario
@@ -12,53 +12,66 @@
Make sure LVM is compiled into your kernel, and you have the LVM tools installed. Debian 3 (woody): install lvm10. Debian Sarge/Sid: install lvm2.
Gentoo has lvm (1.01) and lvm2. You may also need the device-mapper patch for 2.4.x kernels, available at ftp://sources.redhat.com/pub/dm/. From the LVM2 README.Debian:
+<pre>
LVM2 requires the device-mapper kernel module (dm-mod). This is
available as a kernel patch for 2.4 (included as standard in
current Debian 2.4 kernels), and is distributed with linux 2.5 and above.
+</pre>
Apply the patch with something like
+<pre>
# patch -p1 /path/device-mapper.1.01.03/patches/linux-2.4.28-pre4-devmapper-ioctl.patch
+</pre>
!Create a PV[1] partition on your drive
+<pre>
# fdisk /dev/sda
+</pre>
Set the type of this partition (which, in my case, is primary partition 4 and eats the rest of my disc) to 8e - Linux LVM.
!Prepare the partition
First, run vgscan:
+<pre>
# vgscan
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
- vgscan -- WARNING: This program does not do a VGDA backup of your volume group[4]
+ vgscan -- WARNING: This program does not do a VGDA backup of your volume group [4]
+</pre>
This creates a volume group descriptor area (VGDA) at the start of the disks.
+<pre>
# pvcreate /dev/sda4
pvcreate -- physical volume "/dev/sda4" successfully created
+</pre>
-!Create a volume group (VG)[2]
+!Create a volume group (VG) [2]
This volume group can contain multiple discs, but in this case it only uses one.
+<pre>
# vgcreate lvmarray /dev/sda4
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 "lvmarray"
vgcreate -- volume group "lvmarray" successfully created and activated
# vgdisplay
+</pre>
Confirm that the VG size is the right amount for the size of the partition.
Note that if you use devfs, you'll need to use the full devfs pathname, not the /dev/sda4 symlink.
EG:, use /dev/scsi/host0/bus0/target0/lun0/part4 instead of /dev/sda4
!Create some LVs [3]
+<pre>
# lvcreate -L20G -nhome lvmarray
lvcreate -- doing automatic backup of "lvmarray"
lvcreate -- logical volume "/dev/lvmarray/home" successfully created
@@ -72,51 +85,64 @@
# lvcreate -L793 -nusr lvmarray
lvcreate -- rounding size up to physical extent boundary
lvcreate -- doing automatic backup of "lvmarray"
lvcreate -- logical volume "/dev/lvmarray/usr" successfully created
+</pre>
!Create filesystems on your LVs
+<pre>
# for i in home var usr; do mke2fs -j /dev/lvmarray/$i; done
+</pre>
(Now would be a good time to learn about label based mounting!)
!Mount your LVs
+<pre>
mount /dev/lvmarray/home /home
+</pre>
You will of course want to move everything from /home first, and add them to fstab(5) etc... To move your partitions, you'll probably want to be in runlevel 1.
If you get an this error message with the above command:
+<pre>
mount: special device /dev/lvmarray/home does not exist
+</pre>
then you may need to use "vgchange -ay" to activate the logical volumes. This can happen if you are booting to a LiveCD or have rebooted after creating the logical volumes.
!!Resizing logical volumes
Oops! Just created 20g /home, 5gb /var and 860mb /usr. So lets take 4gb from home and add it to usr.
+<pre>
# umount /home
# e2fsadm -L-4G /dev/lvmarray/home
# mount /home
# umount /usr
# e2fsadm -L+4G /dev/lvmarray/usr
# mount /usr
+</pre>
e2fsadm is a utility that comes with LVM that lets you automatically fsck, resize FS and then resize LV.
+<pre>
# e2fsadm -L+1G /foo
+</pre>
is equivalent to the two commands:
+<pre>
# lvextend -L+1G /foo
# resize2fs /foo
+</pre>
You need to have e2fsprogs installed for this to work (but you probably needed it to make the FS to start with.)
When the time comes to learn to resize [LVM] partitions, there'll be more. Until then, see http://tldp.org/HOWTO/LVM-HOWTO
-!! LVM under Debian Sarge
+!
!! LVM under Debian Sarge
If you are upgrading from a 2.4 to a 2.6 kernel and you have an LVM1 partition, you must install the 'lvm2' package.
There are two version of LVM:
@@ -125,8 +151,27 @@
-----
!!Terminology
-[1] __PV__: Physical Volume; a disc or a partition on a disc.
-[2] __VG__: Volume Group; a group of one-or-more physical volumes across which you get a "virtual disk", a space to create logical volumes in.
-[3] __LV__: Logical Volume; something you eventually create an FS on.
-[4] To create a __VGDA__ (Volume Group Descriptor Area) Backup
use !vgcfgbackup(8) regularly
+#
[|ftnt_
1]~[[1|#ftnt_ref_1]~]
__PV__: Physical Volume; a disc or a partition on a disc.
+#
[|ftnt_
2]~[[2|#ftnt_ref_2]~]
__VG__: Volume Group; a group of one-or-more physical volumes across which you get a "virtual disk", a space to create logical volumes in.
+#
[|ftnt_
3]~[[3|#ftnt_ref_3]~]
__LV__: Logical Volume; something you eventually create an FS on.
+#
[|ftnt_
4]~[[4|#ftnt_ref_4]~]
To create a __VGDA__ (Volume Group Descriptor Area) backup,
use !vgcfgbackup(8).
+
+-----
+!!!"Incorrect metadata area header checksum" error
+
+Found this one on a new Ubuntu install. /boot is on a separate partition to the LVM (which you should always do, as [LILO]/[GRUB] aren't good at booting off an LVM volume).
+
+The installer has written an LVM checksum to /boot, and LVM tools are confused when they see it.
+
+So, edit ''/etc/lvm/lvm.conf'' - change
+
+<verbatim>
+filter = [ "r|/dev/cdrom|" ]
+</verbatim>
+to
+<verbatim>
+filter = [ "r|/dev/cdrom|", "r|/dev.*hda1|" ]
+</verbatim>
+
+The regexp match is to catch both /dev/hda1 and /dev/evms/hda1.