• Aucun résultat trouvé

automatically Mounting Filesystems at Boot Time

When your Ubuntu system boots, the boot block on your primary disk identifies the filesystem that contains the second-stage boot loader, which uses a configuration file to determine what kernels and associated boot options are available on your system. Older Linux systems used a boot loader called LiLo (Linux Loader), while Ubuntu and most other modern Linux systems use a boot loader called GRUB (Grand Unified Boot Loader).

During the boot process, the root filesystem is initially mounted read-only for standard processes so that its consistency can be verified. Once this is done, it is remounted in read-write mode, and your system verifies the existence and consistency of any other filesystems that it will be using.

The list of filesystems that are available to your system is contained in the file /etc/fstab (File System Table).

Each line in the /etc/fstab file provides information about one of the filesystems that should be available to your system. To add a new filesystem so that it will always be mounted when your system boots, or to customize how your system interacts with a specific type of device, you need only add or customize an entry for that filesystem in the /etc/fstab file. A sample section of the /etc/fstab file on one of my systems looks like the following (this file will be different on your system): The fields in each /etc/fstab entry (i.e., each line) are as follows:

The first field is the device or remote filesystem to be mounted. This is usually the Linux

L L

device file for the partition that is to be mounted, but can also be an entry of the form hostname:directory for networked filesystems such as NFS. Any ext2, ext3, and

ext4 filesystems can also be identified by the name that they were assigned in the file-system volume label when the filefile-system was created. For example, the entry LABEL=/

in the example /etc/fstab file could be replaced with /dev/sda1 because that is the disk partition where my root filesystem actually lives. However, using labels is more flexible than using specific partition device files because the device file associated with a specific partition may change if the disk containing that partition is moved to another system or if other disks are added to an existing system.

The second field is the directory upon which the specified filesystem should be

L L

mounted. For special types of partitions that should not be mounted, such as swap par-titions, this field should contain the entry none.

The third field identifies the type of filesystem. Common entries in this field are

L

L ext2

(the generic Linux local filesystem type), ext3 (the journaling version of ext2), ext4 (an improved, higher-performance, and high-capacity version of ext3), vfat (a 32-bit Windows FAT partition), iso9660 (the standard CD-ROM filesystem), nfs (networked filesystems using Sun’s NFS protocol), and swap (swap space). If a filesystem is not cur-rently used but you want to keep an entry for it in /etc/fstab, you can put the word ignore in this field, and that filesystem will not be mounted, checked for consistency, and so on.

The types of filesystems that are compiled into your kernel are listed in the file /proc/

filesystems, but this can be misleading. Your kernel usually also supports other types of filesystems, but as loadable kernel modules rather than being hardwired into the kernel. For example, the /proc/filesystems file on my main system contains the following entries:

fuseblk

Filesystems whose types are prefaced by a

L

L nodev entry are not associated with physical devices, but are used internally by applications and the operating system.

The fourth field contains a comma-separated list of any options to the

L

L mount

com-mand that should be used when the filesystem is mounted. Many mount options are filesystem-specific, but some common ones are the following:

async L

L : Writes to the filesystem should be done asynchronously.

auto L

L : The filesystem should be automatically mounted when detected or when a command such as mount-a is executed.

defaults

L : The character or block device containing the filesystem is local to the system.

exec L

L : You can execute programs, scripts, or anything else whose permissions indi-cate that it is executable — from that filesystem.

gid=value L

L : Set the group ID of the mounted filesystem to the specified numeric group ID when the filesystem is mounted.

noatime L

L : Do not update file timestamps in the inode for a file when the file is simply being accessed. Not updating this timestamp can provide significant performance improvements.

noauto L

L : Don’t automatically mount when a filesystem is detected or when the com-mand mount-a is issued. Usually used with removable media such as floppies and CD-ROMs.

nouser L

L : You must be root to mount the filesystem — the filesystem can’t be mounted by any non-root user.

owner L

L : The ownership of the filesystem is set to the user who mounted it — usually root if the filesystem is automatically mounted by the system.

ro L

L : Mount the filesystem read-only.

rw L

L : Mount the filesystem read-write.

suid L

L : Allow programs on the filesystem to change the user’s user or group ID when they are executed if their permission bits indicate that they should do this. Be very careful when using this option with imported filesystems that you don’t actually

administer because running a program that sets the UID to root is a common way of hacking into a system.

uid=value L

L : Set the user ID of the mounted filesystem to the specified numeric user ID when the filesystem is mounted.

For more information on generic options available to the mount command, see the man page for the mount command in Section 8 of the online Linux manual (by using the man8mount command).

The fifth field is used by the

L

L dump command, a standard Linux/UNIX filesystem backup

command, to identify filesystems that should be backed up when the dump command is executed. If the fifth field contains a 0 (or is missing), the dump command assumes that the filesystem associated with that /etc/fstab entry does not need to be backed up.

The sixth field is used by the Linux/UNIX filesystem consistency checker discussed

ear-L L

lier in this chapter in the section entitled “Local Filesystems: Standard and Journaling.”) to identify filesystems whose consistency should be verified when the system is rebooted, and the order in which the consistency of those filesystems should be checked. If the sixth field contains a 0 (or is missing), the fsck program assumes that the filesystem associated with that /etc/fstab entry does not need to be checked.

The contents of this file may seem complex at first, but over time you’ll get used to creating and editing them. Many of the graphical utilities provided for manipulating disk partitions automati-cally create these entries for you — or you can always do what I do, which is to copy an existing, but similar, entry and then modify it as needed for the partition(s) I’m adding.

automatically Mounting removable