- Chapter 3 Linux Filesystem
- The Linux Filesystem
- Filesystem Organization
- Keeping Your Disks Healthy
- Summary
The Linux Filesystem
The Linux filesystem organizes files and directories into a hierarchical structure. A filesystem provides a way to store files that can be randomly accessed, including hard disk partitions, floppy disks, and CD-ROMs. Because tape drives are accessed sequentially, they do not contain a true filesystem. Some of the common filesystems, not all of which are Linux filesystems, are
Extended Filesystemext (Linux, has been replaced by ext2)
Fast Filesystemffs (Amiga)
HPFS Filesystemhpfs (used with the OS/2 operating system; supported in real-mode only)
ISO9660 Filesystemiso9660 (CD-ROM)
Linux Swap Filesystemswap
Minix Filesystemminix (Minix; this was the first filesystem used for Linux)
MS-DOS FilesystemFAT16 msdos (DOS)
Network File Systemnfs (Data is stored on any machine on a network and access is granted via the network)
Novell FilesystemNCPFS (Novell servers)
NT FilesystemNTFS (Windows NT)
proc Filesystemproc (Virtual filesystem used by the Linux kernel to provide information to the user about processes)
Second Extended Filesystemext2 (Linux standard filesystem)
System V Filesystemsysc (System V variants; commercial UNIX systems for PCs)
Uniform Filesystemufs (Used by BSD, SunOS, and NeXTstep; is supported in read-only mode)
UMSDOS Filesystemumsdos (UNIX on MS-DOS; applied on top of a FAT16 filesystem to provide Linux functionality by creating special files; is slow)
Virtual FAT FilesystemVFAT (an extension of the FAT filesystem to support long filenames)
Xenix Filesystemxenix
Xia Filesystemxiafs (An old filesystem; hardly used anymore)
Within the Linux filesystem, the partition or hard drive you are accessing is invisible. Instead, each partition or hard drive is shown relative to the root of the filesystem. The root is represented as /.
If you have the following partitions
|
|
|
|
|
|
|
|
and issue an ls / command, the directory listing will appear and the /var and /home filesystems will show up as subdirectories residing with the / directory, even though they are located on different partitions.
Formatting
Now that you have created your partitions, you must create a filesystem on each one before you can install Linux. Creating a filesystem on your hard disk is similar to formatting a floppy. You create a filesystem by using the mkfs command. Its syntax is
mkfs -t fs-type device blocks
mkfs actually calls another command based on the type of filesystem you specify with the -t fs-type option. The various mkfs commands associated with specific filesystem types are shown in Table 3.3.
Table 3.3 Commands Associated with Specific Filesystem Types Called by the mkfs Utility
Command |
Filesystem Type |
mkfs.ext2 |
Create an ext2 filesystem; same as mke2fs |
mkfs.msdos |
Create an MS-DOS filesystem |
mkfs.minix |
Create a Minix filesystem |
You can use any of these commands instead of using the mkfs utility as a front end.
To create an ext2 filesystem on the first partition from the earlier example, you would issue the following command:
mkfs -t ext2 /dev/hda1 3686759
The notes you took while doing the partitioning are used here because you must provide the mkfs utility with the number of blocks on the partition you are formatting. If you did not note those numbers, you can rerun the fdisk command and display your partition table to find them.
When creating a filesystem, be very careful to ensure the device and block arguments are correct. If you designate the wrong device, you can destroy data on another partition. If you pass the wrong number of blocks, you might actually format part of another partition and destroy any data that is there.
The options you can use with the mkfs utility are listed in Table 3.4.
Table 3.4 Options to Use with the mkfs Command
Option |
Action |
-t fs-type |
Defines the type of filesystem to create |
-v |
Displays all commands used to create the filesystem |
-c |
Checks for bad blocks before creating the filesystem |
-l filename |
Uses the named file as a list of known bad blocks |
You also can use the mkfs command to create a filesystem on a floppy drive; however, the fdformat command is a better choice. It performs a low-level format to create the sector and track information on the floppy. The syntax for the fdformat command is as follows:
fdformat [option] device
You can use the -n option to prevent verification of the format. Floppy devices are usually /dev/fd0 or /dev/fd1.
Key Concept
Before installing Linux, the disk must be prepared. You do this by creating your partitions, activating your swap partition, and designating the filesystem for each partition. After the partitions have been created, they must have a filesystem created by using the format command.