rane 05/09/20 18:48:24 Added: xml/htdocs/doc/en/articles lvm-p1.xml lvm-p2.xml Log: two more articles, this time from #104169
Revision Changes Path 1.1 xml/htdocs/doc/en/articles/lvm-p1.xml 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 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 Index: lvm-p1.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/articles/lvm-p1.xml,v 1.1 2005/09/20 18:48:24 rane Exp $ --> <guide link="/doc/en/articles/lvm-p1.xml"> <title>Learning Linux LVM, Part 1</title> <author title="Author"> <mail link="[EMAIL PROTECTED]">Daniel Robbins</mail> </author> <!-- xmlified by: Joshua Saddler ([EMAIL PROTECTED]) --> <abstract> In this article, Daniel introduces you to the concepts behind Linux LVM (Logical Volume Management) and shows you how to get the latest kernel patches and tools installed on your system. LVM allows you to create logical volumes out of the physical storage resources on your machine. However, unlike physical volumes, the logical volumes can be expanded and shrunk while the system is still running, providing Linux system administrators with the storage flexibility that they've until now only dreamed of. </abstract> <!-- The original version of this article was first published on IBM developerWorks, and is property of Westtech Information Services. This document is an updated version of the original article, and contains various improvements made by the Gentoo Linux Documentation team --> <version>1.0</version> <date>2005-08-29</date> <chapter> <title>Storage management magic with Logical Volume Management</title> <section> <title>LVM intro</title> <body> <note> The original version of this article was first published on IBM developerWorks, and is property of Westtech Information Services. This document is an updated version of the original article, and contains various improvements made by the Gentoo Linux Documentation team. </note> <p> In this series, I'm going to show you how to install and use the new Logical Volume Management support built-in to the Linux 2.4 kernel. If you've never used a form of LVM before, you're in for a treat; it's a wonderful technology. Before we actually get LVM up and running, I'm going to explain exactly what it is and how it works. Then, we'll be ready to test out LVM and get the most out of it. </p> <p> If you're like me, then your experience with UNIX and Linux began on a PC platform, rather than on large, commercial UNIX servers and workstations. On the basic PC, we've always had to deal with partitioning our hard drives. PC people are generally well-acquainted with tools such as <c>fdisk</c>, which are used to create and delete primary and extended partitions on hard disks. Hard disk partitioning is an annoying but accepted part of the process of getting an operating system up and running. </p> <p> Hard drive partitioning can be annoying because to do a good job you really need to accurately estimate how much space you'll need for each partition. If you make a poor estimation, your Linux system could possibly be crippled -- to fix the problem, it's possible that you might even need to perform a full system backup, wipe your hard drives clean, and then restore all your data to a new (and presumably better) partition layout. Ick! These are exactly the kinds of situations that sysadmins try their best to avoid in the first place. </p> <p> While partitions were once static storage regions, thankfully, we now have a proliferation of PC repartitioning tools (PowerQuest's Partition Magic product is one of the most popular). These tools allow you to boot your system with a special disk and dynamically resize your partitions and filesystems. Once you reboot, you have newly resized partitions, hopefully getting you out of your storage crunch. These partition resizing tools are great and solve the problem storage management for some. But are they perfect? Not exactly. </p> <p> Tools like Partition Magic are great for workstations, but aren't really adequate for servers. First of all, they require you to reboot your system. This is something most sysadmins desperately try to avoid doing. What if you simply can't reboot your machine every time your storage needs change, such as if your storage needs change dramatically on a weekly basis? What happens if you need to expand a filesystem so that it spans more than one hard drive, or what do you do if you need to dynamically expand or shrink a volume's storage capacity while allowing Apache to continue to serve Web pages? In a highly available, dynamic environment, a basic partition resizer just won't work. For these and other situations, Logical Volume Management is an excellent (if not perfect) solution. </p> </body> </section> <section> <title>Enter LVM</title> <body> <p> Now, let's take a look at how LVM solves these problems. To create an LVM logical volume, we follow a three-step process. First, we need to select the physical storage resources that are going to be used for LVM. Typically, these are standard partitions but can also be Linux software RAID volumes that we've created. In LVM terminology, these storage resources are called "physical volumes". Our first step in setting up LVM involves properly initializing these partitions so that they can be recognized by the LVM system. This involves setting the correct partition type if we're adding a physical partition, and running the pvcreate command. </p> <p> Once we have one or more physical volumes initialized for use by LVM, we can move on to step two -- creating a volume group. You can think of a volume group as a pool of storage that consists of one or more physical volumes. While LVM is running, we can add physical volumes to the volume group or even remove them. However, we can't mount or create filesystems on a volume group directly. Instead, we can tell LVM to create one or more "logical volumes" using our volume group storage pool: </p> <figure link="/images/docs/l-lvm-1.gif" caption="A volume group is created out of physical volumes"/> <p> Creating an LVM logical volume is really easy, and once it's created we can go ahead and put a filesystem on it, mount it, and start using the volume to store our files. To create a logical volume, we use the <c>lvcreate</c> command, specifying the name of our new volume, the size we'd like the volume to be, and the volume group that we'd like this particluar logical volume to be part of. The LVM system will then allocate storage from the volume group we specify and create our new volume, which is now ready for use. Once created, we can put an ext2 or ReiserFS filesystem on it, mount it, and use it as we like. </p> <figure link="/images/docs/l-lvm-2.gif" caption="Creating two logical volumes from our existing volume group"/> </body> </section> <section> <title>Extents</title> <body> <p> Behind the scenes, the LVM system allocates storage in equal-sized "chunks", called extents. We can specify the particular extent size to use at volume group creation time. The size of an extent defaults to 4Mb, which is perfect for most uses. One of the beauties of LVM is that the physical storage locations of the extents used for one of our logical volumes (in other words, what disk they're stored on) can be dynamically changed while our logical volume is mounted and in use! The LVM system ensures that our logical volumes continue to operate perfectly while allowing the administrator to physically change where everything is stored. </p> <p> Of course, since everything is created out of equally-sized extents, it's really easy to allocate some additional extents for an already-existing logical volume -- in other words, dynamically "grow" the volume: </p> <figure link="/images/docs/l-lvm-3.gif" caption="Adding additional extents from our volume group, expanding the size of our logical volume"/> <p> Once the logical volume has been expanded, you can then expand your ext2 or ReiserFS filesystem to take advantage of this new space. If you use a program such as <c>resize_reiserfs</c>, this filesystem expansion can also happen while the volume is mounted and being used! Truly amazing -- with LVM and online filesystem expansion utilties, it's no longer necessary to reboot your system or even drop to runlevel 1 to change your storage configuration. </p> <p> The only time you need to shut down your system is when you need to add new physical disks. Once new disks have been added, you then can add these new physical volumes to your volume group(s) to create a fresh supply of extents. </p> </body> </section> <section> 1.1 xml/htdocs/doc/en/articles/lvm-p2.xml 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 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 Index: lvm-p2.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/articles/lvm-p2.xml,v 1.1 2005/09/20 18:48:24 rane Exp $ --> <guide link="/doc/en/articles/lvm-p2.xml"> <title>Learning Linux LVM, Part 2</title> <author title="Author"> <mail link="[EMAIL PROTECTED]">Daniel Robbins</mail> </author> <!-- xmlified by: Joshua Saddler ([EMAIL PROTECTED]) --> <abstract> In this article, Daniel shares his experiences converting cvs.gentoo.org's /home filesystem to an LVM logical volume. After the transition, we get to see the benefits of LVM when cvs.gentoo.org's /home partition is dynamically resized in real-time, without rebooting, unmounting /home, or even dropping to runlevel 1. All processes continue to work without any interruption. Daniel's step-by-step details of the conversion will help anyone interested in peforming a similiar transition on their own machine. </abstract> <!-- The original version of this article was first published on IBM developerWorks, and is property of Westtech Information Services. This document is an updated version of the original article, and contains various improvements made by the Gentoo Linux Documentation team --> <version>1.0</version> <date>2005-08-29</date> <chapter> <title>The cvs.gentoo.org upgrade</title> <section> <title>Introduction</title> <body> <note> The original version of this article was first published on IBM developerWorks, and is property of Westtech Information Services. This document is an updated version of the original article, and contains various improvements made by the Gentoo Linux Documentation team. </note> <p> In <uri link="/doc/en/articles/lvm-p1.xml">my first LVM article</uri>, I explained the concepts behind LVM. Now it's time to put LVM into action. In this article, I'm going to set up LVM on the official Gentoo Linux cvs server, cvs.gentoo.org. Although cvs.gentoo.org has only one hard drive, LVM's flexibility still provides an incredible improvement over the standard static partitioning approach. I'll show you all the steps of the LVM conversion process, so that if you're interested you can perform a similar conversion on one of your machines. </p> <warn> Because implementing LVM is a major change to the system (involving the creation of new partitions and other potentially hazardous actions) it's a really good idea to perform a full system backup before beginning this process. If you're not going to perform a backup, I hope you're using a test box with no important data on it. I should mention that I didn't experience any problems while converting to LVM, but it's best to be prepared in case something goes wrong. </warn> <p> That said, let's continue. Before starting the conversion process, I upgraded cvs.gentoo.org so that it was using the following packages. At the time I performed the LVM transition, these were the latest versions available (see <uri link="#resources">Resources</uri> later in this article): </p> <ul> <li>Linux kernel 2.4.1-ac19</li> <li>LVM 0.9.1_beta5</li> <li>reiserfs-utils 3.6.25</li> </ul> <p> Now, for the hard drive. cvs.gentoo.org had a nice new IBM 45 GB hard drive sitting in it; however, when I installed Gentoo Linux on cvs, I only partitioned about 10 gigabytes of the drive, keeping the remaining 35 GB for future partitions. Such are the little tricks you need to employ when not using LVM -- leaving part of the drive unpartitioned is a primitive but effective way to allow for future expansion. However, with LVM there is a better approach. </p> </body> </section> <section> <title>The space problem</title> <body> <p> In the past few weeks, I had been noticing that my root ReiserFS partition had been slowly filling up, as you can see from this <c>df</c> output: </p> <pre caption="Shrinking free space"> Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda3 9765200 6989312 2775888 72% / tmpfs 269052 0 269052 0% /dev/shm </pre> <p> Now, a 72% full root partition isn't exactly a crisis, but it isn't a wonderful situation either. ReiserFS, like many other filesystems, starts slowing down as it gets more and more full, and it was just a matter of time before my root filesystem would fill up completely and filesystem performance would take a hit. </p> <p> I decided to fix this problem by using LVM to create a new logical volume out of the 35 GB of currently unpartitioned space at the end of my hard drive. Then, I'd create a filesystem on this volume and move a good chunk of the contents of <path>/dev/hda3</path> to it. </p> <p> If you're thinking of making a similar transition on one of your machines, the first thing you need to do is find a suitable piece of your root filesystem to move to a logical volume. For me, the choice was easy -- my <path>/home</path> tree was taking up around 5.7 GB. By moving <path>/home</path> to its own LVM logical volume, my root filesystem would then be at about 20% capacity. Since most new data is being added to <path>/home</path>, my root filesystem would likely stay at around 20% capacity as well -- a very healthy situation. </p> </body> </section> <section> <title>The beginnings of a solution</title> <body> <p> To begin the conversion, I first had to partition the unused space at the end of my hard drive. Using <c>cfdisk</c>, I created a 35 GB partition (<path>/dev/hda5</path>) and set the partition type of the partition to <c>8E</c> (the official LVM partition type). After this change, I rebooted to force a reread of my partition table. After the reboot, my partition table looked like this: </p> <pre caption="The new partition table"> # <i>sfdisk -l</i> Disk /dev/hda: 89355 cylinders, 16 heads, 63 sectors/track Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/hda1 * 0+ 247 248- 124960+ 83 Linux /dev/hda2 248 743 496 249984 82 Linux swap /dev/hda3 744 20119 19376 9765504 83 Linux /dev/hda4 20120 89354 69235 34894440 5 Extended /dev/hda5 20120+ 89354 69235- 34894408+ 8e Linux LVM </pre> <p> Now that I had an empty 35 GB partition, I was ready to initialize it for LVM. Here's the procedure -- first, I would initialize the 35 gigabytes as a <e>physical</e> volume; then, I would create a <e>volume</e> group using this physical volume, and finally, I would allocate some of the extents on the volume group, creating a <e>logical volume</e> that would contain my new filesystem and house all the files currently in <path>/home</path>. </p> <p> To begin the process, I used the <c>pvcreate</c> command to initialize <path>/dev/hda5</path> as a physical volume: </p> <pre caption="Creating the physical volume"> # <i>pvcreate /dev/hda5</i> pvcreate -- physical volume "/dev/hda5" successfully created </pre> <p> <c>pvcreate</c> set up a special "accounting" area on <path>/dev/hda5</path>, called the VGDA (volume group descriptor area). LVM uses this area to keep track of how the physical extents are allocated, among other things. </p> <p> My next step was to create a volume group and add <path>/dev/hda5</path> to this group. The volume group would act as a pool of extents (chunks of storage blocks). Once the volume group was created, I could create as many logical volumes as I wanted. I decided that my volume group would be called "main": </p> <pre caption="Creating the volume group"> # <i>vgcreate main /dev/hda5</i> vgcreate -- INFO: using default physical extent size 4 MB vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte -- [email protected] mailing list
