CST8207: GNU/Linux Operating Systems I

Lab Worksheet and Assignment Twelve

Disks, Partitions, and File Systems


This is Worksheet and Assignment 12

This is a combined Worksheet and Assignment.. Quizzes and tests may refer to work done in this Worksheet and Assignment; save your answers. You will use a checking program to verify the correctness of your work, as described on-line in Assignment #12. You must upload the check program results before the due date.

Before you get started - REMEMBER TO READ ALL THE WORDS

You must have your own Fedora 12 virtual machine (with root permissions) running to do this lab. You cannot do the lab on the Course Linux Server because you do not have root permissions on that machine. You must follow the on-line Assignment #12 instructions for checking your work and uploading a mark.

Disks, Partitions, and File Systems

1Commands, topics, and features covered

Use the on-line help (man command) for the commands listed below for more information.

2Correct user, command lines, and command output

3Backup and Recovery

  1. Take a snapshot of your virtual machine before you begin this lab (and perhaps before you begin each new section) so that you can recover back to the snapshot if needed. You can delete the unnecessary snapshots (and reduce your disk use) after you finish the lab successfully.

  2. Are you keeping an external backup copy of all your virtual machines somewhere? You should be!

4Creating a new VMware virtual hard disk

  1. Shut down your Fedora machine so it is powered off and not just suspended.

  2. With your Fedora machine still powered off, add to it a VMware virtual 1GB hard drive as shown in the Course Notes ("Create a New VMware Virtual Hard Disk" PDF). Create it exactly 1 GB in size.

  3. Reboot (power on) your Fedora virtual machine. Check - the new disk should appear as /dev/sdb:

    1. ls -l /dev/sd* (make sure the sdb disk is visible)

    2. cat /proc/partitions (make sure the sdb disk is visible)

  4. Make sure you only change things on this new sdb disk in this lab! The sda disk is your Linux ROOT disk; if you damage it you will need to recover back to your snapshot. You do have a snapshot, right?

5Viewing Existing Partitions using fdisk

  1. First, you must have added a new 1 GB hard drive in VMware and rebooted, as described above.
    DO NOT USE /dev/sda WHICH IS YOUR MAIN FEDORA INSTALLATION DRIVE!

  2. Make sure you have root (super-user) privileges.

  3. At the root shell prompt, type “cat /proc/partitions” and verify that you have an sdb partition of 1GB (approx 1048576 blocks) and that you do not have any sdb1 or sdb2 partitions. If you have any sdb1 or sdb2 or other sdbN partitions, call over your instructor before you continue!

  4. To manage partitions, use the fdisk command. An essential option (try it!) is "-l", e.g.: fdisk -l

  5. Run: fdisk -l /dev/sdb (make sure you see Disk /dev/sdb: 1073 MB)

  6. At the root shell prompt, type (make sure you use the disk device sdb!): fdisk /dev/sdb
    Make sure you use sdb. You will get several warning messages about a “new DOS disklabel” and an invalid flag. This is normal, since the new virtual disk has not been initialized yet. Continue:

  7. The fdisk utility is now prompting you for input with a different prompt: Command (m for help):
    This prompt is the fdisk utility prompt. As it says, type m for a list of menu options for fdisk.

  8. Read the list of Command action commands and record the (one-character) fdisk command to:

    1. display/list/print the table of all partitions: ______

    2. create/add a new partition: ______

    3. remove/delete a partition: ______

    4. show/display/list partition types (system ids): ______

    5. change a partition's type (system id): ______

    6. save/write partition table to disk (and exit): ______

    7. exit/quit fdisk without saving changes: ______

  1. Select the fdisk option that lists the partition types. (Partition types are also called “system identifiers”.) Record the type (system id) number of the following partition types, making sure you read them correctly:

    1. "Linux": ______

    2. "Linux swap / So": ______ (short for Linux swap / Solaris)

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

6Creating Partitions using fdisk

Use the correct commands in the fdisk utility to create the following six new partitions on your sdb disk. Note that fdisk will adjust the size of each partition slightly to fit the DOS partition table disk geometry; don't be alarmed that the size that fdisk creates and displays to you isn't exactly the size you asked for. Display the partition table after each change to confirm that things are working. To learn how to use fdisk, see your in-class notes or see http://tldp.org/HOWTO/Partition/fdisk_partitioning.html

  1. Create a primary partition of 200 MB. The type (system id) will default to type “Linux”.

  2. Create another primary partition of 100 MB. Leave the type (Linux) as default.

  3. Create an extended partition large enough to host the following three logical partitions that total 600MB. You must make the extended partition large enough to hold all three logical partitions described in the next step. NOTE: You cannot create it exactly 600MB. You need to make it a bit larger to accommodate the logical partition information. Experiment to see how much “a bit” means. The end of the extended partition must be less than cylinder 130. (130 is the end of the disk.)

  4. 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 200MB. Leave the partition type set as "Linux".

    2. The size of the second logical partition is 100 MB. Change the partition type to "Linux swap".

    3. The size of the third logical partition is 300MB. 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 partitions 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, no bigger.

  1. Did you remember to set the correct partition types (system id) on each of the six partitions?

  2. Save your changes (six partitions) to disk and exit fdisk. You will return to your root shell prompt.

  3. Verify the creation of six new sdb partitions using both command lines "ls -l /dev/sd*" and “cat /proc/partitions” again. You should have exactly six partitions on this second disk.

  4. Use fdisk to show the partition table, listing the six new partitions that you just created (sdb1, sdb2, sdb3, sdb5, sdb6, sdb7) and answer these questions from the fdisk output:

    1. Give the full device name, blocks, and ID of the two Primary Partitions on the new 1.0GB Drive:

________________________ , _________ , ___

________________________ , _________ , ___

    1. Give the full device name, blocks, and ID of the one Extended partition on the new 1.0GB Drive:

________________________ , _________ , ___

    1. Give the full device names, blocks, and ID of the three Logical partitions on the new 1.0GB Drive:

________________________ , _________ , ___

________________________ , _________ , ___

________________________ , _________ , ___

    1. How many more Primary Partitions could you create on the new 1.0GB Drive, and explain Why:

_

    1. If you had enough disk space, how many more Logical partitions could you create on the new 1.0GB Drive, and explain Why:

_

7Deleting a logical Partition using fdisk

  1. You have six partitions on your second hard disk. (Make sure this is true before continuing!) Create a VMware backup snapshot of this virtual machine, so you can return here if things go wrong.

  2. Use fdisk to delete the first logical (not primary) partition that has size 200MB.

  3. How has the partition numbering changed for the five remaining partitions, after the deletion?

    _______________________________________________________________________________

    _______________________________________________________________________________

    _______________________________________________________________________________

  4. Save (write) the partition changes (now only five partitions) to disk and exit fdisk.

  5. Re-enter fdisk and (re-)create a new logical partition on the second disk, but do NOT save your work. How does the partition numbering change when you recreate the partition you just deleted?

    _______________________________________________________________________________

  6. Are the three logical partitions again in ascending Start block order on the disk? ________________

  7. Switch to the Extra/Expert Mode menu. What Expert command letter fixes partition order? ______

  8. Use the Expert Command to "fix" the partition order. Return to the main menu (non-Expert mode) and list the partitions now. Are the logical partitions now in ascending Start block order? __________

  9. Exit fdisk without saving the sixth partition or the fixed partition order. Do not save your work.

  10. You still have five remaining partitions, the same that you saved in step 4 above. Check these five partitions in the next step.

8Use your 1 GB disk and five partitions from the previous steps

To continue with the next sections of this lab, you must have successfully created these five (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.

# fdisk -l /dev/sdb
Device Boot Start End Blocks Id System

/dev/sdb1 1 26 208813+ 83 Linux

/dev/sdb2 27 40 112455 83 Linux

/dev/sdb3 41 119 634567+ 5 Extended

/dev/sdb5 67 80 112423+ 82 Linux swap / Solaris

/dev/sdb6 81 119 313236 7 HPFS/NTFS

Do not proceed until you have the above five partitions created. The sizes may vary slightly. The System ID must match. The end of the Extended partition must be less than cylinder 130. (130 is the end of the disk). There is a 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 200MB 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. Create a back-up of your 5-partition system now using the VMware snapshot function. You can return to this back-up if anything goes wrong during this lab, or if you want to repeat the lab for practice.

  2. Use fdisk to delete all the partitions and then re-create them again, without writing out your changes. Recreate the above five 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!

9The useful file command - what is that thing?

  1. The Unix/Linux file command is very useful for identifying things in the file system, such as directories, programs, images, files, and special files such as disk partitions. Run the file command and give it as a single argument the full absolute path name of the device file of the Extended partition on your new 1.0 GB disk. Record the command line and the output here:

    ____________________________________________________________________

    ____________________________________________________________________

  2. Repeat the above command line and add the option that makes file examine special files (e.g. block devices) and give the new command line and new extended (x86 boot sector) output here:

    ____________________________________________________________________

    ____________________________________________________________________

    ____________________________________________________________________

    ____________________________________________________________________

  3. Use file (and the correct special file option) on the new Linux swap partition device file and record the (not very useful) output here. (You will note that an empty new partition isn't very interesting.)

    ____________________________________________________________________

  4. Use file (using the correct special file option) on the first partition of the first disk (not your new disk) and record the more useful information printed about the type of file system stored in the partition. Record that command line (using the absolute path of the device file of the first partition of the first disk) __________________________________________________________

  5. Record the output of the previous command line (about an ext4 file system and journal) here:

    ____________________________________________________________________

    ____________________________________________________________________

    ____________________________________________________________________

  6. Try using the file command on various other pathnames and see what it says. Try your ODT files, the password file, the /bin/ls program, the vmlinuz file under /boot. Lastly, use file on /etc/favicon.png and then add the option to dereference (follow) the symbolic link and give the full command line (use the full absolute pathname) and record the (PNG image) output here:

    ____________________________________________________________________

    ____________________________________________________________________

10Creating file systems using mkfs

Make sure you have the five partitions from the previous steps available. To create a file system on an existing partition or device, use one of the mkfs commands. (The partition must already exist!)

  1. Find the device names on your 1GB disk of the two partitions that have partition type (System ID) of Linux”. Create a Linux type ext3 file system on the first Linux partition. Record the exact command line you used, and the output of “file -s device_name” for the device name you used:

    _______________________________________________________________

    _______________________________________________________________

  2. Create an ext4 file system on the second partition that has type “Linux”. Record the exact command line you used, and the output of “file -s device_name” for the device name you used:

    _______________________________________________________________

    _______________________________________________________________

  3. Create an ntfs file system on the only “HPFS/NTFS partition. Record the exact command line you used, and the output of “file -s device_name” for the device name you used:

    _______________________________________________________________

    _______________________________________________________________

    _______________________________________________________________

    _______________________________________________________________

  4. Take a VMware back-up snapshot now and name it something like “done_mkfs”.

11Mounting & Unmounting a Linux File system using mount

  1. List all the partitions on your system using: fdisk -l
    You may see two error messages about /dev/dm-0 and /dev/dm-1 that you can ignore.
    Record the sizes of Disk /dev/sda and Disk /dev/sdb: ___________________________

  2. List all the mounted file systems using: mount with no arguments and answer these questions:
    What partition device name is mounted on the /boot directory? ______________________

    What type of file system is the /boot file system? ______________________

11.1Mount three file systems

  1. Create three directories named /mnt/ext3, /mnt/ext4, and /mnt/ntfs to use as mount points for the three file systems you created at the end of Section 3. (You can reduce your typing by using one command with brace brackets to express the three pathnames.) After creating them, record the output of:

    ls -id /mnt/ext3 /mnt/ext4 /mnt/ntfs

    _______________________________________________________________

    (You can also reduce your typing by using the brace brackets on the above command line!)

  2. Use three mount commands to mount the three file systems you created previously, each mounted on its own directory from above. (Recall that each file system was created with a particular type. Match the file system type with the directory name.) Record the three mount commands you used to do this here:

    _______________________________________________________________

    _______________________________________________________________

    _______________________________________________________________

    (Sorry, you can't use brace brackets here - you have to use three separate command lines.)

  3. 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.)

  4. Record again the (different!) output of: ls -id /mnt/ext3 /mnt/ext4 /mnt/ntfs

    _______________________________________________________________

    (You can again reduce your typing by using the brace brackets on the above command line!)

  5. Note the very small inode numbers used for the ROOT inode on each of these three file systems. The ROOT of a file system typically uses one of the very first available inode numbers.

  6. Leave the three file systems mounted. Take a VMware back-up Snapshot now and name it something like “done_3mount”.

11.2Disk Free - df

  1. The df 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. Give the human-readable amount of disk space Used and Available on the /boot file system:

    _______________________________________________________________

  2. If you add up the Used plus Available disk space on an NTFS file system, it 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? (See your notes or search for: why linux reserved space )

    _______________________________________________________________________________

    _______________________________________________________________________________

    _______________________________________________________________________________

11.3Disk Usage - du

  1. 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). Use du to show a summary of the human-readable amount of disk space on the / (ROOT) file system and record the command line used and its output here (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 directory tree) against the speed of running df in the previous section. Also compare the Used output of df with the summary output of du. Why does df say that more disk space is used than du? (See your notes.)

    _______________________________________________________________________________

    _______________________________________________________________________________

12Preparing a Swap Partition on a hard drive using mkswap and swapon

  1. Enter three commands: Initialize the Linux swap partition on your new 1 GB disk; tell the kernel to use it; display the active swap partitions. Record the three command lines used to do these three actions:

    _______________________________________________________________

    _______________________________________________________________

    _______________________________________________________________

  2. Record the output of “file -s device_name” for the swap device name you used:

    _______________________________________________________________

  3. Record the command (and option) that will display the list of currently active swap areas:

    _______________________________________________________________

  4. Run the above command and record the three lines of output (two active swap areas) here:

    _______________________________________________________________

    _______________________________________________________________

    _______________________________________________________________

  5. Leave the new swap area connected. Take a VMware back-up Snapshot now and name it something like “done_swap”.

13Creating a Linux File system on a virtual Floppy disk and mounting/unmounting/ejecting it

13.1Creating a VMware virtual floppy disk image file

  1. In VMware, click VM Settings

  2. Select Floppy in the Virtual Machine Settings window

  3. Select Use a floppy image

  4. Select the Create... button to create a new floppy disk image file. Name the file: linux.flp
    and select Open to create the file and attach it to your Fedora virtual machine. (Remember where the file is on your disk, so that you can find it again later!)

  5. Back in Virtual Machine Settings, ensure that the floppy is Connected: make sure the Device Status Connected checkbox is checked.

  6. DO NOT check the Connect at power on box or your Fedora machine will not boot.

  7. Click Save to save the new Virtual Machine Settings.

  8. At your Fedora super-user command line, verify that the floppy disk image file is connected by using:

    fdisk -l /dev/fd0

    The first line of output should read: Disk /dev/fd0: 1 MB, 1474560 bytes

13.2Creating a Linux file system on a virtual floppy disk and mounting/unmounting/ejecting it

  1. Create a type ext2 (the default) file system on your floppy disk. Record the exact command line you used, and the output of “file -s device_name” for the floppy disk device name you used:

    _______________________________________________________________

    _______________________________________________________________

  1. Mount the floppy disk file system on /mnt/linux after creating it. Record the command used:

    _______________________________________________________________

  1. Use mount without any arguments to verify that you have a new ext2 file system mounted and copy the single line of output related to the only floppy disk device here:

    _______________________________________________________________

  1. Copy a file to the floppy disk: cp -a /etc/passwd /mnt/linux/passwd

  2. Use this command to see the Linux directory contents: ls -lia /mnt/linux

    Copy only the two lines of output for the lost+found directory and the passwd file here:

    _______________________________________________________________

    _______________________________________________________________

  3. To “eject” a virtual floppy disk, first un-mount it from Linux and then un-check (disconnect) the VMware Device Status Connected checkbox. Do not eject a floppy disk that is still mounted in your Fedora machine! Unmount it first, and only then disconnect it. Do this now: un-mount the floppy and then eject it. Verify that "fdisk -l device_name" gives no output for the unmounted floppy device and copy here the output of “file -s device_name” for the floppy device name you used:

    _______________________________________________________________

14Creating a Microsoft FAT file system on a virtual floppy disk and mounting it

14.1Creating a VMware virtual floppy disk image file

  1. Create and attach to Fedora a new virtual floppy disk image file named: windows.flp
    This new image file you create will replace your Linux floppy image on the virtual floppy disk drive. Make sure you have unmounted your Linux floppy image file before you create and switch images!

  2. Verify that the floppy disk image file is connected as you did in an earlier section above.

    The first line of output should read: Disk /dev/fd0: 1 MB, 1474560 bytes

14.2Creating a Microsoft FAT file system and mounting it

  1. Create a type vfat file system on your Windows floppy disk. Record the exact command line you used, and the output of “file -s device_name” for the floppy disk device name you used:

    _______________________________________________________________

    _______________________________________________________________

  2. Mount the floppy disk file system on /mnt/windows after creating it. Record the command used:

    _______________________________________________________________

  3. Use mount without any arguments to verify that you have a new vfat file system mounted and copy the single line of mount command output related to the only floppy disk device here:

    _______________________________________________________________

  4. Copy the password file to the new floppy disk in a manner similar to the last time you copied it.

  5. Use the ls -lia command to show three lines of output for the contents of your floppy disk, similar to the way you did before. Copy the one line of output for the new copy of the passwd file here:

    _______________________________________________________________

  6. Why is there no lost+found directory shown in the output above?

    ____________________________________________________________________________

  7. Leave the vfat floppy mounted. Take a VMware back-up Snapshot now and name it “done_vfat”.

15Mounting & unmounting a CDROM file system

  1. Method A - Virtual CDROM: In the VMware settings for your Fedora VM, under CD/DVD (IDE) under Device Status, select the checkbox beside “Connected”, and in the same window, under “Connection”, select “Use ISO image”. Use the Browse button and navigate to any directory containing *.iso files. Your Fedora 12 DVD file will work. Even Windows *.iso files will work. (You may also find *.iso files in your VMware software directory.) Pick any one of the *.iso files you find. Save the settings.

  2. Method B - Physical CDROM: Use this method if you didn't use the previous method: Connecting the physical CD/DVD drive to Linux through VMware is much like selecting a floppy disk image file. In the VMware settings for your Fedora VM, under CD/DVD (IDE) under Device Status, select the checkbox beside “Connected”, and in the same window, under “Connection”, select “Use a physical drive”, with Device set to Auto Detect” (or try the other setting, too). Save the settings. Now put a data CD-ROM disk in the CDROM drive (e.g. your Fedora disk, or a Windows Install disk). Note: an Audio CD will not work. Use a data disk.

  3. Fedora is a desktop (not a server) O/S and it may “automount” some disks (especially CDROMs) for you. You will need to unmount them before you can mount them manually using shell commands below. Use the mount command to see if the CDROM device /dev/sr0 has been mounted by Fedora and unmount the device if it has been automounted. (Hint: Rather than searching with your eyes in the output of mount for the sr0 device, use a pipeline to search for it. Unmount it if you see it.)

  4. Make sure no CD is mounted on your Fedora desktop before you continue; unmount /dev/sr0

  5. Linux often creates many symbolic links in the /dev directory that point to the sr0 device name. Use a two-command pipeline to show all these symbolic links (more than one) and record the pipeline here (Hint: One command to show everything under /dev piped into a command that finds strings matching the CDROM device name. Always make the computer do your searching work for you!):

    _______________________________________________________________

  6. Verify that Fedora can access your physical CDROM device: fdisk -l device_name
    You should see some warning messages, disk size information, and (possibly invalid) partition information.

  7. Give the output of “file -s device_name” for the device name of the CDROM. (If the output says "writable, no read permission", you forgot to "Connect" the CDROM to the virtual machine.)

    _______________________________________________________________

  8. Mount the CDROM file system (using any of its device names) on the directory /mnt/cdrom after creating it. Record the command used:

    _______________________________________________________________

    You will see a warning message: is write-protected, mounting read-only

  9. Use mount without any arguments to verify that you have a new file system mounted from the CDROM device and copy the single line of output related to the only CDROM device here:

    _______________________________________________________________

  10. Try (as root) to copy a file to the CDROM: cp -a /etc/passwd /mnt/cdrom/passwd

    and record the error message here (you cannot write on a read-only CDROM disk!):

    _______________________________________________________________

  11. Leave the CDROM mounted. Take a VMware back-up Snapshot now and name it “done_cdrom”.

Lab Check and Upload

Follow the posted instructions on-line in Assignment #12 for checking your work and uploading a mark to Blackboard by the given due date:


http://teaching.idallen.com/cst8207/13w/notes/assignment12.html


1Command: eject device_name

The eject command will unmount a given CDROM file system if its mounted, and eject (disconnect) the media from the drive. On our Fedora systems, the default device is the cdrom device, so just “eject” with no arguments (with no device name) will also work.

2Ejecting and unmounting everything

After marking your assignment using the above check program, give the command lines to do these operations (and do them!):

  1. Eject the CDROM. ____________________________________

  2. Unmount the VFAT file system. ___________________________

  3. Unmount the NTFS file system. ___________________________

  4. Unmount the EXT4 file system. ___________________________

  5. Unmount the EXT3 file system. ___________________________

3Practice these commands

Go back to your earlier snapshots and REPEAT these exercises as often as necessary, until you can do this without looking at the lab instructions. Without looking at the instructions, can you do the following:


Can you do all the above operations without reference to any help files? Practice! A job interview may ask you to partition a disk and install Linux. Try to look like you know what you are doing!

Page 10 of 10

©2012 Algonquin College

Shawn Unger, Todd Kelley, Ian Allen

worksheet12.odt

Version 14 04/05/2013, 01:46:38