Updated: 2013-04-22 09:12 EDT

1 Due Date and Deliverables

2 Purpose of this Assignment

  1. Review partitioning and file system formatting commands from last term.
  2. Add disk space to your CentOS 5.8 VM in two ways:
    1. Add a file system
    2. Grow the root file system
  3. Practise with rsync
  4. Recover from forgotten admin password of your CentOS 5.8 VM
  5. Recover from corrupted MBR of your CentOS 5.8 VM

Remember to READ ALL THE WORDS to work effectively and not waste time.

3 Introduction and Overview

This is an overview of how you are expected to complete this assignment. Read all the words before you start working.

  1. Complete the Tasks listed below.
  2. Verify your own work before running the Checking Program.
  3. Run the Checking Program to help you find errors.
  4. Submit the output of the Checking Program to Blackboard before the due date.
  5. READ ALL THE WORDS to work effectively and not waste time.

Since we also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. We do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.

When you are finished the tasks, leave the files and directories in place as part of your deliverables. Do not delete any assignment work until after the term is over! Assignments may be re-marked at any time; you must have your term work available right until term end.

3.1 Searching the course notes

The previous term’s course notes are always available on the Internet here: CST8207 GNU/Linux Operating Systems I.

All the current and previous terms notes files are also stored on the CLS. You can learn about how to read and search these notes files using the command line on the CLS under the heading Copies of the CST8207 course notes near the bottom of the page Course Linux Server. The current CST8177 term notes are searchable there, too!

3.2 The Source Directory

All references to the “Source Directory” below are to the CLS directory ~idallen/cst8177/13w/assignment09/ and that name starts with a tilde character followed by a userid with no intervening slash.

4 Tasks

4.1 Set Up

  1. Complete your CentOS 5.8 VM Installation and Verification.
    • Make sure it passes the checks for disk sizes and package counts.
  2. Complete these critical system administration tasks required in Assignment #07:
    1. create the sudoers group
    2. create your own account
    3. install and configure the NTP package
    4. copy your start-up files
    5. copy your Assignments directory from the CLS to CentOS
  3. On the Course Linux Server, make the directory ~/Assignments/assignment09, in which some information will be stored related to this assignment, and also Create the check symbolic link needed to run the Checking Program.

  4. In your own account in your CentOS 5.8 VM, also make the directory ~/Assignments/assignment09

  5. Create a full clone of your CentOS 5.8 VM, which we’ll call your Backup VM. Leave your Backup VM for now, we will return to it in later tasks.

  6. Create a snapshot of your CentOS 5.8 VM.
    • Enter a comment explaining where and when you took this snapshot.
    • You can restore back to this snapshot if anything goes wrong.

4.2 Review of CST8207 partitioning and file systems

Review your work from CST8207 GNU/Linux Operating Systems I.

4.3 Adjust your PATH for sysadmin work

As a system administrator, you will need to run the utilities used for system administration (and other root-only commands). Starting a root shell and working in it is dangerous, especially for new sysadmin who are not used to the dangerous power of super-user privileges where small typing mistakes can wipe out entire file systems. (This is you.)

Recall that when your userid is configured as a member of the sudoers group, you can run sudo command, where command is a command that needs root privileges to run, such as sudo pwck. A safer thing to do is remain logged in as your ordinary, unprivileged system admin userid and to only use sudo when you need to execute a specific, privileged root command, e.g. sudo pwck.

Unfortunately, your non-root system administrator user’s PATH is not yet set up for system administrator work using sudo, because it doesn’t include any of the root-only PATH directories. You will need to update your PATH so that sudo will be able to find commands stored in /sbin, /usr/sbin, and /usr/local/sbin, as follows:

  1. Log in to your CentOS 5.8 VM using your own account. Edit your own .bashrc file to add the root-only command directories/sbin, /usr/sbin, and /usr/local/sbin to the right end of your PATH environment variable, after the current PATH directories but before your own personal $HOME/bin directory, which should remain last.
    • You did similar PATH modifications in Assignment #02.
    • Notice that “a=newstuff:$a” would insert newstuff: at the beginning of variable a, and “a=$a:newstuff” would append :newstuff at the end of variable a
    • See also modifying PATH at the end of Slides 3 PDF.
    • Make sure you preserve the PATH you are given by the system. You must add to the default path you are given, not replace it. Since the default path changes (it is different between CentOS and the CLS), you must not hard-code the system path into your own PATH variable. Add to the default PATH.
  2. Type source ./.bashrc to have your current shell run the commands in .bashrc and set your new PATH, or log out and log back in if that doesn’t work. Make sure you have your new PATH set.

  3. Display the contents of your PATH variable to verify your change. It should look something like this on CentOS (with abcd0001 being you own account userid):

    /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/home/abcd0001/bin

    Run a command that you know is in a root-only directory, such as ifconfig. Make sure the shell can find and run the command.

  4. Now your PATH variable is suitable for you to run individual root commands using sudo like this:

    $ sudo admin_command [ arguments ... ]

    where admin_command is any command that resides in one of the root-only command directories that are now in your PATH.

    Use sudo to run the pwck command. You will need to type in your own password, not the root password.

  5. When everything is working correctly with sudo, synchronize your VM’s .bashrc with its copy on the CLS so that the two files continue to be identical.
    • Your PATH on the CLS may be different than on CentOS since the CLS is a Debian Linux system with different packages installed. You will always see /bin and /usr/bin in your PATH.

4.4 Add a disk to your CentOS 5.8 VM

We will add a hard disk to your CentOS 5.8 VM, and partition it. The procedure for adding a hard disk to an actual physical computer is different only in the steps that take place while the machine is powered off. Any step carried out while the machine is running would be the same for physical machines as it is for virtual machines. The console of a physical machine is its actual keyboard and monitor, but in the case of a VM, the console is the VMware window of the machine.

  1. If your CentOS 5.8 VM is not already powered off, login as your system administrator user, and power off the machine. Notice that CentOS 5.8 is configured by default to allow a regular user logged in directly to the console to run the /usr/bin/poweroff (or /usr/bin/reboot) command when no other users are logged in. If you are logged in over the network (with SSH, for example), you would need to use sudo to run those commands as root.

  2. Using the Settings menu for your CentOS VM (not your Backup VM), add a 10G hard disk, accepting defaults for everything except the size. (You did similar work in CST8207 adding a VMware disk; review the notes.)

  3. After adding the new disk, power on your VM, then login as your system administrator user.

  4. Ensure the /proc/partitions file contains the disk you added.
    • Verify that there is a disk of the correct size.
      • The size of your new drive should be 10485760.
      • Divide: 10485760/1024/1024 to confirm the number of gigabytes.
    • Verify that no partitions are listed for the new disk.
    • Note the three-letter device name of the new disk.
  5. On your CentOS VM, copy /proc/partitions to assignment09/partitions_before.txt for later use.

  6. Using sudo, run the command fdisk devicename, where devicename is the absolute path of the device corresponding to the new disk. This will start the fdisk program, just as you did in CST8207 Fdisk Command. Partition the new disk as follows:
    1. First, make sure the new disk has no partitions configured. If you see partitions, you are using fdisk on the wrong disk. Make sure you use fdisk on the new disk device name!
    2. Create a 500MB primary partition as Partition 1 (notice that one of the options for specifying the last cylinder of a partition is +sizeM where size is the number of megabytes).
    3. Create an extended partition as Partition 2, consuming the rest of the disk.
    4. Create a 400 MB logical partition
    5. Create another logical partition consuming the rest of Partition 2.
    6. Save your changes.
    7. Notice whether fdisk tells you as it quits whether you need to reboot for the new partition table to take effect. Do what it says.
  7. On your CentOS VM, copy the new version of /proc/partitions (showing the new partitions you just created) to assignment09/partitions_after.txt

  8. Use the diff command to find the differences between the old and new assignment09/partitions_{before,after}.txt and redirect the results to assignment09/partitions_diff.txt

  9. Examine the differences file, and verify that your new partitions are the only differences. You should see four additional lines in the new partition file, corresponding to the four partitions you created:

    6a7,10
    >    8    17     497983 sdb1
    >    8    18          1 sdb2
    >    8    21     401593 sdb5
    >    8    22    9582741 sdb6

4.5 Migrate the /home directory to its own filesystem

We will create an ext4 filesystem on the primary partition of the new hard disk. Then, in single user mode, we will migrate the contents of the /home directory to that new filesystem. We will configure the /etc/fstab so that the new file system will be automatically mounted on /home, with the option for giving the users disk space quotas.

Most of these system admin commands below will require you to prefix the actual command name with sudo to gain root permissions (unless you are in single-user mode and therefore running everything as root). If you get “permission denied” errors, you forgot to use sudo.

  1. Take a snapshot of your CentOS VM.

  2. Using sudo, run a yum install command to install the e4fsprogs package.

  3. Run using sudo the command file -s /dev/somedevice to check the type of the device special file somedevice that corresponds to your new primary partition. Because it has nothing on it, you should see

    /dev/sdb1: data
  4. Using sudo, format an ext4 file system on the primary partition on the new disk. (Review the CST8207 Partitioning and File Systems notes.)

  5. Again (using sudo) check the type of the device that corresponds to your new primary partition. It should be different now:

    /dev/sdb1: Linux rev 1.0 ext4 filesystem data (extents) (huge files)
  6. Using sudo, also check the type of /dev/sda1, which you are not expecting to have an ext4 filesystem.

  7. Using sudo, also check the type of /dev/sda2, which you are expecting to be an LVM2 physical volume.

  8. From the console (the actual VMware window, not a remote PuTTY or an SSH login) take the system down to single user mode using shutdown now to do so.
    • Recall that we took the system into single user mode to set the clock in a previous lab.
    • Verify that you are in single-user mode by running the command that display the system’s runlevel, runlevel, which should show 1 S
    • Type whoami and confirm that you are always the root user when running in single-user mode. Be careful!
  9. Ensure your /home directory is backed up, as follows: If you took a snapshot of your VM as previously instructed, and if your Backup VM is functional (verify this), then you can consider your /home directory backed up. (On a non-VM system, you would copy /home to a safe backup disk before you tried to move it.)

  10. Record a recursive, sorted listing of all of the pathnames of your /home directory using find /home | sort, redirecting the output to a file named home_before.txt in root’s home directory. Your file should contain more than 130 lines, one for each pathname in the /home directory.

  11. Ensure no processes are using the /home directory or any files under it, with lsof +D /home
    • Because /home is not yet a mount point, you need to use the +D option to include every directory under /home.
    • The command should give you no output if no process is using any file or directory under the /home directory.
    • Make sure there is no output! We are going to move /home.

Note that if you don’t finish correctly the remaining steps in this section in one sitting before you reboot, your sysadmin account will be missing its HOME directory and you will get an error message about that when you log in. You must completely finish the remaining steps in this section correctly to regain log-in access to your sysadmin files in your HOME directory. Do not reboot your machine in this section, since the reboot will cause the /home directory to unmount and all your HOME directories, including the one for your sysadmin account, won’t work. You might want to take another snapshot here before you continue.

  1. Rename the existing /home directory to /old_home
    • Your sysadmin HOME directory is now invalid, since everything under /home has been renamed and is therefore missing.
    • Do not reboot your machine until you finish this section! See the warning above.
  2. Re-create a new empty /home directory, which will be used as a mount point for the new file system you just created, above.

  3. Mount the new file system that you just created on the new /home mount point. (Review the mount command in CST8207 Partitioning and File Systems.)

  4. Run the mount command and confirm that you can see /dev/sdb1 mounted on the /home directory. Do not proceed until this is true!
    • Verify that there is a lost+found directory under /home now. Do not accidentally delete this directory! (If you delete it, read the man page for the mklost+found(8) command and recreate it.)
  5. Use cp -a to copy the contents of the old /old_home directory to the new /home file system.
    • Make sure that you copy the contents of /old_home into /home and do not copy the name /old_home in to /home!
    • After the copy, look inside /home and confirm that you do not see the old_home directory name there.
    • Make sure you do not delete the lost+found directory.
  6. Record the list of all pathnames in /home again, in the same way, sorted, except redirect the output into a new file home_after.txt also in root’s home directory.

  7. Record the differences between the two home_{before,after}.txt files, in a file named home_diff.txt also in root’s home directory. (The files should differ by exactly one line; the new HOME directory has one additional directory in it that wasn’t in the original. We’ve already told you what its name is.)

  8. Add a record to the /etc/fstab file so the new /home file system is mounted automatically, with default options and added quota options for both users (usrquota) and groups (grpquota). (Review CST8207 Partitioning and File Systems for the format of /etc/fstab.)

  9. Use the mount command with the remount option to remount the /home filesystem according to the new options given in /etc/fstab
    • See man mount and look for the remount section under the -o flag (options).
    • If the mount command has errors, do not continue. Fix it!
  10. Use the mount command to verify that /home is now remounted with the two quota options that you set in /etc/fstab.
    • Also use su -l to temporarily become your sysadmin account and verify that your sysadmin HOME directory is valid and contains its usual files. Then exit your shell and return to the single-user shell.
    • If your sysadmin HOME directory is missing, do not continue. Fix it!
  1. Return from single-user to runlevel 3 by typing exit at the single-user shell.

  2. Log in using your account and verify that you are in runlevel 3 by running the command that displays the system’s runlevel.
    • If your sysadmin HOME directory is missing, do not continue. Fix it!
  3. Normally, you would remove the /old_home directory, and everything beneath it to free up space on the / filesystem, reaping the rewards of moving the /home directory to its own filesystem; however, leave the /old_home directory in place for marking purposes. Do not remove /old_home.

  4. Using sudo, move all of the *.txt files you created in the home directory for root into your own Assignments/assignment09 directory, and then change the owner and group of those files from root to yourself (your sysadmin user whose name is of the form abcd0001).
    • You may try, and fail, to use a shell GLOB pattern to move these files with sudo. Why? (Hint: Who is running the shell that is doing the GLOB expansion before executing sudo?)

4.6 Grow the root filesystem

We will use LVM capabilities to extend the volume group VolGroup00 using the first logical partition on the disk we added (the 400MB logical partition). Then we’ll grow the LogVol00 logical volume, and then we’ll grow the root filesystem that resides on that volume. Each step of the way, we’ll record the state before, then after, and record the difference.

  1. You must be logged in to the CentOS VM as your own account.

  2. Add the physical volume as follows:

    1. On your CentOS VM, make your Assignments/assignment09 directory your current working directory.

    2. Display the list of physical volumes on your VM with sudo pvdisplay.

    3. Run the command again, redirecting the output to pv_before.txt

    4. Make the first logical partition on the new hard disk into a LVM physical volume, with the command sudo pvcreate /dev/sdb5

    5. Display the attributes of that physical volume, with the command sudo pvdisplay /dev/sdb5

    6. Display the list of all physical volumes on your VM as before.

    7. Run the command again, redirecting the output to pv_after.txt

    8. Run a command to show the difference between pv_{before,after}.txt and redirect the output to pv_diff.txt
      • It should look right to you, with the correct device name and the expected size range.
      • wc output should be close to this:

        $ wc pv_diff.txt
        13  54 408 pv_diff.txt
  3. Add the physical volume to the VolGroup00 volume group (assuming your volume group is named VolGroup00 – it might be named VolGroup01 or similar, and you’ll find out below) as follows:

    1. Display the list of all volume groups on your VM, with sudo vgdisplay.
      • Note the name of your volume group, and use that name in place of VolGroup00 throughout this assignment.
    2. Run the command again, redirecting the output to vg_before.txt

    3. Add the new physical volume to the VolGroup00 volume group, with the command sudo vgextend VolGroup00 /dev/sdb5.
      • The command should display something like

        Volume group "VolGroup00" successfully extended
    4. Display the list of all volume groups on your VM, as before.

    5. Run the command again, redirecting the output to vg_after.txt

    6. Run a command to show the difference between vg_{before,after}.txt and redirect the output to vg_diff.txt, which should look something like this:

      $ cat vg_diff.txt
      5,6c5,6
      <   Metadata Areas        1
      <   Metadata Sequence No  3
      ---
      >   Metadata Areas        2
      >   Metadata Sequence No  4
      13,15c13,15
      <   Cur PV                1
      <   Act PV                1
      <   VG Size               1.69 GB
      ---
      >   Cur PV                2
      >   Act PV                2
      >   VG Size               2.06 GB
      17c17
      <   Total PE              54
      ---
      >   Total PE              66
      19c19
      <   Free  PE / Size       0 / 0
      ---
      >   Free  PE / Size       12 / 384.00 MB
  4. Extend the LogVol00 logical volume, as follows:

    1. Display the list of all logical volumes on your VM, using sudo lvdisplay.

    2. Run the command again, redirecting the output to lv_before.txt

    3. Grow the LogVol00 logical volume to consume all the space we just added to its volume group, with the command sudo lvextend -l+12 /dev/VolGroup00/LogVol00, where in -l+12, that’s an “minus-el” not a “minus-one”, and the number of physical extents, 12, came from the last line vg_diff.txt, or from the sudo vgdisplay command whose output shows Free PE (Physical Extents).

    4. Display the list of all logical volumes on your VM.

    5. Run the command again, redirecting the output to lv_after.txt

    6. Run a command to show the difference between assignment09/lv_{before,after}.txt and redirect the output to assignment09/lv_diff.txt. Verify that the differences look right:

      $ cat lv_diff.txt
      8,10c8,10
      <   LV Size                1.34 GB
      <   Current LE             43
      <   Segments               1
      ---
      >   LV Size                1.72 GB
      >   Current LE             55
      >   Segments               2
  5. Grow the root file system, as follows:

    1. Run the command df -h which will report file system disk space usage

    2. Run the command again and redirect the output to df_before.txt

    3. Run the command sudo resize2fs /dev/VolGroup00/LogVol00 to grow the root filesystem to consume all the space we just added to the logical volume on which it resides.

    4. Check the new size of your root filesystem. Run the command that will report file system disk space usage and redirect the output to df_after.txt

    5. Run a command to show the difference between assignment09/{df_after.txt,df_before.txt} and redirect the output to df_diff.txt. Verify that it looks right (similar to the following, but some of the exact numbers may differ slightly):

      $ cat df_diff.txt
      3c3
      <                       1.4G  833M  432M  66% /
      ---
      >                       1.7G  833M  787M  52% /

4.7 Install VMware Tools

VMware Tools is a set of kernel modules and programs that provide better integration of your VM into your Host OS environment. For example, it will allow you to choose a set of Host OS directories to make available under the /mnt/hgfs directory of your VM filesystem. Also, it will adjust your VM’s clock after your VM is powered on or resumed. Physical machines have a battery-powered real time clock that is used to set the system time and date upon booting, but in a virtual machine, the Host machine’s clock together with VMware tools provides this function. VMware Tools is a software package distributed as a compressed tarball on a virtual CD that is inserted into your virtual DVD drive when you select Install VMware Tools from the VM menu of your CentOS VM.

  1. Take a snapshot of your CentOS VM.

  2. Power on your CentOS VM if it isn’t already running.

  3. Select Install VMware Tools from the VM menu of your CentOS VM.

  4. Run dmesg to display boot-time messages, and grep for DVD to find out what device name your DVD drive was assigned to when your machine booted. This is one way to find the name of the device you need to mount. The grep command should display a line like devname: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive, where devname is a device name that you will find in the /dev directory.

  5. Mount your DVD device on a convenient mount point, as follows: The /media directory customarily contains mount points for removable devices. Create a suitable mount point (e.g. /media/dvd), and then on it, mount the device you found above. After you’ve successfully mounted the device, you can run the mount command to view the currently mounted devices, and you should see a line /dev/devname on /media/dvd type iso9660 (ro), where devname is the name of the device you found in the previous step.

  6. Look at the contents of the mounted DVD. You should see two files, one of them a compressed tar archive named VMwareTools-9.9.9-999999.tar.gz, where the digits represented by 9’s will be specific to the version of VMware Tools you have.

  7. Change your current working directory to a convenient place, like /tmp You should make sure there will be enough space there, that is, that the file system that contains /tmp has enough free space (three times the size of the compressed archive should be more than enough). Then use sudo tar with options to extract the tar archive on the DVD into the current directory, (which is /tmp).

  8. Notice that the archive extracted to a directory named vmware-tools-distrib. Run the vmware-install.pl script in that directory, with the command sudo vmware-tools-distrib/vmware-install.pl, and read each message/question that appears as the install script runs. You should accept all defaults by pressing Enter. (Recall doing this same thing in CST8207 VMware Tools.)
    • You may ignore one [FAILED] message for Mounting HGFS shares.
    • All other started VMware Tools services should say [OK].
  9. If the last line of output from the script does not say that it ejected the DVD, type a command to eject it using its device name in /dev/ Verify that it’s no longer mounted, using the mount command.

  10. All of the software has already been copied to its installation location, so you should clean up by removing all the vm* VM* items from /tmp.

  11. Under your VMware VM Settings Options tab do these things:
    1. Shared Folders: Enable and add a shared folder on your Host OS machine with your CentOS VM, and verify that you can see that shared folder under the /mnt/hgfs directory on your CentOS VM.
      • Some people have needed to shut down and restart VMware to make this work under a Windows VMware host. Sorry.
    2. VMware Tools: Turn on Synchronize guest time with host and verify that the date/time is now correct on your VM (or at least as correct as on your host computer).
  12. Verify that VMware tools properly sets your clock, as follows: (We will do this in runlevel 3 but remember that on a real world machine you’d need to be very careful about changing the date/time on a machine outside single-user mode.)
    1. Display the date
    2. With sudo set the date to approximately 5 minutes in the past
    3. Display the date to ensure you were successful
    4. Suspend your VM
    5. Resume your VM
    6. Display the date, and verify that it has been set back to your Host OS’s time

4.8 Practice with rsync

We will practice using rsync between your CentOS VM and your Backup VM. You will not use root privileges or sudo to run rsync To keep things simple, we will run the rsync command always on your CentOS VM, and that makes your CentOS the local machine (where the rsync command is run), and therefore your Backup VM will be the remote machine. We will remove a couple of directories from your Backup VM, and restore them with an rsync transfer from your CentOS VM to your Backup VM. We’ll try this until we’re successful. Once we’ve successfully restored those directories, we’ll remove them from your Backup VM again, and rsync a second time, redirecting the verbose output to a file.

  1. With both your CentOS VM and your Backup VM running, login to both machines as your system administrator user. Stay in your home directory on both machines throughout these tasks.

  2. Change your Backup VM hostname so you can more easily distinguish it from your original Cent OS VM, as follows (all of these subtasks are carried out on your Backup VM):
    1. Let’s say your hostname on your CentOS VM (and Backup VM) is abcd0001. On your Backup VM, we will change the hostname to backup-abcd0001 (no spaces).
    2. On your Backup VM, find the number of words in /etc/hosts and remember this number.
    3. Use sudo to edit /etc/hosts and change abcd0001 to backup-abcd0001, where abcd0001 is the previous hostname.
    4. Find the number of words in the new /etc/hosts. The word count should not have changed. If it changed, you have an error.
    5. Next, find the number of words in /etc/sysconfig/network and remember it.
    6. Use sudo to edit /etc/sysconfig/network and change abcd0001 to backup-abcd0001, where abcd0001 is the previous hostname.
    7. Find the number of words in the new /etc/sysconfig/network. The word count should not have changed. If it changed, you have an error.
    8. When you have made both edits successfully, reboot your Backup VM.
    9. Log back in to your Backup VM.
    10. Type hostname and make sure the host name has been changed.
  3. Take a snapshot of your Backup VM.

  4. Take a snapshot of your CentOS VM.

  5. On your Backup VM, run /sbin/ifconfig to find out its IP address.

  6. Verify that you can use ssh to login to your Backup VM from your system administrator account on your CentOS VM, as follows:
    1. Run this command on your CentOS VM: ssh10.0.0.1, where you use your Backup VM IP address instead of 10.0.0.1.
    2. You will be prompted about the authenticity of the host, which is expected because you are logging in for the first time. Answer yes
    3. Supply your password when prompted (it’s the same on both machines, because one is a clone of the other).
    4. Notice that you didn’t need to specify a user name, because the default is to log in to the remote machine with the same user name as the one you’re using to run the ssh command on the local machine.
    5. Run the command hostname to verify that you’ve just logged in to your Backup VM.
    6. Log back out with exit
  7. Use rsync to transfer a single file, your .bashrc, as follows:
    1. Recall that earlier in this assignment, you changed your PATH variable setting in your .bashrc on your CentOS VM, and that change is not present on your Backup VM.
    2. Run sum .bashrc on both machines to verify they are different.
    3. Synchronize this change to your Backup VM by rsyncing your CentOS VM .bashrc to your Backup VM home directory by running the following command on your CentOS VM:

      rsync -av .bashrc 10.0.0.1:
      where you use your Backup VM IP address instead of 10.0.0.1.
    4. Run sum .bashrc on both machines to verify they are now the same.

  8. Run a verbose “dry run” rsync update of your assignment05 directory from your CentOS VM to your Backup VM and verify that no files are transferred. (If you see files transfer, you got the pathnames wrong. The directories are identical; nothing should transfer. Adjust your pathnames and try again until nothing is going to be transferred between the identical machines.)
  1. On your Backup VM (make sure you’re on the right machine!):
    1. The next sections depend on you having successfully copied your Assignments directory from the CLS to your CentOS account.
    2. Use ls to display a long listing of your Assignments/assignment09 directory to make sure that it really is on your Backup VM and it really is empty. The Backup VM will not contain any of the work done in this lab, since that work was done only in the CentOS VM. Do not proceed if you see files under assignment09 – you’re on the wrong machine!
    3. After you’re sure it’s really your Backup VM, remove Assignments/assignment{01,09} (two directories) and everything in them from your Backup VM.
      • You may see some Permission denied errors from some of your Assignment 1 directories, and therefore those directories will not be removed. You can either ignore these errors or fix the permissions so that you can remove the directories.
    4. Be sure you’re doing this removal on your Backup VM!
  2. On your CentOS VM, use rsync with the verbose option to synchronize your Assignments directory from your CentOS VM to your Backup VM, preserving permissions, ownership, hard links, etc, as follows:
    1. Be sure when you run rsync (below) that your CentOS VM is the source (on the “left” side when you’re on your CentOS VM) and your Backup VM (the remote machine with the : when you’re on your CentOS VM) is the destination (on the “right” side).
    2. Again, you’re on your CentOS VM, rsyncing (below) from your CentOS VM (the local machine) to your Backup VM (the remote machine, with the IP address and the :).
    3. From your home directory on your CentOS VM, run any of the following commands. They are all equivalent, and you should examine them all and be sure you understand why they are all equivalent:
      • rsync -avH --dry-run Assignments 10.0.0.1:
      • rsync -avH --dry-run Assignments 10.0.0.1:.
      • rsync -avH --dry-run Assignments 10.0.0.1:./
      • rsync -avH --dry-run Assignments/ 10.0.0.1:Assignments
      • rsync -avH --dry-run Assignments/ 10.0.0.1:Assignments/
      • rsync -avH --dry-run Assignments/ 10.0.0.1:Assignments/.
      • rsync -avH --dry-run Assignments/. 10.0.0.1:Assignments
      • rsync -avH --dry-run Assignments/. 10.0.0.1:Assignments/
      • rsync -avH --dry-run Assignments/. 10.0.0.1:Assignments/.
    4. You will be prompted for your password.
    5. Because of the verbose option (-v) you used with rsync, you should see only your two Assignments/assignment{01,09} directories and contents being copied to your Backup VM. If you see more than this in the “dry run”, you have the pathnames wrong.
    6. Once you are confident that the “dry run” is doing the right minimal set of file copies (only the updates should be being copied), remove the “dry run” option and run the command for real.
    7. On your Backup VM, view the contents of Assignments/assignment{01,09} to verify they are now the same as on your CentOS VM.
      • If it didn’t work, try to find where the Assignments directory ended up, and remove it, or restore your Backup VM snapshot to start over. Carefully review the command you ran on your CentOS VM, fix it, and try the previous task again. Repeat until you succeed, asking for help if necessary.
  3. On your Backup VM, again remove Assignments/assignment{01,09}
    • Again, be sure you’re doing this removal on your Backup VM!
  4. On your CentOS VM, again do a verbose rsync of your Assignments directory to your Backup VM, except this time, redirect the verbose output to Assignments/assignment09/rsync_output.txt
    • Again, you may have permission errors from some of your Assignment 1 directories; ignore the errors.
  5. On your CentOS VM, run an ssh to your Backup VM to list all the Assignments files in your Backup VM, and redirect the output to a file remlist.txt in your assignment09 directory on your CentOS VM, as follows:

        $ hostname
        abcd0001
        $ pwd
        ~/Assignments/assignment09
        $ ssh 10.0.0.1 'find Assignments -ls' > remlist.txt

    where you replace 10.0.0.1 with the IP address of your Backup VM. Note how the find command runs on the remote Backup VM but the output file is created on the local CentOS VM.

    • Again, you may have permission errors from some of your Assignment 1 directories; ignore the errors.
  6. Shut down your Backup VM.

4.9 Boot into single user mode

If you find yourself locked out of a Linux machine, and you have access to the console, booting into single user mode will will often not require a password, and in single-user mode you can change passwords or perform various other repair tasks. (Some systems do password-protect single-user mode, in which case you would need to boot a “live” or “rescue” CD to reset your root password.)

  1. Shutdown and reboot your CentOS VM, and when you see the GRUB menu and the countdown timer, halt the GRUB time-out it by pressing the space bar or an arrow key.

  2. Use GRUB to edit your boot options so you boot into single user mode. (Refer to last term’s CST8207 Booting and GRUB.)

  3. Verify that you are in single user mode: when you issue the command runlevel, the output should be unknown

  4. Note that you are running as root and can change the password of any user in single-user mode, including the root password.

  5. Put the output of the command ps auxww into a file named ps_auxww.txt in your assignment09 directory, and change the ownership and group of this file to your ordinary sysadmin user. (Don’t leave root-owned files in ordinary user accounts!)

  6. Exit this single-user shell to boot into the default runlevel.

  7. Log in and verify you’re in the default runlevel by issuing the runlevel command.

4.10 Boot into rescue mode

If you find a Linux machine is unbootable, and you have console access, you may be able to rescue it by booting the machine from a “Live CD”. We will use the CentOS installation DVD to boot into “rescue” mode, which is a “Live CD” mode.

  1. Power down your CentOS VM gracefully.

  2. Insert the CentOS Installation ISO image file into your virtual DVD drive.

  3. Access the BIOS of your virtual machine, as follows:
    1. On VMware Workstation 7.x and later, to enter the BIOS setup for the guest operating system, click VM > Power > Power On to BIOS
    2. On VMWare Fusion, or an earlier version of VMware Workstation:
      • Shut down the virtual machine
      • Take a backup of the *.vmx file
      • Add this line to the end of the *.vmx file to give a longer pause on the VMware bios screen: bios.bootDelay = "60000"
      • Reboot your virtual machine and you should have 60 seconds to enter the VMware BIOS menul.
    3. In the VMware BIOS menu, change the “Boot” settings so that the CD/DVD drive is before the hard disk in the boot order, if it isn’t already.
    4. Save and Exit the BIOS to boot from the DVD drive.
  4. At the CentOS boot screen, you should see a large CentOS-5 banner on the screen, and a small boot: prompt in the lower left corner.
    • Type linux rescue at the prompt, and press return.
  5. Follow the instructions on the screen to finish booting into rescue mode, allowing it to search for and mount your Linux system when it asks you. (If it fails to mount, you will have to do it manually.)
    • You do not need to enable networking – choose No
  6. When you have a root prompt, cat the password file to see that this is not your actual CentOS system running.

  7. View a listing of /mnt/sysimage to see that is where your root file system is mounted.

  8. Save a copy of the Live CD’s password file, preserving timestamps, permissions, etc, to the file livecd_passwd.txt in your assignment09 directory. The sum of your livecd_passwd.txt file should be 17749 1

  9. Run the command chroot /mnt/sysimage to obtain a shell running with that directory as its root directory.

  10. Again, cat the password file to see that your current root shell is seeing your actual root filesystem (and other programs you run from this prompt will too).

  11. Note that you could fix your MBR with the command grub-install at this point.

  12. In the VMware VM Hardware CD/DVD tab, under Device Status, un-check Connect at power on and save the settings.

  13. Exit from this rescue shell, which will cause a reboot.
    • If you end up booting the CD/DVD again, disconnect it and reboot.
  14. Take the virtual DVD out of the virtual DVD drive. (Disconnect it.)

  15. Log back in and change the ownership and group (to you) of any remaining root owner or group files in your assignment09 directory.
    • System administrators often scan home directories, looking for root-owned files as an indication that someone has broken into the system. Don’t leave root-owned files in your own CentOS account.
    • NOTE: The Checking Program does create root files in your CLS assignment directories. Don’t delete these!
  16. Run the Checking Program as described in the next sections.

4.11 When you are done

When you are finished, run the Checking Program to create an overall mark. Submit the output to Blackboard in the correct location.

Since we also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. We do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.

  1. Optional: Keeping your base CentOS 5.8 VM snapshot, remove any intermediate snapshots you no longer require, to free up disk space.
    • Be careful not to remove your current work!

5 Checking, Marking, and Submitting your Work

The checking program resides on the Course Linux Server, but your work is on your CentOS Virtual Machine. There is a new Fetch program that you must download and use on your CentOS machine to copy information from your CentOS Virtual Machine to your account on the CLS so that the checking program can check it on the CLS.

Once the Fetch program has fetched these files from your Virtual Machine to the CLS, you can run the checking program on the CLS to check what is saved in the files. When you make changes on your CentOS Virtual Machine, you need to run the Fetch program again to update the saved files on the CLS.

Simply running the checking program on the CLS will not update the saved files on the CLS. You must run the Fetch program when you make changes on your CentOS Virtual Machine.

5.1 Part I - Fetch and Check

Do all the following steps on your CentOS 5.8 VM. Read through the whole list before you start typing anything.

  1. Log in to CentOS as your sysadmin non-root account (same userid as Blackboard).
  2. Create a directory in your sysadmin account named Assignments/assignment09 (exactly the same directory hierarchy as you already have on the CLS), unless you already have this directory.
  3. Change to your above assignment09 directory.
  4. As shown below, use wget to get a copy of the Fetch program from this URL into a file named do.sh: http://teaching.idallen.com/cst8177/13w/notes/data/assignment09wget.sh

    CentOS$ wget -O do.sh http://teaching.idallen.com/cst8177/13w/notes/data/assignment09wget.sh
    Saving to: `do.sh'

    Make sure you have a file named do.sh in your directory. You only need to download this once per assignment.

  5. As shown below, use sudo and sh to run the do.sh script you just downloaded to CentOS with the USER environment variable set to your own CLS account userid (as stored in the USER variable).

    CentOS$ sudo USER=$USER sh do.sh
  6. This Fetch program will connect from CentOS to the CLS using your account name. It will copy files from CentOS to your assignment09 directory on the CLS. It will then run the checking program on the CLS to check your work. You will need to answer one question about your IP address, and then wait and type in your CLS password.

It will look something like this:

CentOS$ whoami
abcd0001
CentOS$ hostname
abcd0001
CentOS$ pwd
/home/abcd0001/Assignments/assignment09
CentOS$ wget -O do.sh http://teaching.idallen.com/cst8177/13w/notes/data/assignment09wget.sh
Saving to: `do.sh'
CentOS$ sudo USER=$USER sh do.sh
---------------------------------------------------------------------------
abcd0001: FETCH version 1.  Connecting to CLS as USER='abcd0001' using ssh
---------------------------------------------------------------------------
abcd0001: Use local Algonquin IP cst8177-alg.idallen.ca [y/N]? n
abcd0001: Please wait; using ssh to connect to user 'abcd0001' on cst8177.idallen.ca ...
*** COURSE LINUX SERVER ***
abcd0001@cst8177.idallen.ca's password:         # enter your CLS password
---------------------------------------------------------------------------
idallen-ubuntu assignment09fetch_server.sh version 0 run by abcd0001.
Please wait; collecting info from abcd0001 Virtual Machine
---------------------------------------------------------------------------
VM files collected into Assignments/assignment09/abcd0001.tar.bz on CLS.
Now running check program for abcd0001 on CLS:
----------------------------------------------------------------------------
idallen-ubuntu check: Assignments/assignment09 check program version 00
*** Checking account for abcd0001 on idallen-ubuntu ***
[... checking program output appears here ...]

5.1.1 Notes on the Fetch program

  • This Fetch program updates your saved files on the CLS and then runs the checking program on the CLS. If you only run the checking program on the CLS, it won’t update the files from your CentOS VM and will check the exiting files saved under assignment09 on the CLS.
  • The checking program is running on the CLS, not on your CentOS VM. At the start, the checking program will issue messages relevant to your account on the CLS (e.g. errors in your CLS .bashrc file or world-writable files on the CLS). These errors are on the CLS, not on your CentOS machine.

5.2 Part II - Check and Submit

When you are done with your assignment, you need to run the checking program one last time on the CLS and submit the output file, as follows:

Do all this on the Course Linux Server:

  1. There is a Checking Program named assignment09check in the Source Directory on the CLS. Create a Symbolic Link to this program named check under your new assignment09 directory so that you can easily run the program to check your work and assign your work a mark. Note: You can create a symbolic link to this executable program but you do not have permission to read or copy the program file.

  2. Execute the above “check” program on the CLS using its symbolic link. (Review the CST8207 Search Path notes if you forget how to run a program by pathname from the command line.) This program will check your work, assign you a mark, and display the output on your screen. (You may want to paginate the long output so you can read all of it.)

    You may run the “check” program as many times as you wish, to correct mistakes and get the best mark. Some tasks sections require you to finish the whole section before running the checking program at the end; you may not always be able to run the checking program successfully after every single task step.

  3. When you are done with checking this assignment, and you like what you see on your screen, redirect the output of the Checking Program into the text file assignment09.txt under your assignment09 directory on the CLS. Use the exact name assignment09.txt in your assignment09 directory. You only get one chance to get the name correct. Case (upper/lower case letters) matters. Be absolutely accurate, as if your marks depended on it. Do not edit the file.

  4. Transfer the above assignment09.txt file from the CLS to your local computer and verify its contents. Do not edit this file! No empty files, please! Edited or damaged files will not be marked. You may want to refer to this term’s updated File Transfer notes.

  5. Submit the assignment09.txt file under the correct Assignment area on Blackboard (with the exact name) before the due date. Upload the file via the assignment09 “Upload Assignment” facility in Blackboard: click on the underlined assignment09 link in Blackboard. Use “Attach File” and “Submit” to upload your plain text file.

    No word-processor documents. Do not send email. Use only “Attach File”. Do not enter any text into the Submission or Comments boxes on Blackboard; I do not read them. Use only the “Attach File” section followed by the Submit button. (If you want to send me comments about your assignment, use email.)

  6. Your instructor may also mark the assignment09 directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete any assignment work from the CLS until after the term is over!

Use the exact file name given above. Upload only one single file of plain text, not HTML, not MSWord. No fonts, no word-processing. Plain text only.

Did I mention that the format is plain text (suitable for VIM/Nano/Pico/Gedit or Notepad)?

NO EMAIL, WORD PROCESSOR, PDF, RTF, or HTML DOCUMENTS ACCEPTED.

No marks are awarded for submitting under the wrong assignment number or for using the wrong file name. Use the exact name given above.

WARNING: Some inattentive students don’t read all these words. Don’t make that mistake! Be exact.

READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!

Author: 
| Todd Kelley / Richard Donnelly and
| Ian! D. Allen  -  idallen@idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

Plain Text - plain text version of this page in Pandoc Markdown format


Campaign for non-browser-specific HTML   Valid XHTML 1.0 Transitional   Valid CSS!   Creative Commons by nc sa 3.0   Hacker Ideals Emblem   Author Ian! D. Allen