CIS 191B
Lab 7: File Systems
Last modified: Oct. 31, 2011
The purpose of this lab is to explore the structure of the EXT filesystem used throughout most Linux Distributions. We will run commands that allow you to create file systems, configure the superblock, modify inode information,
perform file system checks, and implement disk quotas.
The objective of this lab is to move the home directories of users from the root file system to a separate file system where we can implement disk quotas.
Background
File systems are storage structures that allow the computer system to maintain
the integrity and whereabouts of large numbers of different files in a quick
and secure manner. Regardless of the type of file system, UNIX/Linux file
systems treat files as having three distinct componenets:
- file names - which are kept in special files called directories
- an inode - a block of data that keeps information about the file e.g.
permissions, ownership, size and location of the contents of the file.
- data - the actual contents of the file are stored in blocks of data
that are allocated in clusters ranging from 1K to 32K or more in size. These
clusters do not necessarily have to be contiguous on the hard disk.
Part I: Creating a File system
Typically, file systems are used to format partitions of a hard disk, floppy or CD-ROM.
In this section, we are going to format a logical
partition on the hard disk. (/dev/sda9).
- Boot the system into Maintenance Mode or log on as root and bring the system into maintenance mode with:
init 1
- Use the fdisk command to check the partition structure of your hard disk.
fdisk -l
Create a new 514MB (63 cylinders) logical partition as sda9. After running fdisk be sure
to run the following command to insure the kernel is aware of the new partiion:
partprobe
- Format this partition with an ext2 file system that contains 800 inodes:
mkfs -t ext2 -N 800 /dev/sda9
- Before we mount the file system, lets look at the superblock structure:
dumpe2fs /dev/sda9 | more
Note the following fields:
- Filesystem volume name
- Filesystem features
- Filesystem state
- Inode count
- Block count
- Block size
- Maximum mount count
Do you understand the kind of information that's kept in the Superblock?
- Let's configure some of these fields with some file system commands:
e2label /dev/sda9 /home
tune2fs -c 24 /dev/sda9 # changes maximum mount count
tune2fs -j /dev/sda9 # adds a journal
- Check your modifications using the dumpe2fs command.
Part II: Mounting and Populating a file System
File systems are controlled by device drivers, and therefore are treated as devices.
To make the files within a file system available to users, the file system device must
be mounted to a directory of an already-mounted file system (usually root).
- Now mount your new filesystem:
mount /dev/sda9 /mnt
- Type the mount command and note the file system type of your new file system. Why is it mounted ext3 when it was created as ext2?
- List the current contents of your filesystem by listing the contents of
the /mnt directory. What is there? Anything?
- Note that the mkfs command made a fairly large, but empty, directory called lost+found in your file system. This directory is used by fsck to store recovered files when fixing file system corruption. What is the inode
of the lost+found directory? What is the inode of the mntpoint, (/mnt)?
directory?
ls -ai /mnt
Note: mount point directories are always given inode number 2. (0 and 1 are
reserved and not used as regular inodes.)
- Now populate your new fileystem with all the home directories of your users.
Here is a cool command for doing that, but it requirres that you are in the /mnt directory:
cd /mnt
(cd /home; tar cvf - . ) | tar xvf -
We have just copied all the subdirectories from the root filesystem to your
file system.
- List the contents of your filesystem with inode numbers:
ls -i
- Change directory to / and unmount your file system.
- Check the integrity of your new file system using the following command:
fsck -f /dev/sda9
The -f option forces the check even though the filesystem was unmounted cleanly.
- You can now free up some disk space on your root file system by removing all the home directories under the /home directory.
cd /home; rm -rf *
- Now that /home is an empty directory on the root file system, you can mount
your new /home file system to that directory. You will do this in Part III
Part III: Setting up disk quotas
In this procedure we will setup disk quotas for our users.
Disk quotas are setup on a per file system basis. Quotas may be set for individual user accounts and/or groups. We are going to setup quotas for user accounts in the file system that we just created.
- As root, mount your new file system to the /home mount point with the following command:
mount -o usrquota /dev/sda9 /home
What would you do if you wanted this file system mounted like this everytime you booted the system?
Go ahead and modify the /etc/fstab file with the following line:
LABEL=/home /home ext3 defaults,usrquota 1 2
- Bring the system back up to runlevel 3:
init 3
- Log in as root and change directory to /home. Verify that all your user directories are there.
- Analyze this file system for current disk usage:
quotacheck -cuv /dev/sda9
Notice the datafile that gets created for holding this quota information. What is its name?
Note that the above command produces a warning about the old file not existing; that is ok.
- Now turn on user quotas on with the command:
quotaon -uv /dev/sda9
- On another screen, log in as a regular user and issue the quota command.
What does it say?
- Go back to your root login and setup a quota for this user using the following command:
edquota username
Notice the beautiful user interface! (Don't be fooled by the wrapping of the two lines.) You are in vi, and you can edit the soft and
hard fields in this file. Note they are currently 0. Notice that you can set quotas on disk space (blocks) or on number of files (inodes). You can play with either set of values. Make sure that your quota limits are above the current usage.
- Once you've setup a quota for your user, test it. You can test the disk block quota by growing a large file using the dd command. You
can test the inode limit by touching a large number of filenames.
- You can now copy this quota setup to another user using the setquota command:
setquota -p firstuser seconduser /dev/sda9
Use this command to setup the same quota for frodo. You can also use the
setquota command to set quotas and avoid using vi:
setquota -u glorfindel 80 100 90 100 /dev/sda9
- setquota may also be used to change the grace period from the default of seven days to some other value - see the man page for further details.
To Turn In
Run the program, glab7 until you are satisfied with the results.
Note: the glab7 program checks to see if you made the /home filesystem on the same day as you run the program;
if you rerun the glab7 program a day later, you will be short 1 point. :-(
Save the results by redirecting to a file called lab7 and scp that file
to your opus account:
scp lab7 logname@opus.cabrillo.edu:
If glab7 is not on your lab machine, you may download it from opus where
it resides in the /home/cis191/bin directory.