Section 8.4. My home Directory Is Too Small


8.4. My /home Directory Is Too Small

As the data you store on computers growsand as the number of users grows on your serveryou'll eventually need more space for your /home directory partition.

Before logical volumes were available for Linux, finding space was rather annoying. It meant that you would back up the /home partition. Then you'd create a new partition, probably on one or more new physical drives. Finally, you'd restore the /home partition. Then the number of users would grow again, and you'd have to repeat the process.

With logical volumes, you can "grow" your /home partition fairly easily. Just add a few logical extents, and you have a partition as large as you need. The process is known as Logical Volume Management (LVM). Several Linux distributions, including Red Hat/Fedora, are starting to use LVM in their default installations.

To make sense of the instructions that follow, you need to understand some fundamental LVM concepts:


Physical volume (PV)

A PV is created from a primary or logical volume on a hard drive.


Physical extent (PE)

A PE is a chunk of disk space created out of one or more PVs. Normally, all your PEs have the same size.


Logical extent (LE)

An LE is a chunk of disk space. Every LE has a corresponding PE. LEs are the building blocks of a logical volume.


Logical volume (LV)

An LV is a designated collection of LEs. Once created, you can mount directories such as /home on an LV.


Volume group (VG)

The LVs on your system, taken together, are organized in a VG. LVM commands are usually applied to a VG, thereby affecting every LVM partition on your system.

In this annoyance, we'll use just a few of the commands associated with LVM. For more information, see the LVM HOWTO at http://www.tldp.org/HOWTO/LVM-HOWTO/. The latest version of LVM available as of this writing is the lvm2 package, which overcomes the original 1 TB limit for mounted volumes. The package name is the same for Debian, Red Hat/Fedora, and SUSE.

8.4.1. Backing Up /home

Creating a backup is a straightforward process, which we described in more detail in Chapter 2. To summarize, there are a number of ways to back up a specific directory such as /home.

The most straightforward backup is a copy of all files and directories to another partition. The standard backup process involves collecting all files and subdirectories from a high-level directory such as /home to a single archive file, which is then saved to media such as a network drive, CD/DVD, or tape drive.

If you've already configured /home on a separate partition, you can also use the dd_rescue tool described in "My Hard Drive Is Failing and I Need a BackupFast," earlier in this chapter.

If your current /home directory is already mounted on an LV, you can skip to the end of this annoyance, where you'll add more LEs to your current LV.

8.4.2. Configuring a Logical Volume

Configuring an LV from existing hard drives is a detailed process. It starts with appropriately configured hard drives or partitions and ends with mounting the LV on an appropriate directory such as /home. I suggest the following steps.

8.4.2.1. Preparing a partition

First, you need to decide if you want to allocate all or part of a hard drive. If you're allocating a partition as an LV, you'll need to assign the appropriate type using fdisk or parted. For example, if you're allocating the second partition on the second SCSI drive as an LV, you need to run the following commands on fdisk:

 # fdisk /dev/sdb Command (m for help): t Partition number (1-15): 2 Hex code (type L to list codes): 8e 

The t command allows you to modify the partition typein this case, the second partition on this hard drive. If you've checked the Hex codes, you'll know that 8e is associated with the Linux LVM partition type. Once you've written this configuration to the hard drive, you can proceed to the next section.

8.4.2.2. Creating a physical volume

You can create a PV from a properly prepared partition with the pvcreate command:

 pvcreate /dev/sdb2 

Alternatively, if you're allocating a complete hard drive as a PV, you don't need to create separate partitions. For example, if your second SCSI drive is new, you can create a PV from it as follows:

 pvcreate /dev/sdb 

If you have a older hard drive with data that you now want to dedicate as a PV, you'll first need to erase the partition table. This command destroys all data on that hard drive:

 dd if=/dev/zero of=/dev/sdb bs=512 count=1 

You can then proceed with the pvcreate /dev/sdb command.

Once you've configured two or more PVs, proceed to the next section.

8.4.2.3. Creating a volume group

It takes two or more PVs to create a VG. If you need more space for your LV partitions, you can add more PVs at a later date. The command is straightforward. For example, if you want to create a VG named homevg from /dev/sdb and /dev/sdc1, run the following command:

 vgcreate homevg /dev/sdb /dev/sdc1 

The default VG includes PEs in 4 MB chunks. As there is a current maximum of 64,000 PEs per LV, that limits the size of an LV to 256 GB. If that's not large enough, you can change the size of a PE with the -s option. For example, the following command configures 16 MB PE chunks:

 vgcreate -s 16M homevg /dev/sdb /dev/sdc1 

This supports a theoretical maximum LV size of 1,024 GB. You can review the defaults associated with the homevg VG with the following command:

 vgdisplay homevg 

8.4.2.4. Growing a VG

If you choose to dedicate an additional PV named /dev/sdd to the VG, you can extend homevg with the following command:

 vgextend homevg /dev/sdd 

8.4.2.5. Creating a LV

Now you can create the LVs that you need, in units of PEs. For example, if you've accepted the default PE size of 4 MB and want an LV of 4 GB, you can create an LV named homevol with the following command:

 lvcreate -l 1000 homevg -n homevol 

This configures an LV that you can use as a partition. In this case, the LV is associated with the following device file:

 /dev/homevg/homevol 

8.4.2.6. Configuring an LV as a partition

Finally! Now you can work with the LV as if it were a partition on another hard drive. As with other partitions, you need to format it as the filesystem of your choice:

 mkfs.reiserfs /dev/homevg/homevol 

Once formatted, you can mount the partition:

 mount -t reiserfs /dev/homevg/homevol /home 

Test the result. Restore your backup of the /home directory. If it works, you can document it in /etc/fstab, so your system mounts it on the LV the next time you boot Linux. One possible line in /etc/fstab might be:

 /dev/homevg/homevol   /home    reiserfs   acl,user_xattr    1 1 

8.4.2.7. Expanding a LV

Now if your users need more space than exists in your current /home partition, you can expand it. Just extend the LV. Assuming you have the PEs available, the following command increases the size of /dev/homevg/homevol to 1,000 MB:

 lvextend -L1000M /dev/homevg/homevol 



Linux Annoyances for Geeks
Linux Annoyances for Geeks: Getting the Most Flexible System in the World Just the Way You Want It
ISBN: 0596008015
EAN: 2147483647
Year: 2004
Pages: 144
Authors: Michael Jang

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net