The UNIX File System
Structure of the File System
- Boot block
- Super block
- Inode list
- Data block
File System creation and maintenance
- Disk formatting
- Creating a File System
- Mounting and dismounting a File System
- File system Integrity Check
- Hands On Session
Objectives
After studying this article, the students should be able to:
- Understand the UNIX file system
- Understand the Creation and maintenance of the file system
- Understand the mounting and dismounting of file systems
UNIX File System
- The physical disk is segmented into logical partitions
- Each partition houses a file system
- Related files are grouped into a file system
- Standard partitions: boot root swap users and others
- Each partition is divided into small units called blocks
- Block size may vary across partitions
- Allocation of blocks is done whenever necessary
Structure of the UNIX File System
- Boot Block : block 0
- Super Block : block 1
- Inode List : block 2
- Data Block : block 3 onwards
The first block or the 0th block of any file system is the boot block. The bootstrap program is present only in the boot block of the root file system.
The information available in the super block is:
- The name of the file system.
- The size of the file system.
- The number of free blocks available in the file system.
- A list of all the free blocks.
- Index to the next free block in the free block list.
- The size of the Inode list, which specifies the number of files that can be allocated.
- The number of free Inodes.
- The index to the next free Inode in the Inode list.
- A flag indicating that the super block has been modified.
- A lock field for the free blocks and free Inodes.
File System Creation and Maintenance
- File system types : s5, bfs, ufs
- Disk formatting : format
- Creating a file system : mkfs -F [blocks] [if] [cylinders]
- Mounting a file system : mount -F
- Dismounting file system : umount
- Integrity check : fsck
Disk Formatting
File systems can be created in fixed disks or hard disks and on removable media like tapes or floppies. Before any file system can be created on these media, these require to be formatted. The command available for this is the format command.
The simple form of format is : format
The device-file-name is one of the names associated with the devices present in the /dev directory. For example, the floppy drive may be rfd096ds15, which represents:
- r raw or character device file
- fd floppy drive
- 0 first drive, 1 as second and so on
- 96 number of tracks
- ds double sided
- 15 number of tracks/sectors per inch
Creating a file system
Once the device is formatted, a file system can be created on it. The mkfs command is used to create a file system.
For example, the command
$ mkfs -F s5 /dev/diskette 1422 1 18
will create a standard s5 file system on the floppy. The different parameters are:
/dev/diskette the name of the first floppy drive
1422 the number of disk blocks ( this depends on the choice of the user)
1 is the interleave factor for the floppy drive
18 the number of cylinders of a floppy drive
The mkfs command may produce the output as:
bytes per logical block = 1024
total logical blocks = 711
total Inodes = 176
gap (physical blocks) = 1
cylinder size (physical blocks) = 18
mkfs: Available blocks = 701
The number of physical blocks are translated into the logical blocks ( 711 in this case). The number of Inodes are approximately the number of logical blocks divided by 4. The default gap is one and the number of cylinders are 18. These figures may vary for different types of floppy disks and UNIX installations.
Mounting and Dismounting the file system
Once the device ( in this case, the floppy) is formatted and a file system is created, it can be used to store files of the UNIX system. However, the drive on which the file system was created will not be accessible by the UNIX system unless it is mounted.
Mounting a file system means assigning the root directory of the new file system to a sub directory of the root directory. After this, the new file system is accessible to the user as a sub directory of the root ( or any other directory under the root). The user cannot distinguish a file system once it is mounted.
To mount a file system the mount command is used. For example, to mount a file system created in a floppy diskette to the /mnt directory of root, the command line format is:
$ mount -F s5 /dev/diskette1 /mnt
After changing the current directory to the /mnt directory, new files can be created or existing files can be accessed from the new file system now mounted under /mnt subdirectory. The directory to which a file system is to be attached has to be otherwise empty.
The information about the mounted file systems is available in the file /etc/mnttab and the /etc/vfstab files.
The entries in the file /etc/vfstab file contains the details of the file systems to be mounted automatically at the time of booting the UNIX system. The /etc/mnttab file holds the information about the file systems that are currently mounted and their mount points on the system.
The file system needsto be dismounted after use. This cannot be done if the file system is busy. The floppy containing the file system can be removed only after the file system has been dismounted. Once the file system is dismounted, the files under the dismounted file system can not be accessed.
The command umount is used to dismount the file system:
$ umount
The device file names on which the file systems were mounted can be obtained by issuing the mount command without any parameters.
- Before the UNIX system is shut down all the file systems, except the root file system, need to be dismounted.
- File system integrity check
- The UNIX file system if not properly shutdown, i.e., if the shutdown process is not carried out, can easily become corrupted.
- As discussed earlier, a copy of the super block is maintained in the RAM, where all the updations are done. The disk copy of the super block is updated only at periodic intervals. If the system gets halted before the memory copy of super block gets written to the disk copy, it can lead to inconsistencies. This involves the file system size, Inode list, free block count and free Inode count.
- Therefore, it is required to check for the inconsistencies of the file system before they can be mounted. This is done through the fcsk ( file system check ) command.
This command is automatically executed during the booting process. It can also be given at the prompt. It is an interactive, multipass file system check and repair program.
Each pass of fsck invokes a different phase, which:
- Checks the file system size
- Checks path names
- Checks the connectivity
- Checks the reference count
- Checks the free block list
- Salvages the free block list