/[gentoo]/xml/htdocs/doc/en/lvm2.xml
Gentoo

Contents of /xml/htdocs/doc/en/lvm2.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (hide annotations) (download) (as text)
Fri Nov 10 21:59:06 2006 UTC (7 years, 9 months ago) by nightmorph
Branch: MAIN
Changes since 1.20: +7 -8 lines
File MIME type: application/xml
fixed path to x86 installcd dir, thanks to diox for reporting on IRC

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

  ViewVC Help
Powered by ViewVC 1.1.20