Penguin
Annotated edit history of LVMNotes version 17, including all changes. View license author blame.
Rev Author # Line
17 CraigBox 1 !!!Setting up [LVM] under Linux on a single drive
4 PerryLorier 2
3 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.
4
5 !!Scenario
6
7 You have a 36gb disc (this might be a RAID logical volume already, but the system sees it as one disc with 36gb on it). You want to install partitions for /usr, /var etc (smart) but you're not sure what sizes they need to be and you will want to be able to resize them in future.
8
9 !!Solution
10
11 At install time, create a small (<100mb) /boot, swap, and a reasonable (4-6gb) / partition. Leave the rest of the space unpartitioned.
12
10 JohnMcPherson 13 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.
13 MichaelBordignon 14 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:
15
17 CraigBox 16 <pre>
13 MichaelBordignon 17 LVM2 requires the device-mapper kernel module (dm-mod). This is
18 available as a kernel patch for 2.4 (included as standard in
19 current Debian 2.4 kernels), and is distributed with linux 2.5 and above.
17 CraigBox 20 </pre>
14 MichaelBordignon 21
22 Apply the patch with something like
23
17 CraigBox 24 <pre>
14 MichaelBordignon 25 # patch -p1 /path/device-mapper.1.01.03/patches/linux-2.4.28-pre4-devmapper-ioctl.patch
17 CraigBox 26 </pre>
14 MichaelBordignon 27
4 PerryLorier 28
29 !Create a PV[1] partition on your drive
30
17 CraigBox 31 <pre>
5 CraigBox 32 # fdisk /dev/sda
17 CraigBox 33 </pre>
4 PerryLorier 34
35 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.
36
37 !Prepare the partition
5 CraigBox 38
39 First, run vgscan:
17 CraigBox 40 <pre>
5 CraigBox 41 # vgscan
42 vgscan -- reading all physical volumes (this may take a while...)
43 vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
16 CraigBox 44 vgscan -- WARNING: This program does not do a VGDA backup of your volume group [4]
17 CraigBox 45 </pre>
4 PerryLorier 46
47 This creates a volume group descriptor area (VGDA) at the start of the disks.
17 CraigBox 48 <pre>
5 CraigBox 49 # pvcreate /dev/sda4
50 pvcreate -- physical volume "/dev/sda4" successfully created
17 CraigBox 51 </pre>
4 PerryLorier 52
16 CraigBox 53 !Create a volume group (VG) [2]
4 PerryLorier 54
55 This volume group can contain multiple discs, but in this case it only uses one.
56
17 CraigBox 57 <pre>
4 PerryLorier 58 # vgcreate lvmarray /dev/sda4
59 vgcreate -- INFO: using default physical extent size 4 MB
60 vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
61 vgcreate -- doing automatic backup of volume group "lvmarray"
62 vgcreate -- volume group "lvmarray" successfully created and activated
63
64 # vgdisplay
17 CraigBox 65 </pre>
4 PerryLorier 66 Confirm that the VG size is the right amount for the size of the partition.
6 DanielLawson 67
68 Note that if you use devfs, you'll need to use the full devfs pathname, not the /dev/sda4 symlink.
8 EricDexter 69 EG:, use /dev/scsi/host0/bus0/target0/lun0/part4 instead of /dev/sda4
4 PerryLorier 70
71 !Create some LVs [3]
72
17 CraigBox 73 <pre>
4 PerryLorier 74 # lvcreate -L20G -nhome lvmarray
75 lvcreate -- doing automatic backup of "lvmarray"
76 lvcreate -- logical volume "/dev/lvmarray/home" successfully created
77
78 # lvcreate -L5G -nvar lvmarray
79 lvcreate -- doing automatic backup of "lvmarray"
80 lvcreate -- logical volume "/dev/lvmarray/var" successfully created
81
82 # lvcreate -L5G -nusr lvmarray
83 lvcreate -- only 793 free physical extents in volume group "lvmarray"
84
85 # lvcreate -L793 -nusr lvmarray
86 lvcreate -- rounding size up to physical extent boundary
87 lvcreate -- doing automatic backup of "lvmarray"
88 lvcreate -- logical volume "/dev/lvmarray/usr" successfully created
17 CraigBox 89 </pre>
4 PerryLorier 90
91 !Create filesystems on your LVs
92
17 CraigBox 93 <pre>
4 PerryLorier 94 # for i in home var usr; do mke2fs -j /dev/lvmarray/$i; done
17 CraigBox 95 </pre>
4 PerryLorier 96
97 (Now would be a good time to learn about label based mounting!)
98
99 !Mount your LVs
100
17 CraigBox 101 <pre>
4 PerryLorier 102 mount /dev/lvmarray/home /home
17 CraigBox 103 </pre>
4 PerryLorier 104
105 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.
15 BenCorley 106
107 If you get an this error message with the above command:
17 CraigBox 108 <pre>
15 BenCorley 109 mount: special device /dev/lvmarray/home does not exist
17 CraigBox 110 </pre>
15 BenCorley 111 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.
4 PerryLorier 112
113 !!Resizing logical volumes
114
115 Oops! Just created 20g /home, 5gb /var and 860mb /usr. So lets take 4gb from home and add it to usr.
116
17 CraigBox 117 <pre>
4 PerryLorier 118 # umount /home
119 # e2fsadm -L-4G /dev/lvmarray/home
120 # mount /home
121
122 # umount /usr
123 # e2fsadm -L+4G /dev/lvmarray/usr
124 # mount /usr
17 CraigBox 125 </pre>
4 PerryLorier 126
127 e2fsadm is a utility that comes with LVM that lets you automatically fsck, resize FS and then resize LV.
128
17 CraigBox 129 <pre>
4 PerryLorier 130 # e2fsadm -L+1G /foo
17 CraigBox 131 </pre>
4 PerryLorier 132
133 is equivalent to the two commands:
134
17 CraigBox 135 <pre>
4 PerryLorier 136 # lvextend -L+1G /foo
137 # resize2fs /foo
17 CraigBox 138 </pre>
4 PerryLorier 139
140
141 You need to have e2fsprogs installed for this to work (but you probably needed it to make the FS to start with.)
142 When the time comes to learn to resize [LVM] partitions, there'll be more. Until then, see http://tldp.org/HOWTO/LVM-HOWTO
11 CraigBox 143
17 CraigBox 144 !!! LVM under Debian Sarge
11 CraigBox 145
146 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.
147
148 There are two version of LVM:
149 # LVM1 (lvm10 in woody/sarge) work only with linux-2.4.
150 # LVM2 (lvm2, only in sarge) work with both linux-2.4 and 2.6, and is backward compatible with LVM1.
4 PerryLorier 151
152 -----
153 !!Terminology
154
17 CraigBox 155 #[|ftnt_1]~[[1|#ftnt_ref_1]~] __PV__: Physical Volume; a disc or a partition on a disc.
156 #[|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.
157 #[|ftnt_3]~[[3|#ftnt_ref_3]~] __LV__: Logical Volume; something you eventually create an FS on.
158 #[|ftnt_4]~[[4|#ftnt_ref_4]~] To create a __VGDA__ (Volume Group Descriptor Area) backup, use !vgcfgbackup(8).
159
160 -----
161 !!!"Incorrect metadata area header checksum" error
162
163 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).
164
165 The installer has written an LVM checksum to /boot, and LVM tools are confused when they see it.
166
167 So, edit ''/etc/lvm/lvm.conf'' - change
168
169 <verbatim>
170 filter = [ "r|/dev/cdrom|" ]
171 </verbatim>
172 to
173 <verbatim>
174 filter = [ "r|/dev/cdrom|", "r|/dev.*hda1|" ]
175 </verbatim>
176
177 The regexp match is to catch both /dev/hda1 and /dev/evms/hda1.