/[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.25 - (hide annotations) (download) (as text)
Wed Feb 11 06:42:14 2009 UTC (5 years, 9 months ago) by nightmorph
Branch: MAIN
Changes since 1.24: +5 -5 lines
File MIME type: application/xml
options are not permitted after the a flag; bug 258547

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

  ViewVC Help
Powered by ViewVC 1.1.20