Today we focus on disk, volume, and partition management. Since some of the steps are performed while not in graphical mode, I recommend printing this lab before starting it.
To be more precise, what we will do is first resize the filesystem -- that is, convince the filesystem that it is smaller, occupying the first 10 GB of the underlying logical volume. Then we will resize the logical volume underneath the filesystem to match. This will free lots of logical extents from which we can create additional logical volumes as desired (such as for additional swap space).
This process (the resizing in particular) will take a while. Before you get started, you may want to read through the man pages for mount, umount, mke2fs, resize2fs, mkswap, swapon, lvs, lvreduce, lvcreate, vgchange, and vgscan. If we were to resize a partition rather than a logical volume, we would use parted and fdisk. (A useful guide to parted can be found in an article about parted at http://www.linux-mag.com/2003-07/guru_01.html. Note that it requires free registration.) You might also want to read through a useful reference to LVM.
Before we begin, as root, run lvs. It will show two logical volumes that are part of one volume group. The second logical volume (1GB) is used for swap space. The first (35+GB) is the volume that we will resize.
Since we want to modify the root filesystem of our drives, we need to boot into some other filesystem. For this we need a "rescue CD", and the CentOS installation CD can serve. So boot from the network installation CD and type "linux rescue" at the boot prompt. On a normal rescue CD or installation CD, we would be able to boot right into a single user mode shell. But since this is a network CD, we need to load the kernel over the network (just like we did for installation). So again specify ftp.cse.lehigh.edu as the network host, and /pub/centos/5.1/os/i386/ as the directory via HTTP.
There are at least two methods possible from this point. Choose one.
Now that the logical volume containing the root partition is not mounted, but the OS knows about the logical volumes on the drive, we can continue. Type resize2fs -p /dev/mapper/VolGroup00-LogVol00 10G to resize the filesystem in LV00. (Actually, you'll need to run e2fsck first, as instructed when you try resize2fs.) When I did this, the e2fsck and resizing took a total of about 3-4 minutes.
Run lvm lvreduce -L 10g VolGroup00/LogVol00 to resize the LV00 logical volume.
At this point you can and should reboot to multiuser mode. If you run df, you'll see a much smaller root volume. The extra space (no longer used by any logical volume) is now visible to pvscan. We want to create additional swap space, so first we need to create a new logical volume. Type lvcreate -L2G VolGroup00. This should establish a new logical volume, which you can check with lvs.
Use mkswap to establish the new volume as a swap file (this is very fast). Now use top to see that you still only have 2GB of swap. Although the filesystem is ready, the OS hasn't yet been told to use it. Edit /etc/fstab to include the new swap partition, then use swapon -a to turn it on. Run top to see that you now have 4GB of swap.
The first step is to create some new logical volumes. Use lvcreate as we did above, but let's create three new volumes, each of 512MB in size. Our goal is to provide a 1GB RAID-5 volume for /home.
Now let's establish our software RAID device. Type "mdadm --create /dev/md0 --level=raid5 -n 3 /dev/mapper/X1 /dev/mapper/X2 /dev/mapper/X3" where you replace X1..X3 with the names of the newly created logical volumes. This tells mdadm to create a new raid 5 device at /dev/md0 with the three specific volumes as the underlying sources, and when finished, lets us access the combined device as /dev/md0. We can now place a filesystem on it, using mke2fs. Once that is in place, try mounting it to /mnt and running df. Look at /proc/mdstat to see the status of the RAID filesystem. (Notice that you can use the filesystem even when the RAID devices are not yet consistent.) The filesystem has been created, but the OS doesn't yet know to re-activate it on boot. We need to create /etc/mdadm.conf so that mdadm will know about this RAID configuration. Look at the man page for mdadm.conf and set it up with the necessary 1-4 lines.
Finally, to make this permanent, we should use mv to move the contents of the existing /home (since it has at least one user directory in it) to our new filesystem, and then unmount it from /mnt and re-mount it to /home. (It would be a good idea to make sure that no regular user is logged in while you move their home directory.) To finish, add the appropriate entry in /etc/fstab and reboot to make sure it works.
In order to sign the lab completion sheet, you will need to: