Difference between revisions of "OPS235 Lab 1 - Fedora17"

From CDOT Wiki
Jump to: navigation, search
(Instructions)
(Investigation 1: How does Linux enable you to access two different drives without using a drive designator?)
Line 47: Line 47:
 
#* <code>/dev/sdb1</code> tells the mount command which device to mount. (If this didn't work try <code>/dev/sdc1</code> or <code>/dev/sda1</code>)
 
#* <code>/dev/sdb1</code> tells the mount command which device to mount. (If this didn't work try <code>/dev/sdc1</code> or <code>/dev/sda1</code>)
 
#* <code>/media/usb</code> tells the mount command where to mount the device (the "mount point")
 
#* <code>/media/usb</code> tells the mount command where to mount the device (the "mount point")
# Type the command mount and compare the output with the output from step 9. Record what has changed.
+
# Type the command mount and compare the output with the output from step 1. Record what has changed.
 
# What file system type is the USB device mounted as? Where was it mounted? What is the device name?
 
# What file system type is the USB device mounted as? Where was it mounted? What is the device name?
 
# Create a file in the directory /media/usb/ by redirecing the output of the cal command: cal >/media/usb/month
 
# Create a file in the directory /media/usb/ by redirecing the output of the cal command: cal >/media/usb/month
 
# Display a detailed listing of the directory where the device is mounted and record the output: ls -l /media/usb
 
# Display a detailed listing of the directory where the device is mounted and record the output: ls -l /media/usb
# Type the command umount /media/usb -- What happened to the contents of the /media/usb directory? Compare results with step 17.
+
# Type the command umount /media/usb -- What happened to the contents of the /media/usb directory? Compare results with step 9.
# Type the command mount and observe the output. What is different from step 14? Why?
+
# Type the command mount and observe the output. What is different from step 6? Why?
 
# Make a new mount point called /media/usb2 Mount your usb flash drive on the new mount point.
 
# Make a new mount point called /media/usb2 Mount your usb flash drive on the new mount point.
 
# Display a detailed listing of the new mount point again. Is your file there?
 
# Display a detailed listing of the new mount point again. Is your file there?

Revision as of 11:55, 13 January 2010

Using Linux to Access Block Devices and Filesystems

Objectives

  • Format, mount, use, and unmount ext3, ext4, and vfat filesystems on USB flash drives.
  • Create filesystems on various storage devices
  • Create hard disk partitions
  • Backup filesystems and images
  • Mount a filesystem stored within a a regular file

Reference

  • man pages for cp, mount, umount, fdisk, mkdir, file, mkfs, dumpe2fs, grep, dd
  • Online reading material for weeks 1 and 2.

Required materials

  • Fedora 12 Live CD
  • USB flash drive, 64 MB or more in size (Warning: the contents of this drive will be erased)
  • One SATA hard disk in a removable drive tray (minimum 80GB)

Instructions

  1. Set your computer's drive selector switch to external, then power up the computer.
  2. Insert the Fedora Live CD into the CD/DVD drive.
  3. Reboot the system.
  4. The boot process is completed when you see the GDM Login Screen. Click on "Automatic Login" to login as the "Live System User".
  5. We are going to start by opening a terminal window to access our shell environment. Click on Applications --> System Tools --> Terminal to start the terminal.
  6. At the top of the terminal window, you should see the command prompt similar to [liveuser@localhost ~]$ This prompt indicates that it is ready to take your command. The program that is running is called a shell.
  7. At the command prompt, enter the command whoami (all in one word) and press return. This command shows the so-called User Name. Make notes of this user name.
  8. At the command prompt, enter the command pwd and press return. This command shows the so-called present working directory or current working directory. Record the present working directory of the shell running on the terminal window. As we have not yet changed directories this should also be your users home directory. (Also indicated by the ~ character in the prompt)
Important.png
Using Superuser Privilege
Throughout this course, you may need to execute commands using the privileges of the the administrative user (username "root", also called the "superuser"). To switch from your account to the root account, type the command: su -

After switching user notice and make note of the change in your shell prompt. Also note the difference in output for the whoami and pwd commands.

Whenever this is required, make a note of it, and determine why superuser privilege is required.

When you are finished using the root account type exit to return to your previous account. Avoid using the superuser account unless absolutely necessary, because the superuser account has unlimited privilege and a typo can destroy your system.

Note.png
Disabling the Auto-mounting of Devices
At this point we need to disable the ability for our linux system to automatically detect and mount removeable media. This would interfere with the learning objectives of the rest of the lab. To do this enter the command: killall devkit-disks-daemon. You will need to do this again if you reboot during this lab.

Investigation 1: How does Linux enable you to access two different drives without using a drive designator?

  1. Type the command mount. Describe the output of the command in your lab log. What do the fields of data represent? Use the man page for the mount command and google searches to find this information
  2. Insert your USB flash drive into a USB port on the computer.
  3. Because we have turned off the automatic mounting feature nothing will happen. In order to access the file system on this storage device we must mount it on to our existing file/directory structure.
  4. To mount a device we must first create a mount point to mount it on. Create a new directory called /media/usb (These steps should be done as "root")
  5. Next we need to use the mount command to mount the device. Try typing the following command: mount -t vfat /dev/sdb1 /media/usb. This command contains 3 important pieces of information (command arguments):
    • -t vfat tells the mount command to mount it as a FAT filesystem. (Most likely choice for a USB flash drive)
    • /dev/sdb1 tells the mount command which device to mount. (If this didn't work try /dev/sdc1 or /dev/sda1)
    • /media/usb tells the mount command where to mount the device (the "mount point")
  6. Type the command mount and compare the output with the output from step 1. Record what has changed.
  7. What file system type is the USB device mounted as? Where was it mounted? What is the device name?
  8. Create a file in the directory /media/usb/ by redirecing the output of the cal command: cal >/media/usb/month
  9. Display a detailed listing of the directory where the device is mounted and record the output: ls -l /media/usb
  10. Type the command umount /media/usb -- What happened to the contents of the /media/usb directory? Compare results with step 9.
  11. Type the command mount and observe the output. What is different from step 6? Why?
  12. Make a new mount point called /media/usb2 Mount your usb flash drive on the new mount point.
  13. Display a detailed listing of the new mount point again. Is your file there?

Answer the Investigation 1 question: How does Linux enable you to access two different drives without using a drive designator? (Write the answer in your lab log book).

Investigation 2: How do you create a vfat or ext3 filesystem?

Idea.png
Flash drives with no partition table
If your device name ends in a letter (for example, it is /dev/sdb instead of /dev/sdb1), add -I to the mkfs commands in this section. This is because your USB flash drive does not have a partition table, which normally causes an error; the -I option tells mkfs to proceed anyways.
  1. Unmount your USB flash drive.
  2. Enter the command: mkfs -t ext3 /dev/sdb1
    • What is the purpose of this command? Use the man page for mkfs to research what you did with this command.
    • Did we execute the command on the device name or the mount point?
  3. Attempt to mount the USB flash drive using the command you used in Investigation 1. What was the result?
  4. Check the man page for the mount command to see how to change your command to mount the device correctly, and issue that command.
  5. Once the device is mounted do a long directory listing of the mount point. What has changed?
  6. Do an internet search to find out what the lost+found directory is for. Record your findings in your notes.
  7. Create a new file on the device using the same technique used in Investigation 1.
  8. Unmount the device and remount it on the original mount point. Is the new file there?
  9. Type the command mount and observe the type value for the USB flash drive filesystem. Compare this value to the type found in Investigation 1.
  10. Change your current working directory to where the device is mounted.
  11. Attempt to unmount the USB flash drive. What was the result? Why? Record your findings in your notes.
  12. Solve the error and unmount the device.
  13. Consult the man pages for mkfs and mkfs.ext3 to see how to reformat the device to a ext3 file system with a volume label that is the same as your learn ID.
  14. Enter the command to reformat the device.
  15. The dumpe2fs /dev/sdb1 command will allow us to see detailed information about ext3 filesystems. Use it to confirm your volume label is correct and record the size of your journal.
  16. Mount the device again as an ext3 filesystem.
  17. While the device is still mounted reformat the device as a vfat filesystem. What error message did you receive? Why? Record your conclusions in your notes.
  18. Unmount the device and format it as vfat.
  19. Now you will investigate what happens when you copy files to the device name rather than the mount point. Issue the command cp /etc/hosts /dev/sdb1
  20. Now mount your device. Was it successful? Try mounting it as ext3. Was it successful? What has happened to the filesystem on the device?
  21. Reformat it as vfat and mount it.
  22. Unmount the device.

Investigation 3: How do you create an ext3 filesystem on a USB flash drive with a volume label?

Idea.png
Tip:
Check the man page for dumpe2fs.
  1. Shutdown your computer. (Under the "System" menu)
  2. Insert your removable SATA hard disk, remove your USB flash drive and restart the computer. (Leave your "Live CD" in the computer)
  3. When the computer has restarted and you have logged in. Insert your USB flash drive into the USB port.
  4. Open a terminal window and run the mount command.
  5. It is quite possible that the device name for your USB flash drive has changed from what you were using previously. Your hardware configuration is different because now you have a hard drive connected. One way to determine what your USB device name is now is to look at the system log. Use the tail command to view the last 20 lines of the file /var/log/messages There should be kernel entries that were generated when you inserted the device.
  6. Create a Linux ext3 filesystem on the USB device, giving it a volume label of "Lab1", and record the following in in your logbook:
    • What is the block size for the new format?
    • How many blocks were created?
    • How often will the new filesystem be automatically checked?
    • What volume label was given to the filesystem?
  7. According to the man page what is the purpose of dumpe2fs?
  8. If you executed dumpe2fs on an MS-DOS filesystem what do you think would be the result?
  9. Mount the USB device onto the mount point /media/lab1
  10. Copy the files /etc/services,/etc/networks to the USB flash drive.

Investigation 4 - How do you create hard disk partitions?

  • Enter the command fdisk -l /dev/sda and describe the output in your log book. The output may be similar to the following:
   Disk /dev/sda: 12.0 GB, 12072517632 bytes
   255 heads, 63 sectors/track, 1467 cylinders
   Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot Start End Blocks Id System
   ...
  • Read and study this reading about how to use the fdisk command before you go on to the next step.
  • Review the man page for the fdisk command.
Stop (medium size).png
Important/warning!
The following operation will erase the contents of your hard disk. If you have any useful data stored on your disk, you must back it up first or use another hard disk that does not contain useful data on it.
  1. Enter the command fdisk /dev/sda to start the hard disk partition program.
  2. At the fdisk command prompt, enter the letter p to print out the current partition table of the hard disk. If there are any partitions, use the d option to delete all of them, starting with the highest partition number first.
  3. At the fdisk command prompt, use the n and t commands to create these three partitions:
                 /dev/sda1 - 300MB (primary, Linux Native)
                 /dev/sda2 - the rest of the hard disk (extended)
                 /dev/sda5 - 300MB (logical, Linux Native) 
  • Use the p option the display the new partition and record it in your log book.
  • Remember to use the w option to write the new partitions information instead of the q option to quit without saving.
  • Logout and restart Fedora.

Answer the Investigation 4 question in your lab log book.

Investigation 5 - How do you create and access a Linux filesystem on a hard disk partition?

  1. After rebooting Fedora, open up a Terminal Window and enter the command fdisk -l /dev/sda to display the hard disk partition table. Verify that you have partitioned your hard disk correctly.
  2. Create a Linux 3rd extended filesystem (ext3) on the 300MB primary partition /dev/sda1
  3. Create the empty directory /mnt/harddisk to serve as a mount point for the partition.
  4. Use the command mount -t ext3 /dev/sda1 /mnt/harddisk to attach the file system you just created to the Fedora Live Linux file system tree.
  5. Copy the files /etc/passwd and /var/log/messages to the mounted partition. Can you do this with a single command?
  6. Unmount the partition.

Answer the Investigation 5 question in your lab log book.

Investigation 6 - How can you save an image of a filesytem?

  1. Your /dev/sda1 partition is formatted with an ext3 filesystem and contains 2 files. You can now create an "image" of that device and duplicate it.
  2. First create an image of the device using the following command:
    • dd if=/dev/sda1 of=sda1.img
  3. The image file you created is a byte by byte duplicate of the original device and all of its contents. You can even mount it as a if it was a real partition.
  4. Make a mount point called /media/sda1-image and mount the image file using the following command:
    • mount -o loop -t ext3 sda1.img /media/sda1-image
    • (The -o loop option is used to mount regular files as if they were real block storage devices.)
  5. List the contents of the mount point. Are your files there?
  6. Copy the file /var/log/boot.log to the mount point.
  7. Unmount the image.

Answer the Investigation 6 question in your lab logbook.

Investigation 7 - How can restore/duplicate an image of a filesystem?

  1. /dev/sda5 was a partition created exactly the same size as /dev/sda1. We should be able to restore the /dev/sda1 image file to it without any loss of data.
  2. Remember that /dev/sda5 was unformatted. Restore the image file by using the dd command:
    • dd if=sda1.img of=/dev/sda5
  3. Now attempt to mount /dev/sda5 onto the mount point /media/harddisk
  4. Were you successful?
  5. Does the partition contain a filesystem?
  6. List the contents of /media/harddisk are all 3 files there?

Answer the Investigation 7 question in your lab logbook.

Investigation 8 - Accessing a compressed file system image

  1. Download | lab1-image.bin and copy that file to your mounted hard disk partition.
  2. To determine the file type of the file lab1-image.bin, enter the command:
    • file lab1-image.bin
  3. Record the output. What was the original name of the uncompressed file?
  4. The file command in the previous step should also report that lab1-image.bin is a gzip compressed data file.
  5. Use the gunzip command to uncompress the file.
  6. You will probably receive an error message when you run the gunzip command. You may need to rename the file before you can uncompress it successfully. See the man pages for additional information if required.
  7. After you have uncompressed the file rename it to the original name reported in step 3.
  8. To determine the file type of the file lab1-image.img, enter the command:
    • file lab1-image.img
  9. Record the output. What type of data does the file contain?
  10. Mount the file system image. The command should be similar to what you used in investigation 6.
  11. Copy the contents of the file system image to your desktop.
  12. To display the specific information about the ext3 file system contained in the file lab1-image.img, enter the command:
    • dumpe2fs lab1-image.img
  13. From the output, find out the volume name and the block count of the ext3 file system.

Conclusion: Not only can we put a Linux file system on a removeable storage device, or a hard disk partition, we can also create a Linux file system on a regular disk file.

Answer the Investigation 8 question in your lab logbook.

Investigation 9 - How do you create a file system in a regular file?

  1. Create an empty file that is exactly 3 MB in size using the following command:
    • dd if=/dev/zero of=/tmp/fstest bs=1k count=3072
  2. How does this command ensure that the file is 3 MB in size?
  3. What is in the file at first?
  4. Create an ext3 filesystem within the newly-created file /tmp/fstest.
  5. Note the warning message/question that appears.
  6. Mount the filesystem (remember to use the loopback option; refer to Investigation 8 if required). Use a mountpoint of your choosing.
  7. Copy the files /etc/services and /etc/protocols to the filesystem mounted in the previous step.
  8. Unmount the filesystem.
  9. Test your filesystem to be sure that the files /etc/services and /etc/protocols were in fact copied into the filesystem within the file named /tmp/fstest.
  10. How much space is left in that filesystem? (Hint: df -h).

Answer the Investigation 9 question in your lab logbook.

Investigation 10 - How can you backup the MBR (Master Boot Record)?

Note.png
Please take note!
A master boot record (MBR), is the 512-byte boot sector that is the first sector of a partitioned hard disk. The MBR is used for the following:
  • Holding a disk's primary partition table.
  • Bootstrapping operating systems after the computer's BIOS passes execution to the MBR.
  • Uniquely identifying individual disk media, with a 32-bit disk signature.
  1. We can duplicate the first 512 bytes of a hard disk using the dd command:
    • dd if=/dev/sda of=mbr.bak bs=512 count=1
  2. Use the command to backup the MBR of your hard disk.
  3. Under what circumstances do you think this will be useful?

Answer the Investigation 10 question in your lab logbook.

Completing the Lab

Important.png
Important!
Arrange evidence of each of the following items on the screen, and then ask your professor or lab monitor to check them:
  1. USB Formatted as ext3 ( )
  2. Volume Label is "LAB1" ( )
  3. USB Mounted on /media/lab-one ( )
  4. Following files on USB services, issue, networks ( )
  5. /dev/sda5 contains 3 files ( )
  6. jpg on Desktop ( )
  7. /tmp/fstest mounted ( )
  8. Instructor satisfied with complete and detailed lab notes ( )

Preparing for the Quizzes

The online readings linked on the course web page contain some useful information about Free and Open Source Software. Use them and Internet searches to answer the following questions to help you prepare for the quizzes:

  1. Who is Linus Torvalds?
  2. Name 3 open source software projects widely used today?
  3. What license agreement does GNU/Linux use?
  4. What are the 4 basic software freedoms that define "Free Software"?
  5. Who makes up the Fedora Community?
  6. Name 4 other significant Linux "Distros"
  7. What command can you use to determine the type of data a file contains?
  8. What are 3 journalled filesystems supported by Linux?
  9. What command will create a Linux ext3 file system on /dev/sdb5, with a volume label called "ops235"?
  10. What is the main function of the fdisk utility?
  11. What command is used to attach the file system on a storage device (e.g. hard disk partition, flash memory card etc) to the file system on a running Linux/UNIX system?
  12. What command is used to detach the file system on a storage medium from the file system on a running Linux/UNIX system?
  13. What type of files are stored in the /dev directory?
  14. Is the dd command used to copy multiple files to another directory?

Useful Information

Hard disk partition names (disk drive is x)

Partition 1 2 3 4 5 6 ...
Type primary, extended primary, extended primary, extended primary, extended logical logical logical
Linux Name /dev/sdx1 /dev/sdx2 /dev/sdx3 /dev/sdx4 /dev/sdx5 /dev/sdx6 /dev/sdx7 -- sdx15