10.2. Creating the /etc/fstab File

The /etc/fstab file is used by some programs to determine where file systems are to be mounted by default, in which order, and which must be checked (for integrity errors) prior to mounting. Create a new file systems table like this:

cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point    type     options             dump  fsck
#                                                                order

/dev/<xxx>     /              <fff>    defaults            1     1
/dev/<yyy>     swap           swap     pri=1               0     0
proc           /proc          proc     nosuid,noexec,nodev 0     0
sysfs          /sys           sysfs    nosuid,noexec,nodev 0     0
devpts         /dev/pts       devpts   gid=5,mode=620      0     0
tmpfs          /run           tmpfs    defaults            0     0
devtmpfs       /dev           devtmpfs mode=0755,nosuid    0     0
tmpfs          /dev/shm       tmpfs    nosuid,nodev        0     0
cgroup2        /sys/fs/cgroup cgroup2  nosuid,noexec,nodev 0     0

# End /etc/fstab
EOF

Replace <xxx>, <yyy>, and <fff> with the values appropriate for the system, for example, sda2, sda5, and ext4. For details on the six fields in this file, see fstab(5).

Filesystems with MS-DOS or Windows origin (i.e. vfat, ntfs, smbfs, cifs, iso9660, udf) need a special option, utf8, in order for non-ASCII characters in file names to be interpreted properly. For non-UTF-8 locales, the value of iocharset should be set to be the same as the character set of the locale, adjusted in such a way that the kernel understands it. This works if the relevant character set definition (found under File systems -> Native Language Support when configuring the kernel) has been compiled into the kernel or built as a module. However, if the character set of the locale is UTF-8, the corresponding option iocharset=utf8 would make the file system case sensitive. To fix this, use the special option utf8 instead of iocharset=utf8, for UTF-8 locales. The codepage option is also needed for vfat and smbfs filesystems. It should be set to the codepage number used under MS-DOS in your country. For example, in order to mount USB flash drives, a ru_RU.KOI8-R user would need the following in the options portion of its mount line in /etc/fstab:

noauto,user,quiet,showexec,codepage=866,iocharset=koi8r

The corresponding options fragment for ru_RU.UTF-8 users is:

noauto,user,quiet,showexec,codepage=866,utf8

Note that using iocharset is the default for iso8859-1 (which keeps the file system case insensitive), and the utf8 option tells the kernel to convert the file names using UTF-8 so they can be interpreted in the UTF-8 locale.

When installing GRUB with UEFI, the ESP must be formatted as a FAT filesystem, most commonly VFAT. This file sees it as VFAT regardless. An example of how you would go about an entry for the ESP would look like this:

cat >> /etc/fstab << "EOF"
/dev/<zzz>  /boot/efi  vfat  rw,relatime,codepage=437,iocharset=iso8859-1   0   2
EOF

The iso8859-1 IO charset is used here as we'll enable it as a part of the kernel UEFI configuration in Section 10.3, “Linux-6.19.10”. Technically the IO charset should match your locale as we've discussed above. However the name of all the files in the ESP only contains 7-bit ASCII characters, so things will be OK as long as the character set for your locale treats 7-bit ASCII characters in the same way as ISO-8859-1. For example, UTF-8 is such a character set.

[Note]

Note

The EFI filesystem only needs to be mounted when installing GRUB. The system uses this partition before the kernel is loaded and is not used otherwise. An alternative to adding this entry to the fstab file is to manually mount it before running grub-install below in Section 10.4, “Using GRUB to Set Up the Boot Process”.

It is also possible to specify default codepage and iocharset values for some filesystems during kernel configuration. The relevant parameters are named Default NLS Option (CONFIG_NLS_DEFAULT), Default Remote NLS Option (CONFIG_SMB_NLS_DEFAULT), Default codepage for FAT (CONFIG_FAT_DEFAULT_CODEPAGE), and Default iocharset for FAT (CONFIG_FAT_DEFAULT_IOCHARSET). There is no way to specify these settings for the ntfs filesystem at kernel compilation time.