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