/[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.32 - (hide annotations) (download) (as text)
Tue Jul 23 14:38:52 2013 UTC (16 months ago) by swift
Branch: MAIN
CVS Tags: HEAD
Changes since 1.31: +5 -4 lines
File MIME type: application/xml
LVM2 now obsolete, refer to https://wiki.gentoo.org/wiki/LVM

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

  ViewVC Help
Powered by ViewVC 1.1.20