Mounting File Systems Automatically: /etc/fstab (2024)

File systems are mounted using the mount command, described in the next section. Although you can mount a file system directly with only a mount command, you can simplify the process by placing mount information in the /etc/fstab configuration file. Using entries in this file, you can have certain file systems automatically mounted whenever your system boots. For others, you can specify configuration information, such as mountpoints and access permissions, which can be automatically used whenever you mount a file system. You needn't enter this information as arguments to a mount command as you otherwise must. This feature is what allows mount utilities on GNOME or KDE to enable you to mount a file system simply by clicking a window icon. All the mount information is already in the /etc/fstab file. For example, when you add a new hard disk partition to your Linux system, you most likely want to have it automatically mounted on startup, and then unmounted when you shut down. Otherwise, you must mount and unmount the partition explicitly each time you boot up and shut down your system. To have Linux automatically mount the file system on your new hard disk partition, you only need to add its name to the fstab file. You can do this by directly and carefully editing the /etc/fstab file to type in a new entry.

An entry in an fstab file contains several fields, each separated from the next by a space or tab. These are described as the device, mountpoint, file system type, options, dump, and fsck fields, arranged in the sequence shown here:

<device> <mountpoint> <filesystemtype> <options> <dump> <fsck>

The first field is the name of the file system to be mounted. This entry can be either a device name or an ext2 or ext3 file system label. A device name usually begins with /dev, such as /dev/hda3 for the third hard disk partition. A label is specified by assigning the label name to the tag LABEL, as in LABEL=/ for an ext2 root partition. The next field is the directory in your file structure where you want the file system on this device to be attached. These are empty directories to be used for file systems, such as /dev/floppy. The third field is the type of file system being mounted. Table 30-7 provides a list of all the different types you can mount. The type for a standard Linux hard disk partition is ext3. The next example shows an entry for the main Linux hard disk partition. This entry is mounted at the root directory, /, and has a file type of ext3:

/dev/hda3 / ext3 defaults 0 1

The following example shows a LABEL entry for the hard disk partition, where the label name is /:

LABEL=/ / ext3 defaults 0 1

Auto Mounts

The file system type for a floppy may differ depending on the disk you are trying to mount. For example, you may want to read a Windows-formatted floppy disk at one time and a Linux-formatted floppy disk at another time. For this reason, the file system type specified for the floppy device is auto. With this option, the type of file system formatted on the floppy disk is detected automatically, and the appropriate file system type is used.

/dev/fd0 /mnt/floppy auto defaults,noauto 0 0
Table 30-7: File System Types

Types

Description

auto

Attempts to detect the file system type automatically.

minux

Minux file systems (filenames are limited to 30 characters).

ext

Earlier version of Linux file system, no longer in use.

ext3

Standard Linux file system supporting long filenames and large file sizes. Includes journaling.

ext2

Older standard Linux file system supporting long filenames and large file sizes. Does not have journaling.

xiaf

Xiaf file system.

msdos

File system for MS-DOS partitions (16-bit).

vfat

File system for Windows 95, 98, and Millennium partitions (32-bit).

reiserfs

A ReiserFS journaling file system.

xfs

A Silicion Graphics (SGI) file system.

ntfs

Windows NT, Windows XP, and Windows 2000 file systems (read-only access, write access is experimental and dangerous).

smbfs

Samba remote file systems, such as NFS.

hpfs

File system for OS/2 high-performance partitions.

nfs

NFS file system for mounting partitions from remote systems.

umsdos

UMS-DOS file system.

swap

Linux swap partition or swap file.

sysv

Unix System V file systems.

iso9660

File system for mounting CD-ROM.

proc

Used by operating system for processes (kernel support file system).

devpts

Unix 98 Pseudo Terminals (ttys, kernel interface file system).

shmfs and tmpfs

Linux Virtual Memory, POSIX shared memory maintenance access (kernel interface file system).

mount Options

The field after the file system type lists the different options for mounting the file system. You can specify a default set of options by simply entering defaults, or you can list specific options next to each other separated by a comma (no spaces). The defaults option specifies that a device is read/write (rw), that it is asynchronous (async), that it is a block device (dev), that it cannot be mounted by ordinary users (nouser), and that programs can be executed on it (exec). By contrast, a CD-ROM has only two options listed for it: ro and noauto. ro specifies that the device is read-only, and noauto specifies it is not automatically mounted. The noauto option is used with both CD-ROMs and floppy drives, so they won't automatically mount, because you don't know if you have anything in them when you start up. At the same time, the entries for both the CD-ROM and the floppy drive specify where they are to be mounted when you decide to mount them. On Red Hat, the kudzu option invokes the Red Hat Kudzu tool, which checks to see if the device has been installed on your system, and that the kernel is running the appropriate drivers for that CD-ROM or floppy disk. Table 30-8 lists the options for mounting a file system. An example of CD-ROM and floppy drive entries follows. Notice the type for a CD-ROM file system is different from that for a hard disk partition, iso9660.

/dev/hdc /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
Table 30-8: Mount Options for File Systems

Options

Description

async

Indicates that all I/O to the file system should be done asynchronously.

auto

Indicates that the file system can be mounted with the -a option. A mount -a command executed when the system boots, in effect, mounts file systems automatically.

defaults

Uses default options: rw, suid, dev, exec, auto, nouser, and async.

dev

Interprets character or block special devices on the file system.

kudzu

Checks that the device is installed and accessible.

noauto

Indicates that the file system can only be mounted explicitly. The -a option does not cause the file system to be mounted.

exec

Permits execution of binaries.

nouser

Forbids an ordinary (that is, nonroot) user to mount the file system.

remount

Attempts to remount an already mounted file system. This is commonly used to change the mount flags for a file system, especially to make a read-only file system writable.

ro

Mounts the file system as read-only.

rw

Mounts the file system as read/write.

suid

Allows set-user-identifier or set-group-identifier bits to take effect.

sync

Indicates that all I/O to the file system should be done synchronously.

user

Enables an ordinary user to mount the file system. Ordinary users always have the following options activated: noexec, nosuid, and nodev.

nodev

Does not interpret character or block special devices on the file system.

noexec

Does not allow execution of binaries on the mounted file systems

nosuid

Does not allow set-user-identifier or set-group-identifier bits to take effect.

Boot and Disk Check

The last two fields of an fstab entry consist of integer values. The first one is used by the dump command to determine if a file system needs to be dumped, backing up the file system. The second value is used by fsck to see if a file system should be checked at reboot, and in what order with other file systems. If the field has a value of 1, it indicates a boot partition, and 2 indicates other partitions. The 0 value means fsck needn't check the file system.

A copy of an /etc/fstab file is shown here. Notice the first line is a comment. All comment lines begin with a #. The entry for the /proc file system is a special entry used by your Linux operating system for managing its processes; it is not an actual device. To make an entry in the /etc/fstab file, you can edit the /etc/fstab file directly. You can use the example /etc/fstab file shown here as a guide to show how your entries should look. The /proc and swap partition entries are particularly critical.

/etc/fstab

Mounting File Systems Automatically: /etc/fstab (1)

# <device> <mountpoint> <filesystemtype> <options> <dump><fsck>/dev/hda3 / ext3 defaults 0 1none /proc proc defaults 0 0none /dev/pts devpts gid=5,mode=620 0 0none /dev/shm tmpfs defaults 0 0/dev/hda2 swap swap defaults 0 0/dev/hdc /mnt/cdrom iso9660 noauto,owner,kudzu,ro  0 0/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0/dev/hda1 /mnt/windows vfat defaults 0 0

Mounting File Systems Automatically: /etc/fstab (2)

CD-ROM and Floppy Defaults

Red Hat creates entries in the fstab file for any CD-ROM and floppy devices you may have. It also creates directories where these drives can be mounted. For Red Hat, these are /mnt/cdrom for your CD-ROM and /mnt/floppy for your floppy disk. If you have several CD-ROMs or floppy drives, directories are created for them with sequential numbers. So on Red Hat, a second CD-ROM drive will use a directory named /mnt/cdrom1.

Partition Labels: e2label

Red Hat uses file system labels for ext2 and ext3 file systems on hard disk partitions. Thus in the /etc/fstab file previously shown, the first entry would use a label for its device name, as shown here. In this case, the label is the slash, /, indicating the root partition. You could change this device's label with e2label, but be sure to also change the /etc/fstab entry for it.

LABEL=/ / ext3 defaults 0 1

For ext2 and ext3 partitions, you can change or add a label with the e2label tool or tune2fs with the -L option. Specify the device and the label name. If you change a label, be sure to change corresponding entries in the /etc/fstab file. Just use e2label with the device name to find out what the current label is. In the next example, the user changes the label of the /dev/hda3 device to TURTLE:

e2label /dev/hda3 TURTLE

Windows Partitions

You can mount either MS-DOS, Windows 95/98/ME, or Windows XP, NT, and 2000 partitions used by your Windows operating system onto your Linux file structure, just as you would mount any Linux file system. You have to specify the file type of vfat for Windows 95/98/ME, and msdos for MS-DOS. Windows XP, NT, and 2000 use the ntfs file type. You may find it convenient to have your Windows partitions automatically mounted when you start up your Linux system. To do this, you need to put an entry for your Windows partitions in your /etc/fstab file and give it the defaults option, or be sure to include an auto option. You make an entry for each Windows partition you want to mount, and then specify the device name for that partition, followed by the directory in which you want to mount it. The /mnt/windows directory would be a logical choice (be sure the windows directory has already been created in /mnt). The next example shows a standard Windows partition entry for an /etc/fstab file. Notice the last entry in the /etc/fstab file example is an entry for mounting a Windows partition.

/dev/hda1 /mnt/windows vfat defaults 0 0
Tip

Linux kernel 2.4 systems currently can only reliably mount ntfs file systems (Windows NT, Windows 2000, and Windows XP) as read-only. They cannot write to these partitions, though experimental and unstable support is provided using the ntsf kernel module (see The Linux-NTSF Project at linux-ntfs.sourceforge.net).

Linux Kernel Interfaces

Your /etc/fstab file may also have entries for two special kernel interface file systems, devpts and tmpfs. Both provide kernel interfaces that are not supported by standard devices. The /dev/pts entry mounts a devpts file system for pseudo-terminals. The /dev/shm entry mounts the tmpfs file system (also known as shmfs) to implement Linux Virtual Memory, POSIX shared memory maintenance access. This is designed to overcome the 4GB memory limitation on current systems, extending usable memory to 64GB.

If your /etc/fstab file ever becomes corrupt—say, if a line gets deleted accidentally or changed—your system will boot into a maintenance mode, giving you read-only access to your partitions. To gain read/write access so that you can fix your /etc/fstab file, you have to remount your main partition. The following command performs such an operation:

# mount -n -o remount,rw /

noauto

File systems listed in the /etc/fstab file are automatically mounted whenever you boot, unless this feature is explicitly turned off with the noauto option. Notice that the CD-ROM and floppy disks in the sample fstab file earlier in this chapter have a noauto option. Also, if you issue a mount -a command, all the file systems without a noauto option are mounted. If you want to make the CD-ROM user-mountable, add the user option.

/dev/hdc /mnt/cdrom iso9660 ro,noauto,user 0 0
Tip

The "automatic" mounting of file systems from /etc/fstab is actually implemented by executing a mount -a command in the /etc/rc.d/rc.sysinit file that is run whenever you boot. The mount -a command mounts any file system listed in your /etc/fstab file that does not have a noauto option. The umount -a command (which is executed when you shut down your system) unmounts the file systems in /etc/fstab.

Mounting File Systems Automatically: /etc/fstab (2024)

FAQs

How to automount with fstab? ›

How to automatically mount a volume at instance startup
  1. sudo cp /etc/fstab /etc/fstab.old. ...
  2. sudo lsblk -o NAME,FSTYPE,UUID,SIZE,LABEL. ...
  3. sudo vim /etc/fstab. ...
  4. <filesystem UUID> <mount point> <type> <options> <dump> <pass> (each element is separated by whitespace)

Which file is used to automatically mount file systems? ›

The /etc/vfstab file, which will automatically mount the file system when the system is booted in multi-user state.

Which file should you modify to automatically mount a filesystem on boot? ›

These file systems are explicitly mounted by the boot process. The stanzas of such file systems in the /etc/filesystems file have mount = automatic . The second type of automatic mount is user-controlled. These file systems are mounted by the /etc/rc script when it issues the mount all command.

What is the purpose of the ETC fstab file? ›

In Linux, it is part of the util-linux package. The fstab file typically lists all available disk partitions and other types of file systems and data sources that may not necessarily be disk-based, and indicates how they are to be initialized or otherwise integrated into the larger file system structure.

How to automatically mount a filesystem in Linux? ›

Configuring a File System to Automatically Mount (Linux Instances...
  1. Log into the instance where you want the file system mounted. ...
  2. Create a mount point, if one hasn't been created. ...
  3. Open the /etc/fstab file in an editor and add a line for the nfs file systems you want automatically mounted.
Nov 21, 2023

How do I turn on auto mount? ›

To enable automounting: Enter the following commands at a command prompt: C:\> diskpart DISKPART> automount enable Automatic mounting of new volumes enabled.

How do I permanently mount a file system? ›

You can mount file systems for a single session using the mount command, and permanently by editing /etc/fstab . Mounting needs to be done by an administrator, either by logging in as root or by using the sudo command. There are some cases where mounting is done automatically, like when you insert a USB flash drive.

What are the different ways of mounting a file system? ›

There are two types of mounts, a remote mount and a local mount. Remote mounts are done on a remote system on which data is transmitted over a telecommunication line. Remote file systems, such as Network File System (NFS), require that the files be exported before they can be mounted.

How can a file system be mounted? ›

Mounting is a process in which the operating system adds the directories and files from a storage device to the user's computer file system. The file system is attached to an empty directory, by adding so the system user can access the data that is available inside the storage device through the system file manager.

How can you ensure a file system will be automatically mounted at boot time? ›

The "automatic" mounting of file systems from /etc/fstab is actually implemented by executing a mount -a command in the /etc/rc. d/rc. sysinit file that is run whenever you boot. The mount -a command mounts any file system listed in your /etc/fstab file that does not have a noauto option.

How does automount work in Linux? ›

automountd locates the file system information in a map, creates the trigger nodes, and performs the mount. Autofs allows the intercepted request to proceed. Autofs unmounts the file system after a period of inactivity.

What is the difference between filesystem and mount? ›

The data and the attributes of a file are stored with the file in the file system. All file attributes are stored in a control block that is sometimes called the inode . Mounting a file system creates a binding for the duration of the mount.

What is the difference between Autofs and fstab? ›

Autofs defined

In short, it only mounts a given share when that share is being accessed and are unmounted after a defined period of inactivity. Automounting NFS shares in this way conserves bandwidth and offers better performance compared to static mounts controlled by /etc/fstab .

How to permanently mount a drive in Linux? ›

Open the fstab file for editing with the command:
  1. sudo nano /etc/fstab. At the bottom of that file, add an entry like this:
  2. /dev/sdb1 /data ext4 defaults 0 0. Here's an explanation: /dev/sdb1 -- the secondary drive. ...
  3. mount -a. If you receive no feedback, everything is good.
May 19, 2023

Why do we need to mount filesystem in Linux? ›

What is the purpose of mounting a file system in Linux? Mounting a file system in Linux is like connecting a USB drive or accessing files from another location on your computer. It's a way to make files and folders from an external source, like a disk or network, part of your computer's directory structure.

How to remount fstab? ›

Remount all filesystems in fstab with command mount -o remount -a. Should re-mount with the changed mount-options of your fstab.

How do I force a drive to mount in Linux? ›

Mount the USB drive to the /media/pendrive directory using the mount command. The mount command has the following syntax; sudo mount /path/to/drive /path/to/mountpoint. 4. Check the drive has been mounted by re-running lsblk.

How to auto mount NTFS drive in Linux? ›

Auto mounting a drive containing a Windows (NTFS) file system using /etc/fstab
  1. Step 1: Edit /etc/fstab. Open the terminal application and type the following command: ...
  2. Step 2: Append the following configuration. ...
  3. Step 3: Create the /mnt/ntfs/ directory. ...
  4. Step 4: Test it. ...
  5. Step 5: Unmount NTFS partion.
May 26, 2021

What is the default mount in fstab? ›

defaults - default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async). suid - allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task.

Top Articles
How to Deduct Stock Losses From Your Tax Bill
NEAR now available globally
$4,500,000 - 645 Matanzas CT, Fort Myers Beach, FL, 33931, William Raveis Real Estate, Mortgage, and Insurance
Creepshotorg
Cranes For Sale in United States| IronPlanet
Kreme Delite Menu
Uca Cheerleading Nationals 2023
What Are the Best Cal State Schools? | BestColleges
BULLETIN OF ANIMAL HEALTH AND PRODUCTION IN AFRICA
Www Craigslist Louisville
Here's how eating according to your blood type could help you keep healthy
biBERK Business Insurance Provides Essential Insights on Liquor Store Risk Management and Insurance Considerations
Student Rating Of Teaching Umn
Cool Math Games Bucketball
Marion County Wv Tax Maps
Vcuapi
Midlife Crisis F95Zone
Condogames Xyz Discord
Are They Not Beautiful Wowhead
Comics Valley In Hindi
Race Karts For Sale Near Me
Mikayla Campinos Laek: The Rising Star Of Social Media
ABCproxy | World-Leading Provider of Residential IP Proxies
Qual o significado log out?
How to Make Ghee - How We Flourish
Lines Ac And Rs Can Best Be Described As
Dove Cremation Services Topeka Ks
Keyn Car Shows
No Limit Telegram Channel
Carroway Funeral Home Obituaries Lufkin
Pixel Combat Unblocked
Danielle Moodie-Mills Net Worth
Why comparing against exchange rates from Google is wrong
The Monitor Recent Obituaries: All Of The Monitor's Recent Obituaries
Kiddie Jungle Parma
Pfcu Chestnut Street
Swgoh Boba Fett Counter
Indiana Jones 5 Showtimes Near Jamaica Multiplex Cinemas
Spy School Secrets - Canada's History
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Oxford Alabama Craigslist
How are you feeling? Vocabulary & expressions to answer this common question!
Gpa Calculator Georgia Tech
Andrew Lee Torres
1Exquisitetaste
Gregory (Five Nights at Freddy's)
Citroen | Skąd pobrać program do lexia diagbox?
What Is The Optavia Diet—And How Does It Work?
Vci Classified Paducah
Hdmovie2 Sbs
Mcoc Black Panther
Bones And All Showtimes Near Emagine Canton
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5505

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.