========================================================== Assignment #07 - hard links, disk usage, Fedora Install ========================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Read *all* the words in this assignment before you begin to type. Available online: Sunday October 21, 2012 CLS: "Course Linux Server" Goals: Understanding and working with hard links, du, and quotas. Install of Fedora 12 into a virtual machine. Deliverables and due date: DUE: 6pm on Sunday November 4, 2012 1. Upload the assignment07.txt file. 2. Create the correct files on the CLS under assignment07 3. Demonstrate a correct Fedora 12 install using Worksheet #7. Late assignments or wrong file names may not be marked. Be accurate. File Submission method: The upload file must have the *exact* name: assignment07.txt Upload the file via the assignment07 "Upload Assignment" facility in Blackboard in a manner similar to how you submitted the previous assignments (but upload under assignment07). Be exact! WARNING: Some inattentive students upload Assignment #07 into the Assignment #6 upload area. Don't make that mistake! Be exact. ============================================================================== Part A - Worksheet - not for hand in ================== Part A1 - disk usage (du) ========================= The "du" command counts the number of disk blocks used in files, and does it recursively for directories. You can turn off directory recursion using the "-s" option to du, and then du will show you only the sum total of disk blocks in that directory (including disk usage in all subdirectories underneath it). The sizes of the directories themselves (in disk blocks) are included in the directory totals: $ rm -rf new $ mkdir new $ du new 4 new $ date >new/foo $ du new 8 new $ date >new/bar $ du new 12 new $ mkdir new/dir $ du new 4 new/dir 16 new $ du -s new 16 new $ date >new/dir/foo $ du new 8 new/dir 20 new $ du -s new 20 new $ rm -r new/* $ du new 4 new Note that even an empty directory takes up some disk space, and some file systems allocate a minimum number of disk blocks for any non-empty file or directory (e.g. 4 blocks, above). We will assume a minimum of 4 blocks per non-empty file or directory. (An *empty* file, such as created by "touch", takes *no* disk space.) Given these supposedly successful commands and output: $ rm -rf new $ mkdir new $ cp file1 file2 file3 new $ du -s new 132 new QUESTION: If I removed *all* the files under "new", how much disk space would I free up? (This is the same as asking: How many disk blocks are used by all the files under "new"? You must not include the disk space used by the directory itself. Only count the file space.) ANSWER: The total disk space used in "new" (including the directory itself) is 132 blocks. We know 4 blocks are used for the directory itself, leaving 132-4=128 blocks for the all the files inside "new". 128 blocks would be freed up by removing all the files under "new". Part A2 - disk usage (du), quotas, and linked files =================================================== The "quota" command shows your disk quota, in disk blocks, if enabled. A quota is a limit on how much disk space you can use on the system. (Quotas are enabled on the CLS as of October 19.) Linked files (files with multiple names) don't take up extra disk blocks or inodes, and so they don't affect the output of "du" or "quota": $ rm -rf new $ mkdir new $ date >new/foo $ du new ; quota 8 new Disk quotas for user cst8207a (uid 1002): Filesystem blocks quota limit grace files quota limit grace home 780 204800 512000 193 0 0 $ ln new/foo new/bar $ ln new/bar new/abc $ ls -i new 3138961 abc 3138961 bar 3138961 foo $ du new ; quota 8 new Disk quotas for user cst8207a (uid 1002): Filesystem blocks quota limit grace files quota limit grace home 780 204800 512000 193 0 0 $ ls -dils new/* 3138961 4 -rw-r--r-- 3 idallen idallen 29 Oct 21 13:28 new/abc 3138961 4 -rw-r--r-- 3 idallen idallen 29 Oct 21 13:28 new/bar 3138961 4 -rw-r--r-- 3 idallen idallen 29 Oct 21 13:28 new/foo Since foo, bar, and abc are all names for the same disk blocks and the same inode, "du" and "quota" count the disk space and inode only once. To free up disk space, all three names for inode 3138961 must be removed. Only then will "du" and "quota" show a reduction in space. Part A3 - finding linked files ============================== Files with multiple names have the same inode numbers but those multiple names may appear in any directory anywhere in the disk partition. You can use "find" and "sort" to make inode numbers sort together on your screen, to make finding duplicates easier: $ rm -rf new $ mkdir new new/bar $ touch new/a new/b new/c $ ln new/a new/bar/a $ ln new/b new/bar/b $ ln new/c new/bar/c $ find new -type f -ls 3138990 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/c 3138989 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/b 3138988 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/a 3138990 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/c 3138989 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/b 3138988 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/a Above, the files with the same inode number do not appear together in the output. It is hard to notice that new/c and new/bar/c have the same inode numbers and so must be the same file. The solution is to sort the output of "find" by inode number: $ find new -type f -ls | sort 3138988 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/a 3138988 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/a 3138989 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/b 3138989 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/b 3138990 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/bar/c 3138990 0 -rw-r--r-- 2 idallen idallen 0 Oct 21 13:47 new/c Now, inode numbers sort together and it is easy to see the duplicate inode numbers and know which files are hard links to each other. You can also use an option to "find" to find files by inode number. Part B - hard link assignment (for hand in) =========================================== You must understand hard links to do this part. See the Class Notes and Part A, above. B0. Execute this exact command line in your account on the CLS: $ ~idallen/cst8207/12f/assignment07/createB.sh There is a leading tilde character in front of "idallen". The command script will create a directory named "assignment07/b" in your HOME directory. It will contain some sub-directories and files. You can remove the "assignment07/b" directory and re-execute the above line to start over from scratch, if you make errors in Part B of this assignment. You will need to redo all of Part B. Your job is to remove all the files in a directory and reduce the disk space used. Recall that the "rm" command does not remove files; it only removes names. Your job is to remove the *files*, to make more disk space, which means you need to find and remove *all* the names for the files. The other names for your files will be restricted to the "assignment07/b" directory, so you don't have to search the whole disk partition to find them all. There are three levels of difficulty. Do the easy one first. Come back and do the harder ones if you have time. B1. The first level of difficulty is "easy". There is a directory named "b/easy" under assignment07. This easy subdirectory contains 236 blocks (recursive total for everything) and a "foo" subdirectory that contains 84 blocks of those 236 blocks. $ cd assignment07/b/easy $ du -s . 236 . $ du -s foo 84 foo Read this section all the way through before you delete anything. YOUR JOB: Remove all the files in the foo subdirectory (but keep the directory), so that the total disk use in the "easy" directory drops to 236-80=156 blocks. Don't try to do this until you've read this whole section through, including the Hints below. Hints: Some of the files in the foo subdirectory have more than one name. Those other names are located somewhere else under easy. The disk blocks for these files in foo will not be freed until you find and remove *all* their names. Do not remove any names from foo until you also know how to find and remove the other names for these files. If you succeed in the "easy" directory you will see this: $ du -s . ; du -s foo ; find . | wc 156 . 4 foo 39 39 335 If you make a mistake, you can recursively remove the "b" directory and recreate it using step B0 above. You will need to redo all of Part B. B2. The next level of difficulty is "medium". (Save this for later.) There are two hidden directory under assignment07/b. The name of the first one contains the string "hard1". This hard1 subdirectory contains 368 disk blocks (recursive total for everything) and a "foo" subdirectory that contains 132 of those 368 blocks. YOUR JOB: Remove all the files in the foo subdirectory (but keep the directory), so that the total disk use in the hard1 directory drops to 368-128=240 blocks. Hints: See the previous question for hints on finding all the file names. If you succeed in the hard1 directory you will see this: $ du -s . ; du -s foo ; find . | wc 240 . 4 foo 60 60 590 If you make a mistake, you can recursively remove the "b" directory and recreate it using step B0 above. You will need to redo all of Part B. B3. The next level of difficulty is "hard". (Save this for later.) There are two hidden directory under assignment07/b. The name of the second one contains the string "hard2". This hard2 subdirectory contains 304 disk blocks (recursive total for everything) and a "foo" subdirectory that contains 132 of those 304 disk blocks. YOUR JOB: Remove all the files in the foo subdirectory (but keep the directory), so that the total disk use in the hard2 directory drops to 304-128=176 blocks. Hints: You will need to look at inode numbers to know which files in directory foo are also named in the other directories under "hard2". The "sort" command will be useful in a pipeline. (See Part A3, above.) An option to "ls" to display nongraphic (unprintable) characters will be needed. Many file names will need to be quoted to protect shell metacharacters. See the previous question for the other hints. If you succeed in the hard2 directory you will see this: $ du -s . ; du -s foo ; find . | wc 176 . 4 foo 60 165 710 If you make a mistake, you can recursively remove the "b" directory and recreate it using step B0 above. You will need to redo all of Part B. Part C - Fedora 12 install ============================= Do Worksheet 7 - Fedora 12 Install - and have your work checked by your instructor in your lab this week (Week 8). (See the last page of the worksheet for the check points.) You need a running Fedora 12 installation in a virtual machine to do the next labs in this course. Don't forget your Fedora 12 root password! Part Z - submission =================== Z1. Create a listing of all your work for this assignment: Run "find assignment07 -ls" to show your results and redirect the output into your own file "assignment07/assignment07.txt" on the CLS. Z2. Transfer the above assignment07.txt file from the CLS to your local computer and verify its contents. (No empty files, please!) Z3. Submit the assignment07.txt file with the exact name before the due date. Z4. Your instructor will mark the assignment07 directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete anything until after the term is over. READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS! -- | 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/