![]() | ![]() |
|
LVM HOWTOAJ LewisCopyright © 2002-2003 Sistina Software, Inc Copyright © 2004 Red Hat, Inc
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, either expressed or implied. While every effort has been taken to ensure the accuracy of the information documented herein, the author(s)/editor(s)/maintainer(s)/contributor(s) assumes NO RESPONSIBILITY for any errors, or for any damages, direct or consequential, as a result of the use of the information documented herein.
IntroductionThis is an attempt to collect everything needed to know to get LVM up and running. The entire process of getting, compiling, installing, and setting up LVM will be covered. Pointers to LVM configurations that have been tested with will also be included. This version of the HowTo is for LVM 2 with device-mapper and LVM 1.0.8. All previous versions of LVM are considered obsolete and are only kept for historical reasons. This document makes no attempt to explain or describe the workings or use of those versions. 1. Latest VersionWe will keep the latest version of this HowTo in the CVS with the other LDP Hoots. You can get it by checking out ``LDP/howto/docbook/LVM-HOWTO.xml'' from the tLDP CVS server. You should always be able to get a human readable version of this HowTo from the http://www.tldp.org/HOWTO/LVM-HOWTO.html 2. DisclaimerThis document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, either expressed or implied. While every effort has been taken to ensure the accuracy of the information documented herein, the author(s)/editor(s)/maintainer(s)/contributor(s) assumes NO RESPONSIBILITY for any errors, or for any damages, direct or consequential, as a result of the use of the information documented herein. 3. ContributorsList of everyone who has put words into this file.
Please notify the HowTo maintainer if you believe you should be listed above. Chapter 1. What is LVM?LVM is a Logical Volume Manager for the Linux operating system. There are now two version of LVM for Linux:
Chapter 2. What is Logical Volume Management?Logical volume management provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions. This gives the system administrator much more flexibility in allocating storage to applications and users. Storage volumes created under the control of the logical volume manager can be resized and moved around almost at will, although this may need some upgrading of file system tools. The logical volume manager also allows management of storage volumes in user-defined groups, allowing the system administrator to deal with sensibly named volume groups such as "development" and "sales" rather than physical disk names such as "sda" and "sdb". 2.1. Why would I want it?Logical volume management is traditionally associated with large installations containing many disks but it is equally suited to small systems with a single disk or maybe two. 2.2. Benefits of Logical Volume Management on a Small SystemOne of the difficult decisions facing a new user installing Linux for the first time is how to partition the disk drive. The need to estimate just how much space is likely to be needed for system files and user files makes the installation more complex than is necessary and some users simply opt to put all their data into one large partition in an attempt to avoid the issue. Once the user has guessed how much space is needed for /home /usr / (or has let the installation program do it) then is quite common for one of these partitions to fill up even if there is plenty of disk space in one of the other partitions. With logical volume management, the whole disk would be allocated to a single volume group and logical volumes created to hold the / /usr and /home file systems. If, for example the /home logical volume later filled up but there was still space available on /usr then it would be possible to shrink /usr by a few megabytes and reallocate that space to /home. Another alternative would be to allocate minimal amounts of space for each logical volume and leave some of the disk unallocated. Then, when the partitions start to fill up, they can be expanded as necessary. As an example: Joe buys a PC with an 8.4 Gigabyte disk on it and installs Linux using the following partitioning system:
Sometime later Joe decides that he want to install the latest office suite and desktop UI available but realizes that the root partition isn't large enough. But, having archived all his MP3s onto a new writable DVD drive there is plenty of space on /home. His options are not good:
With LVM this becomes much easier: Jane buys a similar PC but uses LVM to divide up the disk in a similar manner:
When she hits a similar problem she can reduce the size of /home by a gigabyte and add that space to the root partition. Suppose that Joe and Jane then manage to fill up the /home partition as well and decide to add a new 20 Gigabyte disk to their systems. Joe formats the whole disk as one partition (/dev/hdb1) and moves his existing /home data onto it and uses the new disk as /home. But he has 6 gigabytes unused or has to use symlinks to make that disk appear as an extension of /home, say /home/joe/old-mp3s. Jane simply adds the new disk to her existing volume group and extends her /home logical volume to include the new disk. Or, in fact, she could move the data from /home on the old disk to the new disk and then extend the existing root volume to cover all of the old disk. 2.3. Benefits of Logical Volume Management on a Large SystemThe benefits of logical volume management are more obvious on large systems with many disk drives. Managing a large disk farm is a time-consuming job, made particularly complex if the system contains many disks of different sizes. Balancing the (often conflicting) storage requirements of various users can be a nightmare. User groups can be allocated to volume groups and logical volumes and these can be grown as required. It is possible for the system administrator to "hold back" disk storage until it is required. It can then be added to the volume(user) group that has the most pressing need. When new drive are added to the system, it is no longer necessary to move users files around to make the best use of the new storage; simply add the new disk into an existing volume group or groups and extend the logical volumes as necessary. It is also easy to take old drives out of service by moving the data from them onto newer drives - this can be done online, without disrupting user service. To learn more about LVM, please take a look at Sistina's Logical Volume Manager . Chapter 3. Anatomy of LVMThis diagram gives a overview of the main elements in an LVM system:
Another way to look at is this (courtesy of Erik Bågfors on the linux-lvm mailing list):
3.1. volume group (VG)The Volume Group is the highest level abstraction used within the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit. 3.2. physical volume (PV)A physical volume is typically a hard disk, though it may well just be a device that 'looks' like a hard disk (eg. a software raid device). 3.3. logical volume (LV)The equivalent of a disk partition in a non-LVM system. The LV is visible as a standard block device; as such the LV can contain a file system (eg. /home). 3.4. physical extent (PE)Each physical volume is divided chunks of data, known as physical extents, these extents have the same size as the logical extents for the volume group. 3.5. logical extent (LE)Each logical volume is split into chunks of data, known as logical extents. The extent size is the same for all logical volumes in the volume group. 3.6. Tying it all togetherA concrete example will help: Lets suppose we have a volume group called VG1, this volume group has a physical extent size of 4MB. Into this volume group we introduce 2 hard disk partitions, /dev/hda1 and /dev/hdb1. These partitions will become physical volumes PV1 and PV2 (more meaningful names can be given at the administrators discretion). The PV's are divided up into 4MB chunks, since this is the extent size for the volume group. The disks are different sizes and we get 99 extents in PV1 and 248 extents in PV2. We now can create ourselves a logical volume, this can be any size between 1 and 347 (248 + 99) extents. When the logical volume is created a mapping is defined between logical extents and physical extents, eg. logical extent 1 could map onto physical extent 51 of PV1, data written to the first 4 MB of the logical volume in fact be written to the 51st extent of PV1. 3.7. mapping modes (linear/striped)The administrator can choose between a couple of general strategies for mapping logical extents onto physical extents:
3.8. SnapshotsA wonderful facility provided by LVM is 'snapshots'. This allows the administrator to create a new block device which is an exact copy of a logical volume, frozen at some point in time. Typically this would be used when some batch processing, a backup for instance, needs to be performed on the logical volume, but you don't want to halt a live system that is changing the data. When the snapshot device has been finished with the system administrator can just remove the device. This facility does require that the snapshot be made at a time when the data on the logical volume is in a consistent state, later sections of this document give some examples of this.
More information on snapshots can be found in Section 13.4 Taking a Backup Using Snapshots. Chapter 4. Frequently Asked Questions4.1. LVM 2 FAQ
Here's the Quick Start instructions :)
The primary cause of this is not having run the devmap_mknod.sh script after rebooting into a dm capable kernel. This script generates the control node for device mapper. 4.1.3. Does LVM 2 use a different format from LVM 1 for it's ondisk representation of Volume Groups and Logical Volumes? Yes. LVM 2 uses lvm 2 format metadata. This format is much more flexible than the LVM 1 format metadata, removing or reducing most of the limitations LVM 1 had. Yes. LVM 2 will activate and operate on VG and LVs created with LVM 1. The exception to this is snapshots created with LVM 1 - these should be removed before upgrading. Snapshots that remain after upgrading will have to be removed before their origins can be activated by LVM 2. Yes. Use vgconvert to convert your VG and all LVs contained within it to the new lvm 2 format metadata. Be warned that it's not always possible to revert back to lvm 1 format metadata. One possible cause of this is that some versions of LVM 1 (The user that reported this bug originally was using Mandrake 9.2, but it is not necessarily limited to that distribution) did not put a UUID into the PV and VG structures as they were supposed to. The most current versions of the LVM 2 tools automatically fill UUIDs in for the structures if they see they are missing, so you should grab a more current version and your problem should be solved. Chapter 5. Acquiring LVMThe first thing you need to do is get a copy of LVM.
5.1. Download the source
5.2. Download the development source via CVSNote: the state of code in the CVS repository fluctuates wildly. It will contain bugs. Maybe ones that will crash LVM or the kernel. It may not even compile. Consider it alpha-quality code. You could lose data. You have been warned. 5.3. Before You BeginTo follow the development progress of LVM, subscribe to the LVM mailing lists, linux-lvm and the appropriate commit list (see Section C.1). To build LVM from the CVS sources, you must have several GNU tools:
5.4. Initial SetupTo make life easier in the future with regards to updating the CVS tree create the file $HOME/.cvsrc and insert the following lines. This configures useful defaults for the three most commonly used CVS commands. Do this now before proceeding any further.
Also, if you are on a slow net link (like a dialup), you will want to add a line containing cvs -z5 in this file. This turns on a useful compression level for all CVS commands. 5.5. Checking Out Source Code
CVS commands work from anywhere inside the source tree, and recurse downward. So if you happen to issue an update from inside the `tools' subdirectory it will work fine, but only update the tools directory and it's subdirectories. In the following command examples it is assumed that you are at the top of the source tree. 5.6. Code UpdatesCode changes are made fairly frequently in the CVS repository. Announcements of this are automatically sent to the lvm-commit list. You can update your copy of the sources to match the master repository with the update command. It is not necessary to check out a new copy. Using update is significantly faster and simpler, as it will download only patches instead of entire files and update only those files that have changed since your last update. It will automatically merge any changes in the CVS repository with any local changes you have made as well. Just cd to the directory you'd like to update and then type the following.
If you did not specify a tag when you checked out the source, this will update your sources to the latest version on the main branch. If you specified a branch tag, it will update to the latest version on that branch. If you specified a version tag, it will not do anything. 5.7. Starting a ProjectDiscuss your ideas on the developers list before you start. Someone may be working on the same thing you have in mind or they may have some good ideas about how to go about it. 5.8. Hacking the CodeSo, have you found a bug you want to fix? Want to implement a feature from the TODO list? Got a new feature to implement? Hacking the code couldn't be easier. Just edit your copy of the sources. No need to copy files to .orig or anything. CVS has copies of the originals. When you have your code in a working state and have tested as best you can with the hardware you have, generate a patch against the current sources in the CVS repository.
Mail the patch to the linux-lvm or dm-devel list (Section C.1) with a description of what changes or additions you implemented. 5.9. ConflictsIf someone else has been working on the same files as you have, you may find that there are conflicting modifications. You'll discover this when you try to update your sources.
Don't panic! Your working file, as it existed before the update, is saved under the filename .#pvcreate.c.1.5. You can always recover it should things go horribly wrong. The file named `pvcreate.c' now contains both the old (i.e. your) version and new version of lines that conflicted. You simply edit the file and resolve each conflict by deleting the unwanted version of the lines involved.
Don't forget to delete the lines with all the ``<'', ``='', and ``>'' symbols. Chapter 6. Building the kernel modules6.2. Build the LVM 1 kernel moduleTo use LVM 1 you will have to build the LVM 1 kernel module (recommended), or if you prefer rebuild the kernel with the LVM 1 code statically linked into it. Your Linux system is probably based on one of the popular distributions (eg., Red Hat, SuSE, Debian) in which case it is possible that you already have the LVM 1 module. Check the version of the tools you have on your system. You can do this by running any of the LVM command line tools with the '-h' flag. Use pvscan -h if you don't know any of the commands. If the version number listed at the top of the help listing is LVM 1.0.8, use your current setup and avoid the rest of this section. 6.2.1. Building a patch for your kernelIn order to patch the linux kernel to support LVM 1.0.8, you must do the following:
6.2.2. Building the LVM module for Linux 2.2.17+The 2.2 series kernel needs to be patched before you can start building, look elsewhere for instructions on how to patch your kernel. Patches:
Once the patches have been correctly applied, you need to make sure that the module is actually built, LVM 1 lives under the block devices section of the kernel config, you should probably request that the LVM /proc information is compiled as well. Build the kernel modules as usual. 6.2.3. Building the LVM modules for Linux 2.4The 2.4 kernel comes with LVM 1 already included although you should check at the Sistina web site for updates, (eg. v2.4.9 kernels and earlier must have the latest LVM 1 patch applied ). When configuring your kernel look for LVM 1 under Multi-device support (RAID and LVM). LVM 1 can be compiled into the kernel or as a module. Build your kernel and modules and install then in the usual way. If you chose to build LVM as a module it will be called lvm-mod.o If you want to use snapshots with ReiserFS, make sure you apply the linux-2.4.x-VFS-lock patch (there are copies of this in the LVM/1.0.8/PATCHES directory.) 6.2.4. Checking the proc file systemIf your kernel was compiled with the /proc file system (most are) then you can verify that LVM is present by looking for a /proc/lvm directory. If this doesn't exist then you may have to load the module with the command
If /proc/lvm still does not exist then check your kernel configuration carefully. When LVM is active you will see entries in /proc/lvm for all your physical volumes, volume groups and logical volumes. In addition there is a "file" called /proc/lvm/global which gives a summary of the LVM status and also shows just which version of the LVM kernel you are using. Chapter 7. LVM 1 Boot time scriptsBoot-time scripts are not provided as part of the LVM distribution, however these are quite simple to do for yourself. The startup of LVM requires just the following two commands:
And the shutdown only one:
Follow the instructions below depending on the distribution of Linux you are running. 7.1. CalderaIt is necessary to edit the file /etc/rc.d/rc.boot. Look for the line that says "Mounting local filesystems" and insert the vgscan and vgchange commands just before it. You may also want to edit the the file /etc/rc.d/init.d/halt to deactivate the volume groups at shutdown. Insert the
7.2. DebianIf you download the Debian lvm tool package, an initscript should be installed for you. If you are installing LVM from source, you will still need to build your own initscript: Create a startup script in /etc/init.d/lvm containing the following:
Then execute the commands
7.4. RedhatFor Redhat 7.0 and up, you should not need to modify any initscripts to enable LVM at boot time if LVM is built into the kernel. If LVM is built as a module, it may be necessary to modify /etc/rc.d/rc.sysinit to load the LVM module by adding "modprobe lvm-mod" before the section that reads:
For versions of Redhat older than 7.0, it is necessary to edit the file /etc/rc.d/rc.sysinit. Look for the line that says "Mount all other filesystems" and insert the vgscan and vgchange commands just before it. You should be sure that your root file system is mounted read/write before you run the LVM commands. You may also want to edit the the file /etc/rc.d/init.d/halt to deactivate the volume groups at shutdown. Insert the
7.5. SlackwareSlackware 8.1 requires no updating of boot time scripts in order to make LVM work. For versions previous to Slackware 8.1, you should apply the following patch to /etc/rc.d/rc.S
Chapter 9. Building LVM from the Source9.1. Make LVM library and toolsChange into the LVM directory and do a ./configure followed by make. This will make all of the libraries and programs. If the need arises you can change some options with the configure script. Do a ./configure --help to determine which options are supported. Most of the time this will not be necessary. There should be no errors from the build process. If there are, see Reporting Errors and Bugs on how to report this. You are welcome to fix them and send us the patches too. Patches are generally sent to the linux-lvm list. Chapter 10. Transitioning from previous versions of LVM to LVM 1.0.8Transitioning from previous versions of LVM to LVM 1.0.8 should be fairly painless. We have come up with a method to read in PV version 1 metadata (LVM 0.9.1 Beta7 and earlier) as well as PV version 2 metadata (LVM 0.9.1 Beta8 and LVM 1.0). Warning: New PVs initialized with LVM 1.0.8 are created with the PV version 1 on-disk structure. This means that LVM 0.9.1 Beta8 and LVM 1.0 cannot read or use PVs created with 1.0.8. 10.1. Upgrading to LVM 1.0.8 with a non-LVM root partitionThere are just a few simple steps to transition this setup, but it is still recommended that you backup your data before you try it. You have been warned.
10.2. Upgrading to LVM 1.0.8 with an LVM root partition and initrdThis is relatively straightforward if you follow the steps carefully. It is recommended you have a good backup and a suitable rescue disk handy just in case. The "normal" way of running an LVM root file system is to have a single non-LVM partition called /boot which contains the kernel and initial RAM disk needed to start the system. The system I upgraded was as follows:
Chapter 11. Common TasksThe following sections outline some common administrative tasks for an LVM system. This is no substitute for reading the man pages. 11.1. Initializing disks or disk partitionsBefore you can use a disk or disk partition as a physical volume you will have to initialize it: For entire disks:
11.2. Creating a volume groupUse the 'vgcreate' program:
You can also specify the extent size with this command if the default of 32MB is not suitable for you with the '-s' switch. In addition you can put some limits on the number of physical or logical volumes the volume can have. 11.3. Activating a volume groupAfter rebooting the system or running vgchange -an, you will not be able to access your VGs and LVs. To reactivate the volume group, run:
11.4. Removing a volume groupMake sure that no logical volumes are present in the volume group, see later section for how to do this. Deactivate the volume group:
Now you actually remove the volume group:
11.5. Adding physical volumes to a volume groupUse 'vgextend' to add an initialized physical volume to an existing volume group.
11.6. Removing physical volumes from a volume groupMake sure that the physical volume isn't used by any logical volumes by using then 'pvdisplay' command:
If the physical volume is still used you will have to migrate the data to another physical volume using pvmove. Then use 'vgreduce' to remove the physical volume:
11.7. Creating a logical volumeDecide which physical volumes you want the logical volume to be allocated on, use 'vgdisplay' and 'pvdisplay' to help you decide. To create a 1500MB linear LV named 'testlv' and its block device special '/dev/testvg/testlv':
To create a 100 LE large logical volume with 2 stripes and stripe size 4 KB.
If you want to create an LV that uses the entire VG, use vgdisplay to find the "Total PE" size, then use that when running lvcreate.
11.8. Removing a logical volumeA logical volume must be closed before it can be removed:
11.9. Extending a logical volumeTo extend a logical volume you simply tell the lvextend command how much you want to increase the size. You can specify how much to grow the volume, or how large you want it to grow to:
After you have extended the logical volume it is necessary to increase the file system size to match. how you do this depends on the file system you are using. By default, most file system resizing tools will increase the size of the file system to be the size of the underlying logical volume so you don't need to worry about specifying the same size for each of the two commands.
11.10. Reducing a logical volumeLogical volumes can be reduced in size as well as increased. However, it is very important to remember to reduce the size of the file system or whatever is residing in the volume before shrinking the volume itself, otherwise you risk losing data.
11.11. Migrating data off of a physical volumeTo take a disk out of service it must first have all of its active physical extents moved to one or more of the remaining disks in the volume group. There must be enough free physical extents in the remaining PVs to hold the extents to be copied from the old disk. For further detail see Section 13.5. Chapter 12. Disk partitioning12.1. Multiple partitions on the same diskLVM allows you to create PVs (physical volumes) out of almost any block device so, for example, the following are all valid commands and will work quite happily in an LVM environment:
In a "normal" production system it is recommended that only one PV exists on a single real disk, for the following reasons:
If you do have a disk with more than one partition and both of those partitions are in the same volume group, take care to specify which partitions are to be included in a logical volume when creating striped volumes. The recommended method of partitioning a disk is to create a single partition that covers the whole disk. This avoids any nasty accidents with whole disk drive device nodes and prevents the kernel warning about unknown partition types at boot-up. 12.2. Sun disk labelsYou need to be especially careful on SPARC systems where the disks have Sun disk labels on them. The normal layout for a Sun disk label is for the first partition to start at block zero of the disk, thus the first partition also covers the area containing the disk label itself. This works fine for ext2 filesystems (and is essential for booting using SILO) but such partitions should not be used for LVM. This is because LVM starts writing at the very start of the device and will overwrite the disk label. If you want to use a disk with a Sun disk label with LVM, make sure that the partition you are going to use starts at cylinder 1 or higher. Chapter 13. RecipesThis section details several different "recipes" for setting up lvm. The hope is that the reader will adapt these recipes to their own system and needs. 13.1. Setting up LVM on three SCSI disksFor this recipe, the setup has three SCSI disks that will be put into a logical volume using LVM. The disks are at /dev/sda, /dev/sdb, and /dev/sdc. 13.1.1. Preparing the disksBefore you can use a disk in a volume group you will have to prepare it:
Run pvcreate on the disks
13.1.2. Setup a Volume Group
13.1.3. Creating the Logical VolumeIf the volume group looks correct, it is time to create a logical volume on top of the volume group. You can make the logical volume any size you like. (It is similar to a partition on a non LVM setup.) For this example we will create just a single logical volume of size 1GB on the volume group. We will not use striping because it is not currently possible to add a disk to a stripe set after the logical volume is created.
13.1.4. Create the File SystemCreate an ext2 file system on the logical volume
13.1.5. Test the File SystemMount the logical volume and check to make sure everything looks correct
If everything worked properly, you should now have a logical volume with and ext2 file system mounted at /mnt. 13.2. Setting up LVM on three SCSI disks with stripingFor this recipe, the setup has three SCSI disks that will be put into a logical volume using LVM. The disks are at /dev/sda, /dev/sdb, and /dev/sdc.
13.2.1. Preparing the disk partitionsBefore you can use a disk in a volume group you will have to prepare it:
Run pvcreate on the disks:
13.2.2. Setup a Volume Group
13.2.3. Creating the Logical VolumeIf the volume group looks correct, it is time to create a logical volume on top of the volume group. You can make the logical volume any size you like (up to the size of the VG you are creating it on; it is similar to a partition on a non LVM setup). For this example we will create just a single logical volume of size 1GB on the volume group. The logical volume will be a striped set using for the 4k stripe size. This should increase the performance of the logical volume.
13.2.4. Create the File SystemCreate an ext2 file system on the logical volume
13.2.5. Test the File SystemMount the file system on the logical volume
13.3. Add a new disk to a multi-disk SCSI system13.3.1. Current situationA data centre machine has 6 disks attached as follows:
13.3.2. Prepare the disk partitionsThe new disk is to be shared equally between ops and dev so it is partitioned into two physical volumes /dev/sdg1 and /dev/sdg2 :
Next physical volumes are created on this partition:
13.3.3. Add the new disks to the volume groupsThe volumes are then added to the dev and ops volume groups:
13.3.4. Extend the file systemsThe next thing to do is to extend the file systems so that the users can make use of the extra space. There are tools to allow online-resizing of ext2 file systems but here we take the safe route and unmount the two file systems before resizing them:
We then use the e2fsadm command to resize the logical volume and the ext2 file system on one operation. We are using ext2resize instead of resize2fs (which is the default command for e2fsadm) so we define the environment variable E2FSADM_RESIZE_CMD to tell e2fsadm to use that command.
13.3.5. Remount the extended volumesWe can now remount the file systems and see that the is plenty of space.
13.4. Taking a Backup Using SnapshotsFollowing on from the previous example we now want to use the extra space in the "ops" volume group to make a database backup every evening. To ensure that the data that goes onto the tape is consistent we use an LVM snapshot logical volume. This type of volume is a read-only copy of another volume that contains all the data that was in the volume at the time the snapshot was created. This means we can back up that volume without having to worry about data being changed while the backup is going on, and we don't have to take the database volume offline while the backup is taking place. 13.4.1. Create the snapshot volumeThere is a little over 500 Megabytes of free space in the "ops" volume group, so we will use all of it to allocate space for the snapshot logical volume. A snapshot volume can be as large or a small as you like but it must be large enough to hold all the changes that are likely to happen to the original volume during the lifetime of the snapshot. So here, allowing 500 megabytes of changes to the database volume which should be plenty.
13.4.2. Mount the snapshot volumeWe can now create a mount-point and mount the volume
If you are using XFS as the filesystem you will need to add the nouuid option to the mount command:
13.4.3. Do the backupI assume you will have a more sophisticated backup strategy than this!
13.4.4. Remove the snapshotWhen the backup has finished you can now unmount the volume and remove it from the system. You should remove snapshot volume when you have finished with them because they take a copy of all data written to the original volume and this can hurt performance.
13.5. Removing an Old DiskSay you have an old IDE drive on /dev/hdb. You want to remove that old disk but a lot of files are on it.
13.5.1. Distributing Old Extents to Existing Disks in Volume GroupIf you have enough free extents on the other disks in the volume group, you have it easy. Simply run
13.5.1.1. Remove the unused diskWe can now remove the old IDE disk from the volume group.
13.5.2. Distributing Old Extents to a New Replacement DiskIf you do not have enough free physical extents to distribute the old physical extents to, you will have to add a disk to the volume group and move the extents to it. 13.5.2.1. Prepare the diskFirst, you need to pvcreate the new disk to make it available to LVM. In this recipe we show that you don't need to partition a disk to be able to use it.
13.5.2.2. Add it to the volume groupAs developers use a lot of disk space this is a good volume group to add it into.
13.5.2.3. Move the dataNext we move the data from the old disk onto the new one. Note that it is not necessary to unmount the file system before doing this. Although it is *highly* recommended that you do a full backup before attempting this operation in case of a power outage or some other problem that may interrupt it. The pvmove command can take a considerable amount of time to complete and it also exacts a performance hit on the two volumes so, although it isn't necessary, it is advisable to do this when the volumes are not too busy.
13.5.2.4. Remove the unused diskWe can now remove the old IDE disk from the volume group.
13.6. Moving a volume group to another systemIt is quite easy to move a whole volume group to another system if, for example, a user department acquires a new server. To do this we use the vgexport and vgimport commands. 13.6.1. Unmount the file systemFirst, make sure that no users are accessing files on the active volume, then unmount it
13.6.2. Mark the volume group inactiveMarking the volume group inactive removes it from the kernel and prevents any further activity on it.
13.6.3. Export the volume groupIt is now necessary to export the volume group. This prevents it from being accessed on the ``old'' host system and prepares it to be removed.
13.6.4. Import the volume groupWhen plugged into the new system it becomes /dev/sdb so an initial pvscan shows:
13.7. Splitting a volume groupThere is a new group of users "design" to add to the system. One way of dealing with this is to create a new volume group to hold their data. There are no new disks but there is plenty of free space on the existing disks that can be reallocated. 13.7.1. Determine free space
13.7.2. Move data off the disks to be usedSome space is still used on the chosen volumes so it is necessary to move that used space off onto some others. Move all the used physical extents from /dev/sdg1 to /dev/sde and from /dev/sdg2 to /dev/sde
13.7.3. Create the new volume groupNow, split /dev/sdg2 from dev and add it into a new group called "design". it is possible to do this using vgreduce and vgcreate but the vgsplit command combines the two.
13.7.4. Remove remaining volumeNext, remove /dev/sdg1 from ops and add it into design.
13.7.5. Create new logical volumeNow create a logical volume. Rather than allocate all of the available space, leave some spare in case it is needed elsewhere.
13.7.6. Make a file system on the volume
13.8. Converting a root filesystem to LVM 1
In this example the whole system was installed in a single root partition with the exception of /boot. The system had a 2 gig disk partitioned as:
The / partition covered all of the disk not used by /boot and swap. An important prerequisite of this procedure is that the root partition is less that half full (so that a copy of it can be created in a logical volume). If this is not the case then a second disk drive should be used. The procedure in that case is similar but there is no need to shrink the existing root partition and /dev/hda4 should be replaced with (eg) /dev/hdb1 in the examples. To do this it is easiest to use GNU parted. This software allows you to grow and shrink partitions that contain filesystems. It is possible to use resize2fs and fdisk to do this but GNU parted makes it much less prone to error. It may be included in your distribution, if not you can download it from ftp://ftp.gnu.org/pub/gnu/parted. Once you have parted on your system AND YOU HAVE BACKED THE SYSTEM UP: 13.8.1. Boot single userBoot into single user mode (type linux S at the LILO prompt) This is important. Booting single-user ensures that the root filesystem is mounted read-only and no programs are accessing the disk. 13.8.2. Run PartedRun parted to shrink the root partition Do this so there is room on the disk for a complete copy of it in a logical volume. In this example a 1.8 gig partition is shrunk to 1 gigabyte This displays the sizes and names of the partitions on the disk
Now resize the partition:
Create a new partition
Quit parted
13.8.4. Verify kernel config optionsMake sure that the kernel you are currently running works with LVM 1 and has CONFIG_BLK_DEV_RAM and CONFIG_BLK_DEV_INITRD set in the config file. 13.8.5. Adjust partition typeChange the partition type on the newly created partition from Linux to LVM (8e). Parted doesn't understand LVM 1 partitions so this has to be done using fdisk.
13.8.6. Set up LVM 1 for the new scheme
13.8.7. Create the FilesystemMake a filesystem in the logical volume and copy the root files onto it.
13.8.8. Update /etc/fstabEdit /mnt/etc/fstab on the new root so that / is mounted on /dev/vg/root. For example:
13.8.9. Create an LVM 1 initial RAM disk
Make sure you note the name that lvmcreate_initrd calls the initrd image. It should be in /boot. 13.8.10. Update /etc/lilo.confAdd an entry in /etc/lilo.conf for LVM 1. This should look similar to the following:
You should copy this new lilo.conf onto /etc in the new root fs as well.
13.8.12. Reboot to lvmReboot - at the LILO prompt type "lvm" The system should reboot into Linux using the newly created Logical Volume. If that worked then you should make lvm the default LILO boot destination by adding the line
If it did not work then reboot normally and try to diagnose the problem. It could be a typing error in lilo.conf or LVM 1 not being available in the initial RAM disk or its kernel. Examine the message produced at boot time carefully. 13.8.13. Add remainder of diskAdd the rest of the disk into LVM 1. When you are happy with this setup you can then add the old root partition to LVM 1 and spread out over the disk. First set the partition type to 8e(LVM)
Convert it into a PV and add it to the volume group:
Appendix A. Dangerous Operations
A.1. Restoring the VG UUIDs using uuid_fixerIf you've upgraded LVM from previous versions to early 0.9 and 0.9.1 versions of LVM and vgscan says vgscan -- no volume groups found, this is one way to fix it.
A.2. Sharing LVM volumes
If you have a fibre-channel or shared-SCSI environment where more than one machine has physical access to a set of disks then you can use LVM to divide these disks up into logical volumes. If you want to share data you should really be looking at GFS or other cluster filesystems. The key thing to remember when sharing volumes is that all the LVM administration must be done on one node only and that all other nodes must have LVM shut down before changing anything on the admin node. Then, when the changes have been made, it is necessary to run vgscan on the other nodes before reloading the volume groups. Also, unless you are running a cluster-aware filesystem (such as GFS) or application on the volume, only one node can mount each filesystem. It is up to you, as system administrator to enforce this, LVM will not stop you corrupting your data. The startup sequence of each node is the same as for a single-node setup with
If you need to do any changes to the LVM metadata (regardless of whether it affects volumes mounted on other nodes) you must go through the following sequence. In the steps below ``admin node'' is any arbitrarily chosen node in the cluster.
I'll say it again: Be very careful doing this Appendix B. Reporting Errors and BugsJust telling us that LVM did not work does not provide us with enough information to help you. We need to know about your setup and the various components of your configuration. The first thing you should do is check the linux-lvm mailing list archives to see if someone else has already reported the same bug. If you do not find a bug report for a problem similar to yours you should collect as much of the following information as possible. The list is grouped into three categories of errors.
This can be a lot of information. If you end up with more than a couple of files, tar and gzip them into a single archive. Submit a link to where this file can be found to the appropriate mailing list (see Section C.1) along with a short description of the error. If you do not have a public web or ftp site that you can post the information to, you can try to submit the file to the list. Appendix C. Contact and LinksC.1. Mail listsBefore you post to any of our lists please read the all of this document and check the archives to see if your question has already been answered. Please post in text only to our lists, fancy formated messages are near impossible to read if someone else is not running a mail client that understands it. Standard mailing list etiquette applies. Incomplete questions or configuration data make it very hard for us to answer your questions. LVM Discussion Mailing Lists
LVM-Related Commit Lists
Discontinued Lists
Appendix D. GNU Free Documentation LicenseVersion 1.2, November 2002
D.1. PREAMBLEThe purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. D.2. APPLICABILITY AND DEFINITIONSThis License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. D.3. VERBATIM COPYINGYou may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. D.4. COPYING IN QUANTITYIf you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. D.5. MODIFICATIONSYou may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:
If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. D.6. COMBINING DOCUMENTSYou may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements". D.7. COLLECTIONS OF DOCUMENTSYou may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. D.8. AGGREGATION WITH INDEPENDENT WORKSA compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. D.9. TRANSLATIONTranslation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. D.10. TERMINATIONYou may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. D.11. FUTURE REVISIONS OF THIS LICENSEThe Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. D.12. ADDENDUM: How to use this License for your documentsTo use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this:
If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. |