Updated: 2015-04-16 12:10 EDT

1 Due Date and DeliverablesIndexup to index

Do not print this assignment on paper!

WARNING: Some inattentive students upload Assignment #13 into the Assignment #12 upload area. Don’t make that mistake! Be exact.

2 Purpose of this AssignmentIndexup to index

Do not print this assignment on paper! On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.

This assignment is based on your weekly Class Notes.

  1. Review the Partitions and File Systems commands in the Class Notes.
  2. Practice creating and deleting partitions. Create file systems. Mount and unmount file systems.
  3. Review Booting and GRUB in the Class Notes.
  4. Boot into single user mode. (This is how you change a forgotten root password.)

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

3 Introduction and OverviewIndexup to index

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

For full marks, follow these directions exactly.

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

3.1 Save your workIndexup to index

You will create some minimal file system structure in your HOME directory on the CLS.

Most work will involve changes in your own Linux Virtual Machine running Centos 6.6. You can use the Checking Program to check your work as you go. You can check your work with the Checking Program as often as you like before you submit your final mark.

When you are finished, leave the files and directories in place on both the CLS and your own CentOS Virtual Machine 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 on the CLS; you must have your term work available on the CLS right until term end.

3.2 Searching the course notes on the CLSIndexup to index

All course notes are available on the Internet and also on the CLS. You can learn about how to read and search these CLS 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.

3.3 Commands, topics, and features coveredIndexup to index

Review course notes on Partitions and File Systems and Booting and GRUB.

See the course notes or use the on-line help (man command) for the commands listed below for more information:

3.4 Correct user, command lines, and command outputIndexup to index

3.5 Backup and Recovery on CentOSIndexup to index

  1. Take a running snapshot of your virtual machine before you begin each section of this lab so that you can recover back to the snapshot if needed.
    • Don’t shut your machine down; use a running snapshot so that you don’t lose the current state of the system.
    • You can delete the unused snapshots if everything works well.
    • CentOS snapshots are very small and fast compared to your Windows snapshots; you can save lots of them.
  2. Are you keeping an external backup copy of all your coursework (including your virtual machines) somewhere? You should be!

3.6 Use a remote login, not the VMware consoleIndexup to index

I recommend that once you have booted your CentOS VM, you connect to it and work using a remote login session (e.g. ssh or PuTTY) where copy-and-paste works, you can set the font and screen size and colours, and where you can have multiple simultaneous connections into the VM.

Do not use the little VMware system console.

The VMware console is not friendly. It is limited size, and information can scroll off the top where you won’t see it. If you find some output scrolls off the top of the console, you can use SHIFT plus the PgUP key to scroll the console window up a limited amount.

Don’t use the console; use an SSH terminal session instead.

Note that SSH sessions (and whatever you are doing inside them) do not survive across a VMware suspend. Make sure you save your editor files and exit your SSH session before you pause or suspend your virtual machine. (Editor sessions that run inside the VMware console do survive across suspend and resume, since they don’t depend on a network connection.)

Interested users may look into the various Linux virtual terminal programs such as tmux and screen that do allow you to suspend and resume your sessions even from a remote login.

3.7 CentOS: No root files in non-root accountsIndexup to index

Files saved anywhere under your sysadmin HOME directory in CentOS should be owned by you and in one of your groups, not owned by root or in the root group. (The presence of root files in non-root accounts is often a sign that your machine has been cracked!)

Do not leave root-owner or root-group files in your account. You should change the owner and group to you of anything you create as root in your account. To find files not owned by you or not in your own group in your account:

[abcd0001@abcd0001 ~]$ cd ; pwd ; echo "$USER" ; find . ! -user "$USER" -ls
/home/abcd0001                           # your HOME directory not abcd0001
abcd0001                                 # your own userid not abcd0001
[... any non-abcd0001 owner files are listed here ...]

[abcd0001@abcd0001 ~]$ cd ; pwd ; echo "$USER" ; find . ! -group "$USER" -ls
/home/abcd0001                           # your HOME directory not abcd0001
abcd0001                                 # your own userid not abcd0001
[... any non-abcd0001 group files are listed here ...]

Note that the above commands were run when logged in as your sysadmin account, not when logged in as root – make sure the $USER variable contains your own userid not the root userid. You want to find files not owned by or in the group of your own userid.

If you find any files that are not owned by or in the group of your own sysadmin userid, you should change the owner and group of these files to be your own userid and group. (The command that does this has a recursive option that lets you change everything under a directory.)

Hints: You need to know which account has permissions to change the ownership and group of a file. You need to know how to make the change. See the examples in Users and Groups.

Advanced users can modify the above find to send pathnames into sudo running xargs with chown. See Find and Xargs.

3.8 The Answer File answer.txtIndexup to index

answer.txt

Where you are required to record or save a command line or its output into The Answer File, do the command and then copy and record the command line or its output as a separate line into an answer.txt file in your CentOS Base Directory. You will be told how many lines to save in the file.

If you can’t answer a question, leave a blank line in this answer file. (The vim option :set number may be useful to you as you edit.)

You can use either nl -ba or cat -n to show the contents of a file with line numbers, to make sure each answer is on its correct line number.

Warning: If you try to use appending redirection to write lines onto the end of this file, you can make a mistake and accidentally overwrite and erase the entire file, forcing you to restart the assignment over again from a snapshot. I recommend setting the shell option set -o noclobber to prevent overwriting the file. This is only a risk if you use redirection; if you only use a text editor to modify the file, you can’t accidentally erase the file as easily. Take frequent snapshots if you disregard this advice.

4 TasksIndexup to index

4.1 CentOS: SnapshotIndexup to index

  1. Complete your CentOS Install and Configure.

  2. Before you begin this assignment, create a snapshot of your CentOS Virtual Machine.
    • Enter a comment explaining where and when you took this snapshot.
    • You can restore back to this snapshot if anything goes wrong.

4.2 Set Up – On The CLSIndexup to index

  1. Do a Remote Login to the Course Linux Server (CLS) from any existing computer, using the host name appropriate for whether you are on-campus or off-campus.

  2. Make the CLS directory ~/CST8207-15W/Assignments/assignment13

4.3 CentOS: Set Up – The Base Directory on CentOSIndexup to index

  1. In your own sysadmin account in your CentOS Virtual Machine, also make the CentOS directory ~/CST8207-15W/Assignments/assignment13 (the same hierarchy as you have already made on the CLS).

This CentOS assignment13 directory in your sysadmin account is the Base Directory for all pathnames in this assignment. Store your CentOS files and answers below in this sysadmin Base Directory.

Run the Fetch and Checking Program to verify your work so far.

Pay careful attention to whether you are working on the CLS or CentOS, and which account you are using! Watch the userid and hostname values in your PS1 prompt string! All answer files in this assignment get stored in the CentOS Base Directory, not on the CLS.

4.4 CentOS: Add a second disk to your VM: sdbIndexup to index

You will add a second hard disk to your CentOS Virtual Machine, 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.

Most of the system admin commands in this assignment access the raw disk and will require you 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. If your CentOS Virtual Machine is not already powered off, login on the console (not a terminal session) and use the correct command to power off the virtual machine safely.
    • Never user the VMware Power Off button to kill power to a running Linux system!
    • Never unplug a running Linux machine!
  2. Create a snapshot of your power-off CentOS Virtual Machine.
    • Enter a comment explaining where and when you took this snapshot.
    • You can restore back to this snapshot if anything goes wrong.
  3. With your CentOS machine still powered off, use the VMware Settings menu for your CentOS VM to add to your VM a virtual 1GB hard disk, accepting defaults for everything except the size. See Create VMware Disk. Create the disk exactly 1GB in size.

  4. After adding the new disk, power on your VM, then login as your system administrator user. Use a remote login, not the VMware console.

Shortcut: Rather than having to power off your VM, you can add the virtual disk in VMware and then ask Linux to re-scan the SCSI bus to find the new disk without rebooting it:
echo "- - -" >/sys/class/scsi_host/host2/scan

  1. Ensure the system partition table file /proc/partitions contains the second disk you added.
    • Verify that there is a second disk of the correct size:
      • The size of your second drive should be 1048576.
      • Divide: 1048576/1024/1024 to confirm the number of gigabytes.
    • Verify that no partitions are listed for the second disk.
    • If you have any sdb1 or sdb2 or other sdb partitions, this is not a new disk with no partition table. Get help.
    • Note the three-letter device name of the second disk.

partitions_before.txt

  1. When the second disk is correct, copy the system partition table flie /proc/partitions to file partitions_before.txt in your CentOS Base Directory (6 lines, 20 words).
    • Remember how you did this; you will need to do it again later.
    • All files should be placed under your sysadmin Base Directory on CentOS.

sd_all.txt

  1. Verify that the three-letter device name for the second disk also exists under the /dev directory. Put a long (ls -l) listing of all names under /dev that start with the first two letters of the new disk name into file sd_all.txt in your Base Directory.
    • Do not change your current directory.
    • Use the absolute pathnames for the devices.
    • No pipeline or other command is needed.
    • The output should show the absolute paths of two disks, and two partitions in the first disk – 4 lines and 40 words.
    • Hint: To match a file name pattern see Glob Patterns

4.5 The useful file command – what is that thing?Indexup to index

The Unix/Linux file command is very useful for identifying things in the file system, such as directories, programs, images, files, and special files that might contain file systems, such as disk partitions:

file_s.txt

  1. Run file -s on the absolute path name of the device name of each of your two disks. Note that your new empty disk says simply data while your ROOT disk has a very long line full of information about the boot sector and partitions:

    # file -s /dev/sd[ab]
    /dev/sda: x86 boot sector; GRand Unified Bootloader, ...
    /dev/sdb: data

    Save the two lines of file output in a file_s.txt file (2 lines, 44 words) in your CentOS Base Directory.

4.6 Viewing and Creating Partitions: fdiskIndexup to index

You must have added a new 1GB hard drive in VMware and made sure that Linux sees the new drive, as described above.

Let’s look at the partitions on the first disk (sda):

  1. Log in to your CentOS machine (unless you are already logged in). Use a remote login, not the VMware console.

  2. Run (always with root privileges) fdisk -cul /dev/sda and you will see the two partitions on your first (sda) disk that holds your main ROOT file system:

    # fdisk -cul /dev/sda
    Disk /dev/sda: 2147 MB, 2147483648 bytes
    255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     3074047     1536000   83  Linux
    /dev/sda2         3074048     4194303      560128   82  Linux swap / Solaris

    DO NOT OVERWRITE /dev/sda THAT IS YOUR MAIN CENTOS INSTALLATION DRIVE!

Now let’s look at the second disk (sdb) that should have no partitions:

  1. Run (always with root privileges) fdisk -cul /dev/sdb and make sure you see Disk /dev/sdb: 1073 MB with no errors and no partitions listed under it.

    # fdisk -cul /dev/sdb
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    ...etc...

    If you don’t see 1073 MB, then shut down, delete the disk, recreate the disk, and reboot until your 1GB disk install works.

Make sure you only change things on this new sdb disk in this section! The sda disk is your Linux ROOT disk; if you damage it you will need to recover back to your snapshot. Make sure you have a snapshot to go back to!

  1. In the CentOS man page for the fdisk command, locate and make a note of two option letters:
    • The option to “Switch off DOS-compatible mode. (Recommended)
    • The option to “give sizes in sectors instead of cylinders

We are now going to run the CentOS fdisk program in interactive mode.

To learn more on how to use fdisk, see your in-class notes from the lecture on Partitions and File Systems or see http://tldp.org/HOWTO/Partition/fdisk_partitioning.html

  1. Start fdisk interactively as root using the command fdiskdevicename, where devicename is the absolute path of the device corresponding to the new disk under /dev.
    • As fdisk starts, read the upper-case WARNING about DOS-compatible mode. This is a serious (strongly recommended) warning!
    • Type the correct one-letter command to quit the fdisk program. Do not continue.
  2. Re-run same fdisk command, this time inserting the two option letters you found in the man page, above. (Keep the same device name.)
    • The DOS WARNING should be gone when you start fdisk with those two options. (One other harmless warning about an invalid flag will remain. This is normal, since the new virtual disk is empty and has not been initialized yet. Ignore the one warning.)
    • Always use these two fdisk options on CentOS. (Other versions of fdisk use these options as defaults.)

You should avoid this DOS warning message in future by always using the -cu command line options to fdisk (RTFM) when you run it, even non-interactively. You might even consider making a shell alias that always supplies these two options to fdisk every time you use it on CentOS: alias fdisk='fdisk -cu'   The above two option letters are now default on most more modern versions of fdisk – always read your local man pages to confirm.

  1. The fdisk utility should now be running in interactive mode, prompting you for input with a different prompt from your BASH shell prompt: Command (m for help):
    • This prompt is the fdisk utility prompt.
    • Do not type Linux commands into the fdisk program prompt!
    • As it says, type the command letter m for a list of helpful fdisk interactive command letters.
  2. Inside interactive fdisk use the command to display the partition table and verify that the disk you are working on is the 1GB disk (1073MB) with no partition table and no partitions.

fdisk_info.txt

  1. Still in interactive mode, read the list of Command action commands. Copy the lines below (7 lines, 50 words) into a file fdisk_info.txt and replace each underscore character with the (one-character) fdisk command letter that does the listed function:

    1. _ save/write partition table to disk (and exit)
    2. _ change a partition's type (system id)
    3. _ exit/quit fdisk without saving changes
    4. _ display/list/print the table of all partitions
    5. _ create/add a new partition
    6. _ show/display/list partition types (system ids)
    7. _ remove/delete a partition

    You will need to use every one of these command letters in this assignment. Make sure you get them right.

  2. Still in interactive mode, use the fdisk command letter that lists all the two-hex-digit partition types:
    • Partition types are also called system identifiers in fdisk.
    • Depending on the size of your terminal screen or console, you may find that the big list is longer than one screen. The first line of output from fdisk should begin with 0 Empty. If you don’t see that first line, you won’t see the correct codes. Use a remote login, not the VMware console.

    Use that list to answer this:

    Add the lines below to the end of the same fdisk_info.txt file and replace the underscore on each line with the hex type number (system id) of the following partition types, making sure you read the numbers correctly from the screen:

    8. _ Linux
    9. _ Linux swap / So
    10. _ HPFS/NTFS
    11. _ W95 FAT32 (LBA)

    The swap line, above, is short for Linux swap / Solaris. You will need all these partition ID numbers later in the assignment.

    Your completed fdisk_info.txt file should be 11 lines 67 words.

Run the Fetch and Checking Program to verify your work so far.

4.6.1 Creating Partitions using fdiskIndexup to index

To learn more on how to use fdisk, see your in-class notes or see http://tldp.org/HOWTO/Partition/fdisk_partitioning.html

Below, we will use the correct commands in the fdisk utility to create the following seven new partitions on your sdb disk.

  • Always accept the default proposed by fdisk for the starting sector of a new partition. Push [Enter]; do not type any numbers. You only need to set the end sector (size) of the new partition using the +size{K,M,G} syntax shown by fdisk.

  • fdisk will sometimes adjust the size of each partition slightly to fit the DOS partition table disk geometry and sector size. Don’t be alarmed that the size that fdisk creates and displays to you isn’t exactly the size you asked for.

  • Use the fdisk command letter to display the partition table after each change to confirm that you created the correct partition with the correct size.

  • No changes will be saved to disk unless you explicitly use the fdisk command letter to save them. You can always quit fdisk before saving any changes.

  • First, make sure the disk you are about to change 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!

  1. On the empty disk (the new disk), create a primary first partition of size 200M.
    • Use the suffix letter M, not MB, inside fdisk. Using MB as a suffix creates partitions using power-of-ten MegaBytes (1,000,000) instead of power-of-two MebiBytes.
    • The type (system id) will default to type Linux. Don’t change the type.
    • Use the fdisk command letter to display the partition table to confirm the values and make sure that the size (in blocks) looks correct for the size you requested.
    • The Start sector of this first partition should be 2048. If it isn’t, you probably forgot to use the option that turns off DOS compatibility. Quit and restart with the correct two options.
    • The End sector must be 411647. If it is less, re-read all the words in this question, especially the words in the sentence starting with “Use the suffix…”.
  2. Create a primary second partition of 100M.
    • Leave the type (Linux) as default.
    • Confirm the change. The Number of blocks must be 102400. (If it is less, re-read all the words in the previous question.)
  3. Create an extended third partition large enough to host the following three logical partitions inside it.
    • You must make the extended partition large enough to hold all three logical partitions described in the next step:

NOTE: As mentioned in class, you cannot create an extended partition exactly the sum of the sizes of the logical partitions inside it. You need to make the extended a bit larger to accommodate the overhead of the logical partition information. Experiment to see how much “a bit larger” means. The end of the extended partition must be less than sector 2097151 that is the last sector in the disk. (i.e. Don’t use up the whole disk for the extended partition!)

  1. Create these three logical partitions inside the extended partition that you created in the previous step:

    1. The size of the first logical partition is 200M. Leave the partition type set as “Linux”.
    2. The size of the second logical partition is 100M. Change the partition type to “Linux swap”.
    3. The size of the third logical partition is 300M. Change the partition type to “HPFS/NTFS”.

    If you run out of space creating the logical partitions inside the extended partition, you can delete the extended partition and start over as many times as needed. (You can also start over by exiting fdisk without saving/writing any of your partition changes.)

    Make the extended partition just big enough to contain the logical partitions, no bigger. Try not to have much wasted space between the end of the third logical partition (its end sector) and the end of the extended partition (its end sector). Hint: 610M is too big; make it smaller.

  2. Create a primary fourth partition that uses up the rest of the space after the end of the extended partition.
    • To do this, accept the defaults for both the start and the end of the partition.
    • The last end sector of this last partition will be the end sector of the disk: 2097151
    • The partition should be about 121MB in size.
    • Set the partition type to W95 FAT32 (LBA).
  3. Did you remember to set the correct partition types (system id) on each of the seven partitions?

  4. When all seven partitions are created, with the correct types and sizes, save your changes (seven partitions) to disk, which will cause fdisk to exit. You will return to your shell prompt.

You may find you have created the extended partition “too big” with wasted space at the end; you can re-do the partition smaller. How much smaller? Divide the number of sectors listed by 2048 (the number of 512-byte sectors in a Megabyte) to get the number of Megabytes you can save.

4.6.2 Verify the partitionsIndexup to index

  1. Verify the creation of seven new sdb partitions:
    • Use ls -l /dev/sd* to see the system device names.
    • Look at the new contents of the system partitions file. (You looked at this file this earlier, when creating partitions_before.txt.)
    • You should have exactly seven partitions on this second disk.

partitions_after.txt

  1. As you did earlier, copy the system partitions file into a partitions_after.txt file:
    • You looked at this file this earlier, when creating partitions_before.txt.
    • The new copy must be 13 lines, 48 words.
    • Use diff to see how this file differs from the previous values you copied in partitions_before.txt.
    • You should see seven new partitions on the new disk.

fdisk_sdb.txt

  1. From the command line, use fdisk (non-interactive) to show the partition table for the new disk, always using the above-mentioned two options to give sector (not cylinder) output and avoid the DOS compatibility warnings. Part of the output will look similar to this:

       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    /dev/sdb2          411648      616447      102400   83  Linux
    /dev/sdb3          616448     1853439      618496    5  Extended
    /dev/sdb4         1853440     2097151      121856    c  W95 FAT32 (LBA)
    /dev/sdb5          618496     1028095      204800   83  Linux
    /dev/sdb6         1030144     1234943      102400   82  Linux swap / Solaris
    /dev/sdb7         1236992     1851391      307200    7  HPFS/NTFS

    The exact numbers for end and blocks of sdb3 and the start and blocks of sdb4 may differ slightly from the numbers above. All the other numbers should match exactly.

    Save the output for your disk into an fdisk_sdb.txt file (16 lines, 98 words).

  2. Look at your new disk (only the new disk) and record these three answers (just the answers) on lines in The Answer File:

    Line 1: Full absolute device names of all primary (not extended) partitions on the new disk. Line 2: Full absolute device names of all extended partitions. Line 3: Full absolute device names of all logical partitions.

    Hint: Re-read the word absolute in the above sentences.

    Hint: Did you read the Warning paragraph in The Answer File?

4.6.3 Deleting a logical partition using fdiskIndexup to index

  1. You have seven partitions on your second hard disk. (Make sure this is true before continuing!) Your partition table should look quite similar to the table shown in the previous section. (Read the comments at the bottom of the table to know the allowed differences.)
    • Create a VMware backup snapshot of this running virtual machine (no need to power down), so you can return here if things go wrong. You can delete the snapshot later, if everything works.
  2. Start fdisk interactively. (Remember the two options to avoid DOS warnings!)
    1. Show the partition table. You should have seven partitions.
    2. Delete the first primary partition that has size 100M.
      • Display the new partition table. You should still have two type Linux (System ID 83) partitions left.
      • Note how when you delete a primary partition, none of the other partitions change names.
      • You now have six remaining partitions on sdb.
    3. Quit fdisk without saving any changes.
      • Do not save the changes. You still have seven partitions.
    4. Start fdisk interactively again. (Remember the two options to avoid warnings!)
    5. Show the partition table. You should still have seven partitions.
      • You have seven because you did not save any changes, right?
    6. Delete the first logical (not primary) partition that has size 200M.
      • Display the new partition table. You now have six partitions.
      • Note how when you delete a logical partition sdb5 the other logical partitions above it all renumber themselves downward to keep the first logical partition numbered sdb5. Logical partitions always number consecutively from 5.
      • You now have six remaining partitions on sdb.
    7. Now save (write) the new partition table (six partitions) to disk, which will cause fdisk to exit. You will return to your shell prompt.
  3. Record the full absolute device names of all remaining logical partitions on Line 4 in The Answer File (two names only).

Run the Fetch and Checking Program to verify your work so far.

4.6.4 Snapshot and PracticeIndexup to index

  1. Create a VMware backup snapshot of this running virtual machine (no need to power down), so you can return here if things go wrong:

    • Name this snapshot something like done_fdisk.
    • You can delete the snapshot later, if everything works.
  2. For practice, use fdisk interactively to delete all the partitions and then re-create them again, without writing out your changes. Don’t save the changes; just practice them.
    • Delete all the partitions, then recreate the above six partitions, but don’t save your work.
    • Would you remember how to do this when asked to demonstrate it at a job interview? When installing a new disk? Practice!
    • Quit fdisk without saving any changes.

4.7 Creating file systems using mkfsIndexup to index

Did you read the Warning paragraph in The Answer File?

After partitioning a disk, the next step is making file systems inside the partitions. You must have six partitions available to continue with this section.

To continue with the next sections of this lab, you must have successfully created these six (remaining) partitions on the 1GB disk. Verify that they have exactly the same Device numbers, exactly the same Id and System, approximately the same Start and End, and approximately the same number of Blocks.

       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    /dev/sdb2          411648      616447      102400   83  Linux
    /dev/sdb3          616448     1853439      618496    5  Extended
    /dev/sdb4         1853440     2097151      121856    c  W95 FAT32 (LBA)
    /dev/sdb5         1030144     1234943      102400   82  Linux swap / Solaris
    /dev/sdb6         1236992     1851391      307200    7  HPFS/NTFS

Do not proceed until you have the above six partitions created.
The sizes may vary slightly. The System ID must match. The end of the Extended partition must be less than the end sector of the disk. There is a large gap between the start of the extended partition and the start of the first logical partition; this gap corresponds to the space left by the deleted 200M logical partition.

All file system commands in the next part of this lab that refer to a hard disk will use one of the above partitions. Do not continue until you have the above partitions created correctly.

  1. Enter the number of sectors in the gap at the start of the extended partition as Line 5 in The Answer File.
    • Read All The Words in the previous paragraphs to know what “the gap” means.
  2. Find the device names of the two partitions that have partition type of Linux (System ID 83). (These should be exactly two of the six partitions.)
    1. On the first Linux partition:
      1. Run file -s on this empty partition and note the uninteresting output when the partition has no file system in it.
      2. Use a command to create a Linux type ext3 file system on this partition.
        • Many lines will print on your screen, telling you the characteristics of the file system you just created. Make sure there are no error messages!
        • Record the exact command line you used to create the file system as Line 6 in The Answer File.
      3. Run file -s on this same partition name again to show the type of file system in the partition.
        • You should see one single output line containing this partition type text: ext3 filesystem data
        • Repeat the command and record the one line of partition type output as Line 7 in The Answer File.
    2. On the second Linux partition:
      1. Repeat the above two commands for creating a file system and showing its type, but use a file system type of ext4 this time.
        • Record your command line and the partition type output line on Lines 8 and 9 in The Answer File.
  3. On the only W95 FAT partition:
    1. Repeat the above command for creating a file system, but use a file system type of vfat this time.
      • The command will fail with: mkfs.vfat: No such file or directory
      • The commands for creating DOS file systems are not installed!
      • Confirm the missing command by running: whereis mkfs.vfat
      • We can try to fix this by finding and installing the right package.
    2. To locate the missing package run a query command: yum whatprovides '*/mkfs.vfat'
      • yum will update some internal files then tell you that the missing package name is dosfstools (with a version number).
    3. Install the missing dosfstools package.
      • Verify that which mkfs.vfat now finds the command.
      • (If it doesn’t find it, make sure /sbin is in your PATH.)
    4. Again: Repeat the above two commands for creating a file system and showing its type, but use a file system type of vfat this time.
      • Making this simple file system produces far fewer lines of diagnostic information.
      • If you have installed the missing dosfstools package, everything will work correctly with no errors.
      • Record your command line and the partition type output line on Lines 10 and 11 in The Answer File.
  4. On the only HPFS/NTFS partition:
    1. Repeat the above steps for creating a file system, but use a file system type of ntfs this time.
      • The command will fail with: mkfs.ntfs: No such file or directory
      • The commands for creating NTFS file systems are not installed!
      • Confirm the missing command by running: whereis mkfs.ntfs
      • We can try to fix this by finding and installing the right package.
    2. As you did before, try to locate the missing package based on the missing mkfs.ntfs file name.
      • yum will update some internal files then tell you No Matches found
      • This version of CentOS does not support NTFS file systems using the standard yum repositories for software! :-(
      • We could install an experimental NTFS software package, but we don’t want any experimental software on our server machine.
    3. Give up without making any NTFS file system here.
    4. Send an angry note to Microsoft for using undocumented file system formats that have to be experimentally reverse-engineered.

Run the Fetch and Checking Program to verify your work so far.

4.7.1 Snapshot and PracticeIndexup to index

  1. Create a VMware backup snapshot of this running virtual machine (no need to power down), so you can return here if things go wrong:

    • Name this snapshot something like done_mkfs.
    • You can delete the snapshot later, if everything works.
  2. For practice, repeat this section again, re-typing each of the commands you used to create the file systems. Would you remember how to do this when asked to demonstrate it at a job interview? When installing a new disk? Practice!

4.8 Mounting & Unmounting a Linux File system using mountIndexup to index

Did you read the Warning paragraph in The Answer File?

After partitioning a disk and creating file systems, next comes mounting the new file systems onto existing directories in the system. You must have created six partitions with three new file systems to continue.

mount_before.txt

  1. List all the currently mounted file systems using the mount command with no arguments.
    • You should see six lines, or seven if you use VMware and have a vmware-vmblock device mounted.
    • None of the above new file systems should be visible in the output. If you have any disk partitions mounted other than the ROOT partition (sda1), unmount the partitions now before continuing.
    • Save the mount output as a mount_before.txt file. (6 lines, 36 words or 7 lines, 42 words if you use VMware)
  2. Use a single command to create (empty) directories named /mnt/ext3, /mnt/ext4, and /mnt/vfat to use as mount points for all the file systems you successfully created above.
    • If you don’t remember to create the empty directory first, the mount command will generate error messages such as mount point /mnt/ext3 does not exist.
  3. Use mount commands to mount all three file systems you created previously, each mounted on its own self-named directory. (Recall that each file system was created with a particular type. Match the partition file system type with the directory name.)
    • You do not need to specify the type of the file system being mounted, because mount can tell. If mount says you must specify the filesystem type then almost surely there is no file system created in that partition. Fix it and then try again.
    • Record as Lines 12-14 in The Answer File the three mount commands you used to mount these three partitions. (Remember: The directories must already exist!)

Reminder: You almost never need the -t option when mounting a file system, since Linux knows the type by looking inside the partition. If mount ever gives the error you must specify the filesystem type, it is because there is no file system created inside that partition. The file -s command can confirm this for you. Create the file system first, then mount it.

4.8.1 Show mounted: mountIndexup to index

mount_after.txt

  1. Use mount without any arguments to verify that you have three new mounted file systems. Each file system type should match the directory name on which it is mounted. Each file system should be mounted only once. (If you have duplicate entries, unmount them using the umount command.)
    • Save the mount output as a mount_after.txt file. (9 lines, 54 words or 10 lines, 60 words if you use VMware)

file_after.txt

  1. Save the output (run as root) of file -s /dev/sd* as a file_after.txt file. (10 lines)
    • You should now see needs journal recovery on three lines, including the two newly-mounted Linux file systems.

blkid_after.txt

  1. Save the output (run as root) of the command blkid as a blkid_after.txt file. (at least 5 lines)
    • This command shows you the UUID values that you could use to uniquely identify each partition in the first column of the /etc/fstab file. (Do not use UUID mount names in this assignment; use the device partition names when the time comes.)
  2. Use the command ls -lid / /mnt/ext? to see the inode numbers of the three Linux directories mounted on your system.
    • Notes that all three directories have the same inode number 2. Aren’t inode numbers supposed to be unique? (Review Links and Inodes.) Know why these three directories have the same inode number. (This question may appear on your final exam.)
  3. Create a VMware backup snapshot of this running virtual machine (do not power down), so you can return here if things go wrong:

    • Name this snapshot something like done_3mount.
    • You can delete the snapshot later, if everything works.
    • If you power down, you will lose the three mounted file systems and will have to re-mount them after the reboot.

4.8.2 Show mounted: dfIndexup to index

This section depends on having the three newly-mounted file systems, done above. If you rebooted your machine, you need to re-mount the three file systems again before you continue. See above.

  1. The df (“disk free”) command shows information about mounted file systems, including the amount of disk space used and disk space still available. A useful option is -h that shows output in “human-readable” form.
    • Use the command df -h to see the sizes of the file systems.
  2. The two new, empty Linux file systems we just mounted show about 5.6MB and 1.6M of space used, even though the file systems contain no files yet. Know why a new file system is not empty; this question may appear on your final exam.

  3. If you add up the Used plus Available disk space on a VFAT (DOS) file system, it exactly equals the Size of the file system. If you add up Used+Available on a Linux file system, it is usually about 5% smaller than the Size of the file system. Why? (This question may appear on your final exam.)

4.8.3 Disk Usage - duIndexup to index

The du command walks the file system and recursively shows the disk usage in every directory under a directory.

  • With the -s option, only the summary of the disk usage is shown.
  • With the -h option, the output is given in “human-readable” form (similar to the same option to df).
  • With the -x option, du will stay within a file system and not follow directories that are mount points.
  1. Use du to show a summary of the human-readable amount of disk space on only the / (ROOT) file system.
    • You will need three option letters.
    • The command will take some time to finish! Wait for it!
  2. Compare the speed of running the above du command (which has to walk the entire ROOT directory tree) against the speed of running df in the previous section. This is why sysadmin prefer df!

4.8.4 Unmount all three new file systemsIndexup to index

  1. Unmount all three file systems that you just mounted.
    • Make sure that the system is back to the state you recorded in the mount_before.txt file: only six or seven lines.

Run the Fetch and Checking Program to verify your work so far.

4.8.5 PracticeIndexup to index

  1. For practice, repeat this section again, re-typing each of the commands you used to mount and unmount each file system. Would you remember how to do this when asked to demonstrate it at a job interview? When installing a new disk? Practice!

4.9 Preparing a Swap Partition using mkswap and swaponIndexup to index

Did you read the Warning paragraph in The Answer File?

  1. Use one command to initialize the Linux swap partition on your new 1GB disk.
    1. Record the command line you used as Line 15 in The Answer File.
    2. Record as Line 16 in The Answer File the output of using file -s on the Linux swap partition.
      • The output should include the words swap file
  2. Use one command to tell the kernel to use the new swap device.

swap.txt

  1. Display the list of active swap partitions.
    • Save the output of this command in a swap.txt file. (3 lines, 15 words)
  2. Disconnect the swap area you just connected.
    • Only one swap partition should remain, on your first disk.

Run the Fetch and Checking Program to verify your work so far.

4.9.1 Snapshot and PracticeIndexup to index

  1. Create a VMware backup snapshot of this running virtual machine (no need to power down), so you can return here if things go wrong:

    • Name this snapshot something like done_swap.
    • You can delete the snapshot later, if everything works.
  2. For practice, repeat this section again, re-typing each of the commands you used to initialize and enable the swap partition. Would you remember how to do this when asked to demonstrate it at a job interview? When installing a new disk? Practice!

4.10 Kernel Version Number (release number)Indexup to index

Did you read the Warning paragraph in The Answer File?

Your Linux kernel has a version number, as in
“What version of the kernel are you running? I’m running version 2.6.32”.
The version number is often followed by a dash and some sub-version numbers and qualifiers, e.g. 2.6.32-504.1.3.el6.i686.

Unfortunately, the command that prints system information, including the kernel version number, calls the number a kernel release number, because it uses the option name version to stand for the kernel compile date. When using this system information command you must use the option named release to display the kernel version number.

  1. Display only the version (release) of the Linux kernel that is running on CentOS (one word, no spaces):
    • The output starts with the digit 2. on CentOS 6 and is at least 19 characters long (but may be longer, if you have upgraded your CentOS VM kernel recently).
    • Record the command line you must use as Line 18 in The Answer File.
    • Record the one line of output for CentOS as Line 19 in The Answer File. (One word; no spaces.)
  2. Log in to the CLS find out what kernel version it is running.
    • The output starts with the digit 3. on the CLS – the CLS runs a newer kernel than CentOS.
    • Record the one line of output for the CLS as Line 20 in The Answer File. (One word; no spaces.)

Run the Fetch and Checking Program to verify your work so far.

4.11 Booting into single-user mode (changing forgotten root password)Indexup to index

Did you read the Warning paragraph in The Answer File?

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 are given a root shell and 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.)

Review Booting and GRUB.

This section depends on a successful CentOS Virtual Machine installation, including a visible (not hidden) GRUB menu. (You made these changes when you configured CentOS in an earlier assignment.)

To change a forgotten root password or do maintenance on the system that requires it to be quiescent (no users or disk activity), you can boot your system in a restricted single-user mode that does not start many system daemons and goes directly into a root shell prompt on the system console without requiring a password.

The system should not be left in single-user mode; many service programs are not started. Networking may not be enabled; you may not even be able to log-in remotely (e.g. using SSH) in single-user mode.

  1. View your CentOS GRUB configuration file and look at the (very long) kernel line in that file. Note all the options used on the right end of the kernel line; you will see them again soon.
    • Record on Line 21 in The Answer File the Linux absolute pathname of this GRUB configuration file.
  2. Record on Line 22 in The Answer File the kernel option keyword used in booting a machine single-user (maintenance mode). (one word)

  3. Safely reboot your CentOS VM into the GRUB menu:
    • You will need to be on the VMware console to see this, since ssh sessions will be killed across a reboot.
    • Halt the GRUB menu time-out:
    • When the boot process begins, if you correctly disabled the hiddenmenu command in GRUB, you will boot directly to the GNU GRUB menu where you should see a list of CentOS systems to boot and at the bottom a 30 second countdown in progress.
    • Interrupt the countdown by pressing an arrow key. (If you didn’t disable hiddenmenu, when the countdown is interrupted your system should display the one-entry GRUB menu.)
CentOS 6 GRUB Menu

CentOS 6 GRUB Menu

  1. Now, just as the GRUB menu instructions tell you, to modify the kernel arguments you press just the single letter a – just the letter key, no [Enter] key!
    • After pressing a you will see your cursor on a line that ends with the same kernel arguments you viewed earlier in the configuration file.
    • You can use the [Home] key to zoom to the left end of the kernel options line, and the [End] key to zoom to the right:
CentOS 6 Kernel Options

CentOS 6 Kernel Options

  1. Modify this kernel options line so that the system will boot single-user. (Add the correct kernel option keyword to the right end of the line.)
    • As the instructions say, push [Enter] to accept your changes and directly boot the system using these new kernel options.
    • These changes to the kernel options are not saved back into the configuration file – they are only in effect for this boot menu.
    • (If you wanted to abandon your changes and leave the menu entry unmodified, you would have used the Escape key, as it says.)
  2. The system should come up in single-user (maintenance) mode with a root shell prompt. (If you get a login prompt, you didn’t use the right kernel option keyword. Reboot into GRUB and try again.)
    • You can perform any root function at this prompt, including changing passwords (even the root password).
    • Often single-user mode has no networking enabled and only a minimal number of file systems mounted.

psbsd_single.txt

  1. From the single-user shell, place a full list of all processes for all users, BSD format, text user name (not numeric UID), full wide listing (not truncated at all), into a psbsd_single.txt file. (All assignment answer files must be saved in your sysadmin Base Directory.) The output should be approximately 55 lines and 4KB. (If you have many more than this, perhaps you mistakenly set your VM to use more than 1 processor?) All the processes in the listing will be owned by root. The first two lines should look similar to this:

    USER  PID %CPU %MEM  VSZ   RSS TTY  STAT START   TIME COMMAND
    root    1  0.0  0.5 2900  1380 ?    Ss   16:35   0:01 /sbin/init

    Remember to fix the owner and group of the file.

  2. Use the command that displays the previous and current Run Level (two words on one line) and record this line of output as Line 23 in The Answer File.

  3. Leave single-user mode and let the system finish booting into full multi-user mode:
    • Leaving single-user mode does not mean rebooting the machine; do not reboot or shut down the machine.
    • Go directly from single-user to multi-user mode without a shutdown or reboot.
    • The login prompt should appear on the console.
  4. Log in as your sysadmin account. Use a remote login, not the VMware console. Repeat the command that displays the previous and current Run Level and save the output as Line 24 in The Answer File (two more words on one line).
    • If you rebooted the machine, you won’t have the right answer here. Boot back into single-user mode and then transition to multi-user mode without a shutdown or reboot.

Run the Fetch and Checking Program to verify your work so far.

4.12 Changing System V Run Levels and ServicesIndexup to index

Did you read the Warning paragraph in The Answer File?

See the course notes on Legacy Run Levels and Services. As with most system maintenance activities, you will need to use the root user to run the privileged commands in this section.

  1. If not already logged in, log in to the CentOS VM console (not via SSH) as your ordinary (non-root) sysadmin account.
    • You will see console messages if you are logged in to the console, which you will not see using an SSH terminal connection.

chkconfig-before.txt

  1. Use a command to list all services and all run level information into file chkconfig-before.txt in your CentOS assignment13 directory. It should be approximately 22 lines. Two of the lines should look like this:

    ntpdate         0:off   1:off   2:off   3:off   4:off   5:off   6:off
    postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
  2. Use the same command name to enable (turn on) the NTP Date service only in Run Level 4 (a normally unused Run Level in CentOS).

  3. Use the same command name to disable (turn off) the above Postfix Mail Service service in Run Level 4.

chkconfig-after.txt

  1. Save a second listing of all services and all run levels into file chkconfig-after.txt in your CentOS assignment13 directory. It should still be approximately 22 lines. Two of the lines should now look like this:

    ntpdate         0:off   1:off   2:off   3:off   4:on    5:off   6:off
    postfix         0:off   1:off   2:on    3:on    4:off   5:on    6:off
  2. Use the diff command to compare the before listing file with the after listing file. Only two lines should have changed.

postfix.txt

  1. Run a command to show a full list of all processes for all users, BSD format, text user name (not numeric UID), full wide listing (not truncated at all) and search for any lines containing the string postfix.
    • You will see about three or four lines.
    • Save those three or four lines into a postfix.txt file.
  2. Record as Line 25 in The Answer File the Linux absolute pathname of the system configuration file that gives the default Run Level for your CentOS system.

  3. Record as Line 26 in The Answer File the one line from the above system configuration file that sets the default Run Level for your CentOS system. (Hint: It’s the only non-comment line in the file!)

  4. Use a command to confirm that your current Run Level is the same as the CentOS default Run Level. (This should be true unless you are running in single-user mode, which you should not be.)

  5. On the system console (not a terminal session), use a command to change from the current Run Level (which should be the default) to Run Level 4. You will see (only if logged in on the console) various status messages about services that stop and start:
    • The Postfix service will announce that it is shutting down.
    • The udev event manager will retrigger some events.
    • The ntpdate service will try to synchronize the time, and fail.
  6. Use the command that displays the previous and current Run Level (two words on one line) and record this line of output as Line 27 in The Answer File.

  7. In a system log file, find the reason that the ntpdate service did not work:
    • How do you know which System Log Files were modified most recently? Those log files are the files you should look in for the log message.
    • The message from ntpdate talks about a socket being in use.
    • When you find the right log file name, record the Linux absolute pathname of the correct log file as Line 28 in The Answer File.
    • Record this last ntpdate log message as Line 29 in The Answer File.
  8. Run a command to show a full list of all processes for all users, BSD format, text user name (not numeric UID), full wide listing (not truncated at all) and again search for any processes running as the postfix userid.
    • No processes running as the postfix userid will be found. (You might see a process run by you, searching for postfix.)
  9. On the system console (not a terminal session), use a command to change from the current Run Level 4 back to the CentOS system default Run Level. You will again see (only if logged in on the console) various status messages about services that stop and start:
    • The udev event manager will retrigger some events.
    • The Postfix service will announce that it is starting.
  10. Use the command that displays the previous and current Run Level (two words on one line) and record this line of output as Line 30 in The Answer File.

  11. Confirm that the postfix processes are again running.

Run the Fetch and Checking Program to verify your work so far.

4.13 Manually Starting/Stopping ServicesIndexup to index

Did you read the Warning paragraph in The Answer File?

See the notes on Starting and Stopping Services. As with most system maintenance activities, you will need to use the root user to run the privileged commands in this section.

  1. Make sure your system is running as the default CentOS Run Level.

  2. Use a command to ask for the service status of the postfix service:
    • The output of the command will include the pid of the service and say that the master process is running.
    • Record the one line of output (with the pid) as Line 31 in The Answer File.
    • Hint: Do not use any command name not taught in this course. Review the List of Command Names taught in this course.
  3. Use the same command name to stop the postfix service:
    • You will see one line of logging information saying: Shutting down postfix: [ OK ]
  4. Use the same command name to ask for the service status of the postfix service:
    • The output of the command will say that the master service is stopped.
    • Record the one line of output from the command as Line 32 in The Answer File. (Record the stopped output line from the status command, not the Shutting down logging information.)
  5. Use a command to start the postfix service:
    • You will see one line of logging information saying: Starting postfix: [ OK ]
  6. Use the same command name to try to start the ntpdate service:
    • The command will pause for a minute or so.
    • You will see one line of service status information saying: [FAILED]
    • Look at the end of the correct system log file and copy and record the one-line reason it failed as Line 33 in The Answer File.

    Hint: How do you know which System Log Files were modified most recently? Those log files are the files you should look in for the log message. Look at the end of that log file for the message from ntpdate.

Run the Fetch and Checking Program to verify your work so far.

4.14 When you are doneIndexup to index

That is all the tasks you need to do.

Log in to the CLS and submit your mark from the CLS following the Checking Program instructions below.

Read your CLS Linux EMail and remove any messages that may be waiting. See Reading eMail for help.

Optional: Keeping your main configuration snapshots, 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 WorkIndexup to index

See CentOS: Remote Checking, Marking, and Submitting your Work.

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

Author: 
| 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