/[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 - (show annotations) (download) (as text)
Tue Jul 23 14:38:52 2013 UTC (12 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 <?xml version='1.0' encoding="UTF-8"?>
2 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/lvm2.xml,v 1.31 2013/01/20 16:21:39 swift Exp $ -->
3 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
4
5 <guide disclaimer="obsolete" redirect="https://wiki.gentoo.org/wiki/LVM">
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>9</version>
28 <!-- Last content edit: 2013-01-20 -->
29 <date>2013/07/23</date>
30
31 <chapter>
32 <title>Introduction</title>
33 <section>
34 <body>
35
36 <p>
37 This guide is based on an example with two SATA hard disks. It means that you
38 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 link="/doc/en/handbook/handbook-x86.xml?part=1">Handbook, Part 1</uri>. Make
46 sure you <e>read</e> the Gentoo Installation Manual <e>before</e> you start
47 your installation process.
48 </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
55 </body>
56 </section>
57 <section>
58 <title>Initial requirements</title>
59 <body>
60
61 <p>
62 If you do a fresh install of Gentoo, you will need to use a bootable CD with
63 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 </p>
68
69 <p>
70 If you install LVM2 on a currently running system with some spare hard disk
71 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 </p>
75
76 </body>
77 </section>
78 <section>
79 <title>Partitions</title>
80 <body>
81
82 <p>
83 Our example system has two SATA hard disks and will be partitioned as follows:
84 </p>
85
86 <ul>
87 <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 </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
104 </body>
105 </section>
106 </chapter>
107
108 <chapter>
109 <title>Installation</title>
110 <section>
111 <body>
112
113 <p>
114 Follow the handbook, but with the following amendments to chapter <e>4.
115 Preparing the Disks</e>:
116 </p>
117
118 <p>
119 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 </p>
123
124 <p>
125 Create a small physical <path>/boot</path> partition (sda1). In this example,
126 <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 </p>
130
131 <p>
132 Create a swap partition (sda2).
133 </p>
134
135 <p>
136 Create a / (root) partition (sda3). If you are interested in trying to put your
137 root partition under LVM management (which we do not recommend), see the
138 resources section at the end of this guide for a link to a mini-howto on how to
139 do this. The size of the root partition need not be large if you will keep
140 <path>/opt /usr /home /var</path> and <path>/tmp</path> in an LVM2 Volume Group
141 (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 </p>
145
146 <note>
147 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 Also exclude <path>/usr</path> and <path>/var</path> from LVM2 if you do not
153 want to boot with an initramfs.
154 </note>
155
156 <p>
157 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 </p>
162
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 <p>
174 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 handbook.
177 </p>
178
179 <p>
180 Start the lvm service.
181 </p>
182
183 <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 </pre>
195
196 <p>
197 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 following example, the line that allows scanning of all devices is replaced by
201 one that rejects every device but our two SATA disks.
202 </p>
203
204 <pre caption="Activating LVM">
205 <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 /dev/sda and /dev/sdb and reject anything else)</comment>
211 filter = [ "a|/dev/sd[ab]|", "r/.*/" ]
212 <comment>(Save the file and quit nano)</comment>
213 # <i>vgscan</i>
214 Reading all physical volumes. This may take a while...
215 No volume groups found
216 <comment>(Make any previously set up volume groups available)</comment>
217 # <i>vgchange -a y</i>
218 </pre>
219
220 <p>
221 Prepare the partitions.
222 </p>
223
224 <pre caption="Preparing the partitions">
225 # <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 </pre>
231
232 <p>
233 Setup a volume group. A volume group is the result of combining several
234 physical units into a single logical device.
235 </p>
236
237 <p>
238 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 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 # <i>vgcreate vg /dev/sda4</i>
248 /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 # <i>vgextend vg /dev/sdb1</i>
252 /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 <p>
257 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 </p>
261
262 <table>
263 <tr>
264 <th>Directory</th>
265 <th>Size</th>
266 </tr>
267 <tr>
268 <ti>/usr</ti>
269 <ti>10 GB</ti>
270 </tr>
271 <tr>
272 <ti>/home</ti>
273 <ti>5 GB</ti>
274 </tr>
275 <tr>
276 <ti>/opt</ti>
277 <ti>5 GB</ti>
278 </tr>
279 <tr>
280 <ti>/var</ti>
281 <ti>10 GB</ti>
282 </tr>
283 <tr>
284 <ti>/tmp</ti>
285 <ti>2 GB</ti>
286 </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 then to shrink it. You might therefore want to start with smaller partitions
297 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 <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 </pre>
310
311 <p>
312 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 </p>
316
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 <p>
326 Mount your partitions as described in the handbook and mount your LVM2 logical
327 volumes as if they were partitions. Replace the usual <path>/dev/sdxx</path>
328 with <path>/dev/vg/logical_volumename</path>.
329 </p>
330
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 <p>
351 When configuring your kernel, make sure to configure your kernel to
352 support LVM2. Select the LVM2 module as follows:
353 </p>
354
355 <pre caption="Selecting the LVM2 module in the Linux kernel">
356 Device Drivers ---&gt;
357 Multiple devices driver 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 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 with the initramfs and add in <c>dolvm</c> as a boot parameter.
371 </p>
372
373 <pre caption="Building an initramfs">
374 # <i>emerge genkernel</i>
375 # <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 </pre>
383
384 <p>
385 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 </pre>
398
399 <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
406 <p>
407 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 </p>
411
412 <pre caption="Extract of /etc/fstab">
413 /dev/sda1 /boot ext3 noauto,noatime 1 2
414 /dev/sda2 none swap sw 0 0
415 /dev/sda3 / ext3 noatime 0 1
416 # Logical volumes
417 /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 </pre>
423
424 <p>
425 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 </p>
429
430 <pre caption="Shutting down LVM2">
431 # <i>vgchange -a n</i>
432 </pre>
433
434 <p>
435 Restart your machine and all partitions should be visible and mounted.
436 </p>
437
438 </body>
439 </section>
440 </chapter>
441
442 <chapter>
443 <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 # <i>vgexport -a</i>
466 <comment>(Import all volumes)</comment>
467 # <i>vgimport -a</i>
468 <comment>(Reactivate all volumes)</comment>
469 # <i>vgchange -a y</i>
470 </pre>
471
472 </body>
473 </section>
474 </chapter>
475
476 <chapter>
477 <title>Resources</title>
478 <section>
479 <body>
480
481 <ul>
482 <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 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 </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 </ul>
498
499 </body>
500 </section>
501 </chapter>
502
503 <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