1 |
<?xml version='1.0' encoding="UTF-8"?> |
2 |
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/lvm2.xml,v 1.30 2013/01/18 23:06:26 nightmorph Exp $ --> |
3 |
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
4 |
|
5 |
<guide> |
6 |
<title>Gentoo LVM2 installation</title> |
7 |
|
8 |
<author title="Author"> |
9 |
<mail link="avi@CFFtechnologies.com">Avi Schwartz</mail> |
10 |
</author> |
11 |
<author title="Contributor"> |
12 |
<mail link="rajiv@gentoo.org">Rajiv Manglani</mail> |
13 |
</author> |
14 |
<author title="Editor"> |
15 |
<mail link="neysx@gentoo.org">Xavier Neys</mail> |
16 |
</author> |
17 |
|
18 |
<abstract> |
19 |
This guide describes how to setup your Gentoo machine using the Logical Volume |
20 |
Manager version 2 (LVM2). |
21 |
</abstract> |
22 |
|
23 |
<!-- The content of this document is licensed under the CC-BY-SA license --> |
24 |
<!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
25 |
<license/> |
26 |
|
27 |
<version>8</version> |
28 |
<date>2013-01-20</date> |
29 |
|
30 |
<chapter> |
31 |
<title>Introduction</title> |
32 |
<section> |
33 |
<body> |
34 |
|
35 |
<p> |
36 |
This guide is based on an example with two SATA hard disks. It means that you |
37 |
will more than likely need to change the drive, partition names and partition |
38 |
sizes to match your own setup and needs. |
39 |
</p> |
40 |
|
41 |
<warn> |
42 |
This document is not intended to be an LVM2 tutorial. It serves as a |
43 |
supplement to the Gentoo installation procedure as described in the <uri |
44 |
link="/doc/en/handbook/handbook-x86.xml?part=1">Handbook, Part 1</uri>. Make |
45 |
sure you <e>read</e> the Gentoo Installation Manual <e>before</e> you start |
46 |
your installation process. |
47 |
</warn> |
48 |
|
49 |
<note> |
50 |
For a complete LVM HOWTO point your browser to |
51 |
<uri>http://tldp.org/HOWTO/LVM-HOWTO</uri> |
52 |
</note> |
53 |
|
54 |
</body> |
55 |
</section> |
56 |
<section> |
57 |
<title>Initial requirements</title> |
58 |
<body> |
59 |
|
60 |
<p> |
61 |
If you do a fresh install of Gentoo, you will need to use a bootable CD with |
62 |
LVM2 support such as a Gentoo Installation CD. You can find the Installation CDs |
63 |
for an x86 architecture on our <uri link="/main/en/mirrors.xml">mirrors</uri> |
64 |
under <path>/releases/x86/current/installcd</path>. Other architectures might be |
65 |
supported as well. |
66 |
</p> |
67 |
|
68 |
<p> |
69 |
If you install LVM2 on a currently running system with some spare hard disk |
70 |
space, you will need to enable the LVM2 module (<path>dm-mod</path>) in the |
71 |
kernel. This module is available in <path>gentoo-sources</path>. Compiling |
72 |
your kernel and getting LVM2 to work is covered later in this guide. |
73 |
</p> |
74 |
|
75 |
</body> |
76 |
</section> |
77 |
<section> |
78 |
<title>Partitions</title> |
79 |
<body> |
80 |
|
81 |
<p> |
82 |
Our example system has two SATA hard disks and will be partitioned as follows: |
83 |
</p> |
84 |
|
85 |
<ul> |
86 |
<li>/dev/sda1 -- /boot</li> |
87 |
<li>/dev/sda2 -- (swap)</li> |
88 |
<li>/dev/sda3 -- /</li> |
89 |
<li>/dev/sda4 -- Will be used by LVM2</li> |
90 |
<li>/dev/sdb1 -- Will be used by LVM2</li> |
91 |
</ul> |
92 |
|
93 |
<impo> |
94 |
Pay attention to the partition names as it is easy to confuse the a's and b's, |
95 |
and the partition numbers. One false move could wipe out the wrong partition. |
96 |
You have been warned! |
97 |
</impo> |
98 |
|
99 |
<p> |
100 |
OK, time to start... |
101 |
</p> |
102 |
|
103 |
</body> |
104 |
</section> |
105 |
</chapter> |
106 |
|
107 |
<chapter> |
108 |
<title>Installation</title> |
109 |
<section> |
110 |
<body> |
111 |
|
112 |
<p> |
113 |
Follow the handbook, but with the following amendments to chapter <e>4. |
114 |
Preparing the Disks</e>: |
115 |
</p> |
116 |
|
117 |
<p> |
118 |
Use <c>fdisk</c> as described in the handbook, but use the partition scheme |
119 |
mentioned above as an example. It is only <e>an example</e>, adapt it to your |
120 |
own needs. |
121 |
</p> |
122 |
|
123 |
<p> |
124 |
Create a small physical <path>/boot</path> partition (sda1). In this example, |
125 |
<path>/boot</path> will be not managed by LVM2. This partition will contain |
126 |
your bootloader and your kernel(s). A 64MB partition should be well enough for |
127 |
quite a few kernel generations. |
128 |
</p> |
129 |
|
130 |
<p> |
131 |
Create a swap partition (sda2). |
132 |
</p> |
133 |
|
134 |
<p> |
135 |
Create a / (root) partition (sda3). If you are interested in trying to put your |
136 |
root partition under LVM management (which we do not recommend), see the |
137 |
resources section at the end of this guide for a link to a mini-howto on how to |
138 |
do this. The size of the root partition need not be large if you will keep |
139 |
<path>/opt /usr /home /var</path> and <path>/tmp</path> in an LVM2 Volume Group |
140 |
(vg). In this case, 1GB should be sufficient. Note however that, if you have |
141 |
<path>/usr</path> or <path>/var</path> in an LVM2 volume group, you will need to |
142 |
boot the system with an initramfs. |
143 |
</p> |
144 |
|
145 |
<note> |
146 |
It is <b>not</b> recommended to put the following directories in an |
147 |
LVM2 partition: <path>/etc</path>, <path>/lib</path>, <path>/mnt</path>, |
148 |
<path>/proc</path>, <path>/sbin</path>, <path>/dev</path>, and |
149 |
<path>/root</path>. This way, you would still be able to log into your system |
150 |
(crippled, but still somewhat usable, as root) if something goes terribly wrong. |
151 |
Also exclude <path>/usr</path> and <path>/var</path> from LVM2 if you do not |
152 |
want to boot with an initramfs. |
153 |
</note> |
154 |
|
155 |
<p> |
156 |
Assuming the <path>/boot</path>, swap and root partitions do not use the whole |
157 |
physical disk, create a fourth partition on this disk and set it to type 8e |
158 |
(Linux LVM). If you have more physical drives you would like to use with LVM, |
159 |
create one partition on each and give them the same type (8e). |
160 |
</p> |
161 |
|
162 |
<note> |
163 |
Considering the huge size of current disks, you might consider splitting your |
164 |
hard disks into smaller partitions instead of creating a big partition that |
165 |
will be added to an LVM2 volume group in one block. LVM2 makes it easy to |
166 |
extend your volumes after all. This leaves you some unallocated partitions you |
167 |
might need to use outside of an LVM2 group. In short, don't use your disk space |
168 |
until you know you need it. As an example, one contributor had split his |
169 |
160 Gb hard disk into 8 partitions of 20 Gb each. |
170 |
</note> |
171 |
|
172 |
<p> |
173 |
Create the filesystems on <path>/dev/sda1</path> and <path>/dev/sda3</path>, |
174 |
and create and activate the swap on <path>/dev/sda2</path> as described in the |
175 |
handbook. |
176 |
</p> |
177 |
|
178 |
<p> |
179 |
Start the lvm service. |
180 |
</p> |
181 |
|
182 |
<pre caption="Starting the lvm service"> |
183 |
# <i>rc-config start lvm</i> |
184 |
</pre> |
185 |
|
186 |
<p> |
187 |
It is recommended to add the lvm service to the boot runlevel. This way LVM2 |
188 |
will be activated each time the system boots. |
189 |
</p> |
190 |
|
191 |
<pre caption="Adding lvm to the boot runlevel"> |
192 |
# <i>rc-config add lvm boot</i> |
193 |
</pre> |
194 |
|
195 |
<p> |
196 |
Before scanning and activating LVM, you might want to edit |
197 |
<path>/etc/lvm/lvm.conf</path> to exclude some devices. By default, LVM2 will |
198 |
scan all devices, even your CDROM which can generate error messages. In the |
199 |
following example, the line that allows scanning of all devices is replaced by |
200 |
one that rejects every device but our two SATA disks. |
201 |
</p> |
202 |
|
203 |
<pre caption="Activating LVM"> |
204 |
<comment>(Avoid scanning all devices but our disks)</comment> |
205 |
# <i>nano -w /etc/lvm/lvm.conf</i> |
206 |
<comment>(Look for the following line)</comment> |
207 |
filter = [ "a/.*/" ] |
208 |
<comment>(Replace it with the following one to scan |
209 |
/dev/sda and /dev/sdb and reject anything else)</comment> |
210 |
filter = [ "a|/dev/sd[ab]|", "r/.*/" ] |
211 |
<comment>(Save the file and quit nano)</comment> |
212 |
# <i>vgscan</i> |
213 |
Reading all physical volumes. This may take a while... |
214 |
No volume groups found |
215 |
<comment>(Make any previously set up volume groups available)</comment> |
216 |
# <i>vgchange -a y</i> |
217 |
</pre> |
218 |
|
219 |
<p> |
220 |
Prepare the partitions. |
221 |
</p> |
222 |
|
223 |
<pre caption="Preparing the partitions"> |
224 |
# <i>pvcreate /dev/sda4 /dev/sdb1</i> |
225 |
No physical volume label read from /dev/sda4 |
226 |
Physical volume "/dev/sda4" successfully created |
227 |
No physical volume label read from /dev/sdb1 |
228 |
Physical volume "/dev/sdb1" successfully created |
229 |
</pre> |
230 |
|
231 |
<p> |
232 |
Setup a volume group. A volume group is the result of combining several |
233 |
physical units into a single logical device. |
234 |
</p> |
235 |
|
236 |
<p> |
237 |
In our example, <path>/dev/sda1</path>, <path>/dev/sda2</path> and |
238 |
<path>/dev/sda3</path> are the <path>/boot</path>, swap and root partitions so |
239 |
we need to combine <path>/dev/sda4</path> and <path>/dev/sdb1</path>. It can be |
240 |
done with a single command, but, as an example, we will create our volume group |
241 |
and extend it. |
242 |
</p> |
243 |
|
244 |
<pre caption="Creating and extending a volume group"> |
245 |
<comment>(Create a volume group named vg)</comment> |
246 |
# <i>vgcreate vg /dev/sda4</i> |
247 |
/etc/lvm/backup: fsync failed: Invalid argument <comment>(Ignore this warning)</comment> |
248 |
Volume group "vg" successfully created |
249 |
<comment>(Extending an existing volume group)</comment> |
250 |
# <i>vgextend vg /dev/sdb1</i> |
251 |
/etc/lvm/backup: fsync failed: Invalid argument <comment>(Ignore this warning, again and later as well)</comment> |
252 |
Volume group "vg" successfully extended |
253 |
</pre> |
254 |
|
255 |
<p> |
256 |
Create the logical volumes. Logical volumes are the equivalent of partitions |
257 |
you would create using fdisk in a non LVM2 environment. In our example, we |
258 |
create the following partitions: |
259 |
</p> |
260 |
|
261 |
<table> |
262 |
<tr> |
263 |
<th>Directory</th> |
264 |
<th>Size</th> |
265 |
</tr> |
266 |
<tr> |
267 |
<ti>/usr</ti> |
268 |
<ti>10 GB</ti> |
269 |
</tr> |
270 |
<tr> |
271 |
<ti>/home</ti> |
272 |
<ti>5 GB</ti> |
273 |
</tr> |
274 |
<tr> |
275 |
<ti>/opt</ti> |
276 |
<ti>5 GB</ti> |
277 |
</tr> |
278 |
<tr> |
279 |
<ti>/var</ti> |
280 |
<ti>10 GB</ti> |
281 |
</tr> |
282 |
<tr> |
283 |
<ti>/tmp</ti> |
284 |
<ti>2 GB</ti> |
285 |
</tr> |
286 |
</table> |
287 |
|
288 |
<p> |
289 |
Since we are going to use LVM2, we should not worry too much about partition |
290 |
sizes because they can always be expanded as needed. |
291 |
</p> |
292 |
|
293 |
<note> |
294 |
As Terje Kvernes commented, it is easier to increase the size of a partition |
295 |
then to shrink it. You might therefore want to start with smaller partitions |
296 |
and increase their size as needed. |
297 |
</note> |
298 |
|
299 |
<pre caption="Creating and extending logical volumes"> |
300 |
# <i>lvcreate -L10G -nusr vg</i> |
301 |
Logical volume "usr" created <comment>(Further similar messages not displayed)</comment> |
302 |
# <i>lvcreate -L5G -nhome vg</i> |
303 |
# <i>lvcreate -L5G -nopt vg</i> |
304 |
# <i>lvcreate -L10G -nvar vg</i> |
305 |
# <i>lvcreate -L2G -ntmp vg</i> |
306 |
<comment>(As an example, let's extend a logical volume with 5 extra Gbytes)</comment> |
307 |
# <i>lvextend -L+5G /dev/vg/home</i> |
308 |
</pre> |
309 |
|
310 |
<p> |
311 |
Create filesystems on the logical volumes the same way you would on a regular |
312 |
partition. We use ext3 on the logical volumes but any filesystem of your |
313 |
choice will work: |
314 |
</p> |
315 |
|
316 |
<pre caption="Creating the filesystems"> |
317 |
# <i>mke2fs -j /dev/vg/usr</i> |
318 |
# <i>mke2fs -j /dev/vg/home</i> |
319 |
# <i>mke2fs -j /dev/vg/opt</i> |
320 |
# <i>mke2fs -j /dev/vg/var</i> |
321 |
# <i>mke2fs -j /dev/vg/tmp</i> |
322 |
</pre> |
323 |
|
324 |
<p> |
325 |
Mount your partitions as described in the handbook and mount your LVM2 logical |
326 |
volumes as if they were partitions. Replace the usual <path>/dev/sdxx</path> |
327 |
with <path>/dev/vg/logical_volumename</path>. |
328 |
</p> |
329 |
|
330 |
<pre caption="Mounting your logical volumes"> |
331 |
<comment>(Make sure you have mounted your root partition as described in the handbook first)</comment> |
332 |
# <i>mkdir /mnt/gentoo/usr</i> |
333 |
# <i>mount /dev/vg/usr /mnt/gentoo/usr</i> |
334 |
# <i>mkdir /mnt/gentoo/home</i> |
335 |
# <i>mount /dev/vg/home /mnt/gentoo/home</i> |
336 |
# <i>mkdir /mnt/gentoo/opt</i> |
337 |
# <i>mount /dev/vg/opt /mnt/gentoo/opt</i> |
338 |
# <i>mkdir /mnt/gentoo/var</i> |
339 |
# <i>mount /dev/vg/var /mnt/gentoo/var</i> |
340 |
# <i>mkdir /mnt/gentoo/tmp</i> |
341 |
# <i>mount /dev/vg/tmp /mnt/gentoo/tmp</i> |
342 |
</pre> |
343 |
|
344 |
<note> |
345 |
The rest of the installation handbook is mostly unchanged so we shall not |
346 |
walk you through it again except to point out differences. |
347 |
</note> |
348 |
|
349 |
<p> |
350 |
When configuring your kernel, make sure to configure your kernel to |
351 |
support LVM2. Select the LVM2 module as follows: |
352 |
</p> |
353 |
|
354 |
<pre caption="Selecting the LVM2 module in the Linux kernel"> |
355 |
Device Drivers ---> |
356 |
Multiple devices driver support (RAID and LVM) ---> |
357 |
[*] Multiple devices driver support (RAID and LVM) |
358 |
< > RAID support |
359 |
<M> Device mapper support |
360 |
</pre> |
361 |
|
362 |
<p> |
363 |
The compiled module is called <path>dm-mod.ko</path> |
364 |
</p> |
365 |
|
366 |
<p> |
367 |
Also build an initramfs if you have <path>/usr</path> or <path>/var</path> on an |
368 |
LVM-based partition. Don't forget to edit your boot loader to boot the system |
369 |
with the initramfs and add in <c>dolvm</c> as a boot parameter. |
370 |
</p> |
371 |
|
372 |
<pre caption="Building an initramfs"> |
373 |
# <i>emerge genkernel</i> |
374 |
# <i>genkernel --lvm --install initramfs</i> |
375 |
# <i>nano -w /boot/grub/grub.conf</i> |
376 |
<comment>(...)</comment> |
377 |
title Gentoo Linux |
378 |
root (hd0,0) |
379 |
kernel /kernel-3.2.2-gentoo-r5 root=/dev/sda1 <i>dolvm</i> |
380 |
<i>initrd /initramfs-genkernel-x86_64-3.2.2-gentoo-r5</i> |
381 |
</pre> |
382 |
|
383 |
<p> |
384 |
Now, install the lvm2 package. |
385 |
</p> |
386 |
|
387 |
<impo> |
388 |
Make sure your <path>/usr/src/linux</path> link points to the kernel sources you |
389 |
are using because the lvm2 ebuild depends on the device-mapper ebuild which |
390 |
will check the presence of a required source file under |
391 |
<path>/usr/src/linux/include/linux</path>. |
392 |
</impo> |
393 |
|
394 |
<pre caption="Emerging the LVM2 package"> |
395 |
# <i>emerge lvm2</i> |
396 |
</pre> |
397 |
|
398 |
<p> |
399 |
Edit <path>/etc/lvm/lvm.conf</path> as described <uri |
400 |
link="#doc_chap2_pre2">earlier</uri>. The file you previously edited is part of |
401 |
your installation environment and will disappear after the next reboot. This |
402 |
time, you edit the real one inside your new Gentoo install. |
403 |
</p> |
404 |
|
405 |
<p> |
406 |
When editing your <path>/etc/fstab</path> file, follow the handbook and add |
407 |
your LVM2 logical volumes as needed. Again, here are a few lines needed for |
408 |
our example: |
409 |
</p> |
410 |
|
411 |
<pre caption="Extract of /etc/fstab"> |
412 |
/dev/sda1 /boot ext3 noauto,noatime 1 2 |
413 |
/dev/sda2 none swap sw 0 0 |
414 |
/dev/sda3 / ext3 noatime 0 1 |
415 |
# Logical volumes |
416 |
/dev/vg/usr /usr ext3 noatime 0 2 |
417 |
/dev/vg/home /home ext3 noatime 0 2 |
418 |
/dev/vg/opt /opt ext3 noatime 0 2 |
419 |
/dev/vg/var /var ext3 noatime 0 2 |
420 |
/dev/vg/tmp /tmp ext3 noatime 0 2 |
421 |
</pre> |
422 |
|
423 |
<p> |
424 |
When you reach the end of the installation part of the handbook, don't forget |
425 |
to umount all your LVM2 logical volumes as well and for a good measure run the |
426 |
following command before you reboot: |
427 |
</p> |
428 |
|
429 |
<pre caption="Shutting down LVM2"> |
430 |
# <i>vgchange -a n</i> |
431 |
</pre> |
432 |
|
433 |
<p> |
434 |
Restart your machine and all partitions should be visible and mounted. |
435 |
</p> |
436 |
|
437 |
</body> |
438 |
</section> |
439 |
</chapter> |
440 |
|
441 |
<chapter> |
442 |
<title>Continuing After a Reboot</title> |
443 |
<section> |
444 |
<body> |
445 |
|
446 |
<p> |
447 |
If you have interrupted the Gentoo installation at one point and want to |
448 |
continue, you need to create the volume device nodes first: |
449 |
</p> |
450 |
|
451 |
<pre caption="Reactivating the volumes"> |
452 |
# <i>vgscan --mknodes</i> |
453 |
</pre> |
454 |
|
455 |
<p> |
456 |
Installation CDs with less recent tools might need to reactivate the volumes |
457 |
instead: |
458 |
</p> |
459 |
|
460 |
<pre caption="Reactivating the volumes"> |
461 |
<comment>(Deactivate all volumes first)</comment> |
462 |
# <i>vgchange -a n</i> |
463 |
<comment>(Export all the volumes)</comment> |
464 |
# <i>vgexport -a</i> |
465 |
<comment>(Import all volumes)</comment> |
466 |
# <i>vgimport -a</i> |
467 |
<comment>(Reactivate all volumes)</comment> |
468 |
# <i>vgchange -a y</i> |
469 |
</pre> |
470 |
|
471 |
</body> |
472 |
</section> |
473 |
</chapter> |
474 |
|
475 |
<chapter> |
476 |
<title>Resources</title> |
477 |
<section> |
478 |
<body> |
479 |
|
480 |
<ul> |
481 |
<li> |
482 |
The official <uri link="http://sources.redhat.com/lvm2">LVM2 home page</uri> |
483 |
</li> |
484 |
<li> |
485 |
The <uri link="http://tldp.org/HOWTO/LVM-HOWTO">LVM Howto</uri> |
486 |
</li> |
487 |
<li> |
488 |
Daniel Robbins's articles on LVM for IBM's DeveloperWorks: <uri |
489 |
link="/doc/en/articles/lvm-p1.xml">Part 1</uri> and <uri |
490 |
link="/doc/en/articles/lvm-p2.xml">Part 2</uri> |
491 |
</li> |
492 |
<li> |
493 |
How to boot your root FS off of LVM1: |
494 |
<uri>http://www.the-infinite.org/archive/docs/lvm/howto-boot-off-root-lv.txt</uri> |
495 |
</li> |
496 |
</ul> |
497 |
|
498 |
</body> |
499 |
</section> |
500 |
</chapter> |
501 |
|
502 |
<chapter> |
503 |
<title>Acknowledgements</title> |
504 |
<section> |
505 |
<body> |
506 |
|
507 |
<p> |
508 |
Thanks <mail link="bangert@gentoo.org">Thilo Bangert</mail> and <mail |
509 |
link="terjekv@math.uio.no">Terje Kvernes</mail> for their help and comments on |
510 |
this document. |
511 |
</p> |
512 |
|
513 |
</body> |
514 |
</section> |
515 |
</chapter> |
516 |
</guide> |