CSE 265: System and Network Administration

Lab #4

Today we continue on disk, volume and partition management, to prepare your system for our first course project. We also practice using sudo and creating new users and groups. Make certain that you have completed lab 3 and have a working rescue installation in case things go wrong here (but hopefully you won't need it).

  1. In lab #3, you learned how to resize a filesystem, resize a logical volume, create volumes, etc. We will continue with many of those tasks today. First, however, let's configure sudo to allow your regular account to have access to file system commands.

    Modify the sudo configuration file to include an entry for your account and to permit it to run the collection of storage commands (there is an alias for them already defined). Verify that it works by executing sudo /sbin/fdisk -l /dev/sda to see the partitions defined on your hard drive.

    Now expand the list of commands to include lvs, pvs, and pvresize so that we can use them as well. (We may need to add other commands later.)

  2. After completing lab 3, your root filesystem is smaller than when we started. Use df and lvs (using sudo) to see the filesystems and logical volumes known to your system. If you add the space used by the logical volumes shown by lvs and compare to the size of the /dev/sda2 partition, you will find that there is quite a bit of space unused. However, if you use pvs to see the information about your physical volumes, you'll see that /dev/sda2 (assigned to volume group vg_sandbox) is listed as almost the whole drive. This means you cannot create new partitions (as there is no space on /dev/sda). You can only create logical volumes to utilize available space within the Volume Group already defined.

    Sometimes it is useful to be able to create partitions directly, skipping LVM volumes entirely. Our first goal in this lab will be to shrink the physical volume so that you could create new partitions on your drive. Unfortunately, the pvresize command will not shrink a physical volume that has extents allocated in areas that will no longer be covered by a smaller volume. So we need to do this manually.

    As you may recall from your readings about LVM, a physical volume is comprised of physical extents (portions of a physical volume that can be allocated to a particular volume group). As we saw above with pvs, there was lots of space free on our only volume group. Since LVM could use any extent (it is not required to use only the lowest-ordered extents), we must first find out where our logical volumes have been allocated (that is, which physical extents are being used).

    We can find out what LVM is doing by telling it to create a backup LVM volume group configuration. Run /sbin/vgcfgbackup and it will create the file /etc/lvm/backup/vg_sandbox with human-readable contents.

    Examine this file. The physical_volumes entry will show you the range of extents used (pe_start and pe_count). Each logical volume has a starting extent (specified by "pv0" within stripes) and an extent_count saying how large it is. What you should see is that all of the physical extents used by your logical volumes are packed together pretty much at the beginning of the drive except for your original swap space (not the one you created). This is good, because it means that we can truncate this partition without harm.

    If we had physical extents in use in the area we wish to free (at the end) that correspond to volumes containing data, we would need to move that data to an earlier available extent. The command to do this is pvmove. So it would be an option here if we needed it.

    While we could modify the volume backup file and tell the system about the revised file with /sbin/vgcfgrestore, lvs also has a command that does exactly what we want: pvresize. So, look at its short man page, and figure out how to use 100GB less storage from /dev/sda2.

    Once you've done so, LVM is now convinced that its storage allocation has changed but the disk partitioning does not yet reflect it. Run fdisk again to see that the partitions have not changed.

    What we need is to resize the /dev/sda2 partition. While the GNU parted program could do this, it will complain that it does not recognize the filesystem on the partition (it does not understand LVS). We can still use parted to accomplish our goal. Run parted on the drive. At the parted prompt, type print to list the partitions that it sees. We are going to replace the existing sda2 partition with a smaller one. Use the rm command to delete the 2rd partition. Then use mkpart primary fat32 (not mkpartfs) to create a new one that leaves 100GB free. Note that mkpartfs would install a filesystem on the new partition (overwriting our existing filesystem!). Check the revised partition table with print, and notice that the new (smaller) partition does not have the right filesystem type. The one we removed had the lvm flag. Now use the set command to set the lvm flag. That's it! You can now quit. While parted does not require rebooting after these changes, you might want to do so to verify that everything is still functional.

  3. In this task, we explore how to manage user accounts.

    Create an account for a friend using useradd and passwd. Notice that it automatically created a home directory and a personal group in /etc/group. Look at the password you created in /etc/shadow to see whether it is md5 or not. How can you tell?

    Establish an account for me, called prof, with the specific password: $6$9lAKxQZj$1Agt39ynQJRY28OsnwM/Kh8omTqhix0CpdBg8gLIPnV7qL39gWftM6DqmM4duDfMgfCamD0Kt8EvRrbmTIV0n0 so that I can log in with a password that I know. Create a new entry in /etc/group for a new group, and add your personal account and the prof account to it. Verify that your account now is in two groups using the groups command.

In order to sign the lab completion sheet when I get back, you will need to:

  1. show me the output of fdisk and pvs to see new physical sizes
  2. show me the output of groups prof

If you have time, you might start working on homework #3.


This page can be reached from http://www.cse.lehigh.edu/~brian/course/2012/sysadmin/labs/
Last revised: 5 February 2012.