When introducing a new hard disk partition into a Linux system, the user would, of course, want it to be automatically mounted at startup and unmounted at shutdown. Otherwise, this section will have to be explicitly mounted and unmounted at every boot and every shutdown of the system. In order for the OS / Linux to automatically mount the file system that exists in the new hard disk partition, you need to add its name to the fstab file. This can be done manually or with the fstool command. The fstab file is located in the / etc directory. It lists the filesystems that are mounted with the mount command with the -a option. This command is located in the /etc/rc.d/rc.boot file. The commands in this file perform operations to initialize the system. They are executed every time the system boots. When the system is shut down, the umount -a command is executed, which unmounts all file systems listed in the fstab file. The umount -a command is located in the /etc/rc.d/init/halt file, which contains the commands that are executed whenever the system is shutdown. This way, all filesystems that you specify in the / etc / fstab file are automatically mounted on system startup and unmounted on system shutdown. On other systems, such as Redhat, the mount -a command can be found in the /etc/rc.d/rc.sysinit file.
The fstab file element contains multiple fields, separated by spaces or tabs. The first field is the name of the filesystem to be mounted. It usually starts with / dev, for example / dev / hda3, the third partition on the hard drive. The next field is the directory in the file structure to which you want to attach the file system on this device. The third field is the type of filesystem to be mounted. The hard disk partition type for the standard Linux file system is ext2. The following example shows the fstab file line corresponding to the primary hard disk partition for Linux. It is mounted in the root directory (/) and is of type ext2.
/dev/hda3 / ext2 defaults 0 1
The field following the file system type specifies the various mount options. There is a standard set of default options; all of them can be set by entering one option defaults / Other options in the list are separated by commas (no spaces). The deffaults option designates the device as a read / write device, asynchronous, block-oriented, not mountable for ordinary users, with the ability to run programs on it. For CD-ROMs, only two options are specified, go and noauto. The go option indicates that the files on this device are read-only, noauto – that it is not automatically mounted. The noauto option is used for both CD-ROMs and floppy disks so that they are not automatically mounted since you don’t know if they will be installed at startup. At the same time, the entries of the file in question, relating to both CD-ROMs and floppies, indicate in which directory they will be mounted at startup, if you nevertheless decide to mount them. Below is an example of recordings for CD-ROMs and floppy disks. The file system type on the CD-ROM, iso9660, is different from the hard disk partition type. The floppy drive also provides all the standard options used for hard disk partitions.
/dev/fd0 /mnt/floppy ext2 defaults,noauto 0 0 /dev/hdc /mnt/cdrom iso9660 ro,noauto 0 0
The last two fields contain integer values. The first is used by the dump command to determine the frequency of file system backups. The latter is used by the fsck command to determine if a system check is necessary and the order of possible checks. If the field value is 1, then this is the root section. The value indicates that you do not need to check the file system at boot.
Below is a copy of the / etc / fstab. Its first line is a comment. All comment lines start with a # sign. The / proc file system is a special file system that the Linux operating system uses to manage system processes. It does not correspond to any real device.
/ etc / fstab
|_____________________________________________________________________________________ | # device mountpoint filesystemtype options dumpm fsckorder| | /dev/hda3 / ext2 defaults 0 1 | | /dev/hdc /mnt/cdrom iso9660 ro,noauto 0 0 | | /dev/fd0 /mnt/floppy ext2 defaults,noauto 0 0 | | /proc /proc proc defaults | | /dev/hda2 /none swap sw | | /dev/hda1 /mnt/dos msdos defaults 0 0 | | /dev/hda4 /mnt/win vfat iocharset=koi8-r,codepage=866,rw,noexec 0 0 | |____________________________________________________________________________________|
To specify a new file system in / etc / fstab, you can either edit it manually or use the fstool utility, which prompts you for the appropriate information.
As mentioned above, partitions used by the MS-DOS operating system can be mounted in the Linux file structure. This is done in the same way as when mounting any Linux file system. You just need to specify the type of section – msdos. It will probably be more convenient if the system automatically mounts MS-DOS partitions when Linux starts up. To do this, enter an entry in the / etc / fstab file for each MS-DOS partition to be mounted. Specify the device name for the partition and the name of the directory where it should be mounted. The logical choice is the / mnt / dos directory (make sure the dos directory in / mnt is already created). Enter msdos for the file system type. The following example shows a standard / etc / fstab file line for an MS-DOS partition. Note that this entry is the last entry in the above / etc / fstab file.
/dev/hda1 /mnt/dos msdos defaults 0 0
A section that has an entry in / etc / fstab can only be mounted in the directory specified by that entry. You do not need to enter a device file name. Mount will find the entry corresponding to this section in the fstab file (by directory name) and thus determine the device name. For example, to unmount the DOS partition / dev / hda1 in the previous example, the mount command only needs to specify the directory in which it is mounted. In this case, it is / mnt / dos.
# umount /mnt/dos
If the / etc / fstab file is corrupted – say you accidentally delete or change a line – the system will boot into maintenance mode and give you read-only access to the partitions. To get read / write access and fix the fstab file, you need to remount the main partition. This operation is performed by the following command:
# mount -n -0 remount,ro /
The / etc / fstab file shown here as an example can be used as a guide for generating entries. The elements corresponding to the / proc and swap sections are especially important.