Gentoo Archives: gentoo-doc-cvs

From: Lukasz Damentko <rane@×××××××××××.org>
To: gentoo-doc-cvs@l.g.o
Subject: [gentoo-doc-cvs] cvs commit: lvm-p1.xml
Date: Tue, 20 Sep 2005 18:48:49
Message-Id: 200509201842.j8KIgoY3022530@robin.gentoo.org
1 rane 05/09/20 18:48:24
2
3 Added: xml/htdocs/doc/en/articles lvm-p1.xml lvm-p2.xml
4 Log:
5 two more articles, this time from #104169
6
7 Revision Changes Path
8 1.1 xml/htdocs/doc/en/articles/lvm-p1.xml
9
10 file : http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lvm-p1.xml?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=gentoo
11 plain: http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lvm-p1.xml?rev=1.1&content-type=text/plain&cvsroot=gentoo
12
13 Index: lvm-p1.xml
14 ===================================================================
15 <?xml version="1.0" encoding="UTF-8"?>
16 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
17 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/articles/lvm-p1.xml,v 1.1 2005/09/20 18:48:24 rane Exp $ -->
18
19 <guide link="/doc/en/articles/lvm-p1.xml">
20 <title>Learning Linux LVM, Part 1</title>
21
22 <author title="Author">
23 <mail link="drobbins@g.o">Daniel Robbins</mail>
24 </author>
25 <!-- xmlified by: Joshua Saddler (jackdark@×××××.com) -->
26
27 <abstract>
28 In this article, Daniel introduces you to the concepts behind Linux
29 LVM (Logical Volume Management) and shows you how to get the latest
30 kernel patches and tools installed on your system. LVM allows you to
31 create logical volumes out of the physical storage resources on your
32 machine. However, unlike physical volumes, the logical volumes can
33 be expanded and shrunk while the system is still running, providing
34 Linux system administrators with the storage flexibility that they've
35 until now only dreamed of.
36 </abstract>
37
38 <!-- The original version of this article was first published on IBM
39 developerWorks, and is property of Westtech Information Services. This
40 document is an updated version of the original article, and contains
41 various improvements made by the Gentoo Linux Documentation team -->
42
43 <version>1.0</version>
44 <date>2005-08-29</date>
45
46 <chapter>
47 <title>Storage management magic with Logical Volume Management</title>
48 <section>
49 <title>LVM intro</title>
50 <body>
51
52 <note>
53 The original version of this article was first published on IBM
54 developerWorks, and is property of Westtech Information Services. This
55 document is an updated version of the original article, and contains
56 various improvements made by the Gentoo Linux Documentation team.
57 </note>
58
59 <p>
60 In this series, I'm going to show you how to install and use the new
61 Logical Volume Management support built-in to the Linux 2.4 kernel. If
62 you've never used a form of LVM before, you're in for a treat; it's a
63 wonderful technology. Before we actually get LVM up and running, I'm
64 going to explain exactly what it is and how it works. Then, we'll be
65 ready to test out LVM and get the most out of it.
66 </p>
67
68 <p>
69 If you're like me, then your experience with UNIX and Linux began on
70 a PC platform, rather than on large, commercial UNIX servers and
71 workstations. On the basic PC, we've always had to deal with
72 partitioning our hard drives. PC people are generally well-acquainted
73 with tools such as <c>fdisk</c>, which are used to create and delete
74 primary and extended partitions on hard disks. Hard disk partitioning
75 is an annoying but accepted part of the process of getting an
76 operating system up and running.
77 </p>
78
79 <p>
80 Hard drive partitioning can be annoying because to do a good job you
81 really need to accurately estimate how much space you'll need for
82 each partition. If you make a poor estimation, your Linux system
83 could possibly be crippled -- to fix the problem, it's possible that
84 you might even need to perform a full system backup, wipe your hard
85 drives clean, and then restore all your data to a new (and presumably
86 better) partition layout. Ick! These are exactly the kinds of
87 situations that sysadmins try their best to avoid in the first place.
88 </p>
89
90 <p>
91 While partitions were once static storage regions, thankfully, we now
92 have a proliferation of PC repartitioning tools (PowerQuest's
93 Partition Magic product is one of the most popular). These tools allow
94 you to boot your system with a special disk and dynamically resize
95 your partitions and filesystems. Once you reboot, you have newly
96 resized partitions, hopefully getting you out of your storage crunch.
97 These partition resizing tools are great and solve the problem storage
98 management for some. But are they perfect? Not exactly.
99 </p>
100
101 <p>
102 Tools like Partition Magic are great for workstations, but aren't
103 really adequate for servers. First of all, they require you to reboot
104 your system. This is something most sysadmins desperately try to avoid
105 doing. What if you simply can't reboot your machine every time your
106 storage needs change, such as if your storage needs change dramatically
107 on a weekly basis? What happens if you need to expand a filesystem so
108 that it spans more than one hard drive, or what do you do if you need
109 to dynamically expand or shrink a volume's storage capacity while
110 allowing Apache to continue to serve Web pages? In a highly available,
111 dynamic environment, a basic partition resizer just won't work. For
112 these and other situations, Logical Volume Management is an excellent
113 (if not perfect) solution.
114 </p>
115
116 </body>
117 </section>
118 <section>
119 <title>Enter LVM</title>
120 <body>
121
122 <p>
123 Now, let's take a look at how LVM solves these problems. To create an
124 LVM logical volume, we follow a three-step process. First, we need to
125 select the physical storage resources that are going to be used for
126 LVM. Typically, these are standard partitions but can also be Linux
127 software RAID volumes that we've created. In LVM terminology, these
128 storage resources are called "physical volumes". Our first step in
129 setting up LVM involves properly initializing these partitions so
130 that they can be recognized by the LVM system. This involves setting
131 the correct partition type if we're adding a physical partition, and
132 running the pvcreate command.
133 </p>
134
135 <p>
136 Once we have one or more physical volumes initialized for use by LVM,
137 we can move on to step two -- creating a volume group. You can think
138 of a volume group as a pool of storage that consists of one or more
139 physical volumes. While LVM is running, we can add physical volumes
140 to the volume group or even remove them. However, we can't mount or
141 create filesystems on a volume group directly. Instead, we can tell
142 LVM to create one or more "logical volumes" using our volume group
143 storage pool:
144 </p>
145
146 <figure link="/images/docs/l-lvm-1.gif" caption="A volume group is
147 created out of physical volumes"/>
148
149 <p>
150 Creating an LVM logical volume is really easy, and once it's created
151 we can go ahead and put a filesystem on it, mount it, and start using
152 the volume to store our files. To create a logical volume, we use the
153 <c>lvcreate</c> command, specifying the name of our new volume, the
154 size we'd like the volume to be, and the volume group that we'd like
155 this particluar logical volume to be part of. The LVM system will
156 then allocate storage from the volume group we specify and create our
157 new volume, which is now ready for use. Once created, we can put an
158 ext2 or ReiserFS filesystem on it, mount it, and use it as we like.
159 </p>
160
161 <figure link="/images/docs/l-lvm-2.gif" caption="Creating two
162 logical volumes from our existing volume group"/>
163
164 </body>
165 </section>
166 <section>
167 <title>Extents</title>
168 <body>
169
170 <p>
171 Behind the scenes, the LVM system allocates storage in equal-sized
172 "chunks", called extents. We can specify the particular extent size
173 to use at volume group creation time. The size of an extent defaults
174 to 4Mb, which is perfect for most uses. One of the beauties of LVM is
175 that the physical storage locations of the extents used for one of our
176 logical volumes (in other words, what disk they're stored on) can be
177 dynamically changed while our logical volume is mounted and in use!
178 The LVM system ensures that our logical volumes continue to operate
179 perfectly while allowing the administrator to physically change where
180 everything is stored.
181 </p>
182
183 <p>
184 Of course, since everything is created out of equally-sized extents,
185 it's really easy to allocate some additional extents for an
186 already-existing logical volume -- in other words, dynamically "grow"
187 the volume:
188 </p>
189
190 <figure link="/images/docs/l-lvm-3.gif" caption="Adding additional
191 extents from our volume group, expanding the size of our logical
192 volume"/>
193
194 <p>
195 Once the logical volume has been expanded, you can then expand your
196 ext2 or ReiserFS filesystem to take advantage of this new space. If
197 you use a program such as <c>resize_reiserfs</c>, this filesystem
198 expansion can also happen while the volume is mounted and being used!
199 Truly amazing -- with LVM and online filesystem expansion utilties,
200 it's no longer necessary to reboot your system or even drop to
201 runlevel 1 to change your storage configuration.
202 </p>
203
204 <p>
205 The only time you need to shut down your system is when you need to
206 add new physical disks. Once new disks have been added, you then can
207 add these new physical volumes to your volume group(s) to create a
208 fresh supply of extents.
209 </p>
210
211 </body>
212 </section>
213 <section>
214
215
216
217 1.1 xml/htdocs/doc/en/articles/lvm-p2.xml
218
219 file : http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lvm-p2.xml?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=gentoo
220 plain: http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lvm-p2.xml?rev=1.1&content-type=text/plain&cvsroot=gentoo
221
222 Index: lvm-p2.xml
223 ===================================================================
224 <?xml version="1.0" encoding="UTF-8"?>
225 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
226 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/articles/lvm-p2.xml,v 1.1 2005/09/20 18:48:24 rane Exp $ -->
227
228 <guide link="/doc/en/articles/lvm-p2.xml">
229 <title>Learning Linux LVM, Part 2</title>
230
231 <author title="Author">
232 <mail link="drobbins@g.o">Daniel Robbins</mail>
233 </author>
234 <!-- xmlified by: Joshua Saddler (jackdark@×××××.com) -->
235
236 <abstract>
237 In this article, Daniel shares his experiences converting
238 cvs.gentoo.org's /home filesystem to an LVM logical volume. After
239 the transition, we get to see the benefits of LVM when
240 cvs.gentoo.org's /home partition is dynamically resized in real-time,
241 without rebooting, unmounting /home, or even dropping to runlevel 1.
242 All processes continue to work without any interruption. Daniel's
243 step-by-step details of the conversion will help anyone interested
244 in peforming a similiar transition on their own machine.
245 </abstract>
246
247 <!-- The original version of this article was first published on IBM
248 developerWorks, and is property of Westtech Information Services. This
249 document is an updated version of the original article, and contains
250 various improvements made by the Gentoo Linux Documentation team -->
251
252 <version>1.0</version>
253 <date>2005-08-29</date>
254
255 <chapter>
256 <title>The cvs.gentoo.org upgrade</title>
257 <section>
258 <title>Introduction</title>
259 <body>
260
261 <note>
262 The original version of this article was first published on IBM
263 developerWorks, and is property of Westtech Information Services. This
264 document is an updated version of the original article, and contains
265 various improvements made by the Gentoo Linux Documentation team.
266 </note>
267
268 <p>
269 In <uri link="/doc/en/articles/lvm-p1.xml">my first LVM article</uri>,
270 I explained the concepts behind LVM. Now it's time to put LVM into
271 action. In this article, I'm going to set up LVM on the official Gentoo
272 Linux cvs server, cvs.gentoo.org. Although cvs.gentoo.org has only one
273 hard drive, LVM's flexibility still provides an incredible improvement
274 over the standard static partitioning approach. I'll show you all the
275 steps of the LVM conversion process, so that if you're interested you
276 can perform a similar conversion on one of your machines.
277 </p>
278
279 <warn>
280 Because implementing LVM is a major change to the system (involving the
281 creation of new partitions and other potentially hazardous actions)
282 it's a really good idea to perform a full system backup before
283 beginning this process. If you're not going to perform a backup, I
284 hope you're using a test box with no important data on it. I should
285 mention that I didn't experience any problems while converting to LVM,
286 but it's best to be prepared in case something goes wrong.
287 </warn>
288
289 <p>
290 That said, let's continue. Before starting the conversion process, I
291 upgraded cvs.gentoo.org so that it was using the following packages. At
292 the time I performed the LVM transition, these were the latest versions
293 available (see <uri link="#resources">Resources</uri> later in this
294 article):
295 </p>
296
297 <ul>
298 <li>Linux kernel 2.4.1-ac19</li>
299 <li>LVM 0.9.1_beta5</li>
300 <li>reiserfs-utils 3.6.25</li>
301 </ul>
302
303 <p>
304 Now, for the hard drive. cvs.gentoo.org had a nice new IBM 45 GB hard
305 drive sitting in it; however, when I installed Gentoo Linux on cvs, I
306 only partitioned about 10 gigabytes of the drive, keeping the remaining
307 35 GB for future partitions. Such are the little tricks you need to
308 employ when not using LVM -- leaving part of the drive unpartitioned is
309 a primitive but effective way to allow for future expansion. However,
310 with LVM there is a better approach.
311 </p>
312
313 </body>
314 </section>
315 <section>
316 <title>The space problem</title>
317 <body>
318
319 <p>
320 In the past few weeks, I had been noticing that my root ReiserFS
321 partition had been slowly filling up, as you can see from this
322 <c>df</c> output:
323 </p>
324
325 <pre caption="Shrinking free space">
326 Filesystem 1k-blocks Used Available Use% Mounted on
327 /dev/hda3 9765200 6989312 2775888 72% /
328 tmpfs 269052 0 269052 0% /dev/shm
329 </pre>
330
331 <p>
332 Now, a 72% full root partition isn't exactly a crisis, but it isn't a
333 wonderful situation either. ReiserFS, like many other filesystems,
334 starts slowing down as it gets more and more full, and it was just a
335 matter of time before my root filesystem would fill up completely and
336 filesystem performance would take a hit.
337 </p>
338
339 <p>
340 I decided to fix this problem by using LVM to create a new logical
341 volume out of the 35 GB of currently unpartitioned space at the end
342 of my hard drive. Then, I'd create a filesystem on this volume and
343 move a good chunk of the contents of <path>/dev/hda3</path> to it.
344 </p>
345
346 <p>
347 If you're thinking of making a similar transition on one of your
348 machines, the first thing you need to do is find a suitable piece of
349 your root filesystem to move to a logical volume. For me, the choice
350 was easy -- my <path>/home</path> tree was taking up around 5.7 GB. By
351 moving <path>/home</path> to its own LVM logical volume, my root
352 filesystem would then be at about 20% capacity. Since most new data is
353 being added to <path>/home</path>, my root filesystem would likely stay
354 at around 20% capacity as well -- a very healthy situation.
355 </p>
356
357 </body>
358 </section>
359 <section>
360 <title>The beginnings of a solution</title>
361 <body>
362
363 <p>
364 To begin the conversion, I first had to partition the unused space at
365 the end of my hard drive. Using <c>cfdisk</c>, I created a 35 GB
366 partition (<path>/dev/hda5</path>) and set the partition type of the
367 partition to <c>8E</c> (the official LVM partition type). After this
368 change, I rebooted to force a reread of my partition table. After the
369 reboot, my partition table looked like this:
370 </p>
371
372 <pre caption="The new partition table">
373 # <i>sfdisk -l</i>
374 Disk /dev/hda: 89355 cylinders, 16 heads, 63 sectors/track
375 Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
376 Device Boot Start End #cyls #blocks Id System
377 /dev/hda1 * 0+ 247 248- 124960+ 83 Linux
378 /dev/hda2 248 743 496 249984 82 Linux swap
379 /dev/hda3 744 20119 19376 9765504 83 Linux
380 /dev/hda4 20120 89354 69235 34894440 5 Extended
381 /dev/hda5 20120+ 89354 69235- 34894408+ 8e Linux LVM
382 </pre>
383
384 <p>
385 Now that I had an empty 35 GB partition, I was ready to initialize it
386 for LVM. Here's the procedure -- first, I would initialize the 35
387 gigabytes as a <e>physical</e> volume; then, I would create a
388 <e>volume</e> group using this physical volume, and finally, I would
389 allocate some of the extents on the volume group, creating a
390 <e>logical volume</e> that would contain my new filesystem and house
391 all the files currently in <path>/home</path>.
392 </p>
393
394 <p>
395 To begin the process, I used the <c>pvcreate</c> command to
396 initialize <path>/dev/hda5</path> as a physical volume:
397 </p>
398
399 <pre caption="Creating the physical volume">
400 # <i>pvcreate /dev/hda5</i>
401 pvcreate -- physical volume "/dev/hda5" successfully created
402 </pre>
403
404 <p>
405 <c>pvcreate</c> set up a special "accounting" area on
406 <path>/dev/hda5</path>, called the VGDA (volume group descriptor
407 area). LVM uses this area to keep track of how the physical extents
408 are allocated, among other things.
409 </p>
410
411 <p>
412 My next step was to create a volume group and add
413 <path>/dev/hda5</path> to this group. The volume group would act as a
414 pool of extents (chunks of storage blocks). Once the volume group was
415 created, I could create as many logical volumes as I wanted. I decided
416 that my volume group would be called "main":
417 </p>
418
419 <pre caption="Creating the volume group">
420 # <i>vgcreate main /dev/hda5</i>
421 vgcreate -- INFO: using default physical extent size 4 MB
422 vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
423
424
425
426 --
427 gentoo-doc-cvs@g.o mailing list