/[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.14 - (show annotations) (download) (as text)
Tue Aug 16 22:30:19 2005 UTC (9 years, 1 month ago) by neysx
Branch: MAIN
Changes since 1.13: +7 -7 lines
File MIME type: application/xml
#102294 Use 1GB for the root partition to leave some space for kernel modules under /lib

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

  ViewVC Help
Powered by ViewVC 1.1.20