![]() |
|
|
|
|
|
LVM: The logical way to manage space
By Mayank Sarup <Mayank@freeos.com>
There are tools available that can resize your partition, but what do you do if there is no free space left on your hard drive? One option is that you delete and re-create your partitions. Add another hard drive, create a bigger partition there and move our data there. Although possible, such methods are temporary and in all probability, you will run out of space again. The need of the hour therefore, is not a static and temporary solution, but a more dynamic one that’s also easy to administer and maintain. And LVM fulfills that need. LVM frees you from dilemmas like `Should I have a /home that is 5GB or should I make it 4GB and make a slightly larger /var partition?’ For whatever decision you take, most of the time, you either end up allocating more space than required or you find that future requirements have nullified your allocations. But with LVM, you don’t need to spend time thinking about how much space you should allocate to a partition. You can make a partition as big or as small as you like. You can always dynamically add/reduce the space allocated to the partition. Even better, you can do this while your partition is online i.e. it is still mounted.
Head over to http://www.sistina.com/lvm. Download the tarball for your LVM version. We grabbed the 0.9.1 beta 2 release. Untar the file in a suitable location and change into the LVM/0.9 directory. Compile it! If you’re working with a 2.2 kernel, get your hands on kernel 2.2.17 because that’s the kernel version for which patches are available in the `Patches’ sub-directory. Applying the patches is a simple affair. Read the `Install’ file for more information on the patches suitable for your system. Change to /usr/src/linux or to the directory containing the kernel sources and run the following commands to patch your kernel. Patch in the order given below. cat /src/LVM/0.9/PATCHES/linux-2.2.17-rawio.patch | patch –p1 Patches for beta 2.4 kernels are also available, but since it has already made its way into the kernel, you will be better off using a stable kernel release. Here, we’re using kernel 2.4.3. Do a ‘make menuconfig’ to configure your patched kernel. Go into “Multi-device support” and choose `Compile support’ for LVM into your kernel or make it into a module. We recommend making it into a Module. In that case, put the following two lines in your /etc/modules.conf alias block-major-58 lvm-mod You will also require the userspace tools for LVM administration. Go to LVM/0.9 directory and compile them. ./configure Now that you have the required LVM tools installed, add “vgscan” and “vgchange –-a y” to your startup files so that, the available volume groups are initialized and available at startup before the LVM-based filesystems are mounted. This would be /sbin/init.d/boot in SuSE, and /etc/rc.d/rc.sysinit in Red Hat. Similarly add “vgchange -a n” to the shutdown script after your filesystems are unmounted. Look for the script /sbin/init.d/halt in SuSE. Understand it! Now, before you start using LVM, you need to look at some of the terms that you will encounter. To start with, there are Physical Volumes (PVs). These are the basic building blocks and would be the partitions that you have available. You can also use RAID volumes but we’re just working with plain old partitions. So /dev/hda6, hdb1 etc. are the PV’s. These PV’s together form a Volume Group (VG). Basically, the effective disk space that is available in a VG is the sum total of the various PV’s that you add to the VG. Once you have allocated enough disk space to your VG (Don’t worry about allocating space. Remember, you can add any amount of space later), you can set about creating Logical Volumes (LVs). LVs are the final containers of your data. We’'ve actually come full circle here. We started out with distinct partitions that were collated into a single storage area and now we’re creating distinct, logical partitions from the space we added to the VG. Use it! Now that you know a few of the buzzwords of LVM, lets go on to the command line and start using LVM. Look for some unused partitions/space that can be used for LVM. You need at least one. Create a new partition or use an existing partition. Existing partitions will lose all data so make sure there’s nothing useful on those partitions. Fdisk is a good tool to create the partitions. You will also have to set the partition type to 8e (Linux LVM). #fdisk -l /dev/hda Now initialize the partition. #pvcreate /dev/hda7 # pvcreate /dev/hda8 The above command creates a volume group descriptor at the start of the partition. The allocation of the physical extents is stored here. Create a new volume group and add the two physical volumes to it. # vgcreate freeos /dev/hda7 /dev/hda8 This will create a volume group named freeos containing the physical volumes /dev/hda7 and /dev/hda8. Now you can go on to create the logical volumes within the volume group. # lvcreate -L 2G -n lv1 freeos This will create a logical volume of size 2GB named lv1 in the volume group freeos. Use the command “vgdisplay” to see the details regarding the volume groups present in your system. # vgdisplay Now you need to build a filesystem on this logical volume. Here, we’re using reiserfs. #mkreiserfs /dev/freeos/lv1 Mount the newly created filesystem. We found that we had to specify the filesystem type. #mount -t reiserfs /dev/freeos/lv1 /mnt/lv1 Now you can copy all your data here or move some partition running short of space here. If there are no problems and the working is perfect, you can add an entry to /etc/fstab so that the filesystem is mounted at boot. /dev/freeos/lv1 /mnt/lv1 reiserfs defaults 1 2 Resizing! Well, this is cited as the most important reason for using LVM— -- the fact that you can just add space to your volume group and also dynamically resize your logical volumes. Adding more space to your volume group is a simple affair. Let’s say you have /dev/hda9 of type Linux LVM and you would like to add that to the volume group freeos. The tool to use is vgextend. # vgextend freeos /dev/hda9 vgextend— -- INFO: maximum logical volume size is 255.99 Gigabyte Ok, so now you have added more space to your volume group. Let’s use some of the space to extend our lv1 logical volume. # lvextend -L+1G /dev/freeos/lv1 lvextend— -- extending logical volume “/dev/freeos/lv1” to 2 GB Lvextend takes a variety of parameters for size. You use the plus “+” to say that that partition size should be extended by 1 GB. You can, alternatively, use a “-“ here to reduce the partition size by 1 GB. You can give an absolute value too. Now check the free space on your partition. # df -h You still need to resize the filesystem to take over the new space. # resize_reiserfs -s+1024M -f /dev/freeos/lv1 Although you can do the resize while the partition is online, we recommend that you first unmount the partition and then do such operations on the filesystem. When resizing downwards, it is definitely a must that you unmount the filesystem. To reduce the filesystem size, first reduce the size of your logical volume. # resize_reiserfs -s-1024M -f /dev/freeos/lv1 ReiserFS report: Syncing..done Now reduce the size of the logical volume. # lvreduce -L-1G /dev/freeos/lv1 As you can see, barring the initial creation of the volume groups, LVM is far more extensible and easy to use than what you have been used to so far. Now you don’t need to worry about running out of disk space, thanks to LVM, and carry on working.
Other articles by Mayank Sarup
Current Rating: [ 7.65 / 10 ]
Number of Times Rated: [ 133 ]
|
|
|
© 1998-2004 FreeOS Technologies (I) Pvt. Ltd. All rights reserved.
[Privacy Policy]
![]() |