/[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.22 - (show annotations) (download) (as text)
Mon Feb 26 08:58:04 2007 UTC (7 years, 6 months ago) by nightmorph
Branch: MAIN
Changes since 1.21: +5 -6 lines
File MIME type: application/xml
further vanilla-sources removals as it's unsupported

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

  ViewVC Help
Powered by ViewVC 1.1.20