Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the introduction of fstab to automatically mount files when Linux system boots?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Linux system boot automatic mount file fstab introduction is what, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

Linux system boot automatic mount file fstab introduction

I. Introduction to fstab

The fstab file contains a variety of file system descriptions that can be modified by special tools. Each file system description in the fstab takes up one line, and each line is separated by TAB or space.

II. Introduction to fstab file content

[root@Centos ~]# cat /etc/fstab

# /etc/fstab

# Created by anaconda on Sun Aug 7 05:42:06 2016

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1

UUID=4eff9bdb-7e0b-4d25-8931-dc776537bc73 /boot ext4 defaults 1 2

/dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2

/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

The first column is the device (/dev/sda) or remote file system (nfs) to mount

The second column is the mount point of the file system

The third column is the file system that needs to be mounted

The fourth column mounts the required parameters

async This parameter indicates that the file system I/O involved is asynchronous processing, and will not be written to the disk synchronously to improve performance. It is generally not used in production environments.

atime This parameter indicates that the inode time of each data access is updated synchronously during each data access. It is the default parameter. It is not recommended to use it in high concurrency situations in actual production environments.

auto can be mounted automatically via the-a option

defaults defaults (rw,suid,dev,auto)

noatime Update file system access inode time asynchronously, improve I/O performance, common in actual production environment

noauto does not mount automatically

noexec non-executable executable program

The fifth column determines whether the file system needs to be dumped, usually set to 0 or 1

The sixth column controls whether the file needs to be booted for fsck checking

0 is not required, root partition is generally set to 1,/boot partition is generally set to 2

III. Configure fstab file

[root@Centos ~]# vi /etc/fstab

# /etc/fstab

# Created by anaconda on Sun Aug 7 05:42:06 2016

# Accessible filesystems, by reference, are maintained under '/dev/disk'

/dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

192.168.1.2:/data/bbs /mnt nfs defaults 0 0

Save and exit

IV: Configuration test

As mentioned earlier, we can put the boot autoboot file under/etc/rc.local

So before testing this configuration, let's test whether/etc/rc.local can meet the requirements of boot automount.

[root@localhost ~]# cat /etc/rc.local

#!/ bin/sh

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

[root@localhost ~]# echo "/bin/mount -t nfs 192.168.1.2:/data/bbs /mnt">>/etc/rc.local

[root@localhost ~]# tail -1 /etc/rc.local

/bin/mount -t nfs 192.168.1.2:/data/bbs /mnt

[root@localhost ~]# reboot

Restart the system to test the boot mount

[root@localhost /]# df -h Check whether the mount is successful

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root 18G 3.3G 14G 20% /

tmpfs 491M 0 491M 0% /dev/shm

/dev/sda1 485M 35M 426M 8% /boot

192.168.1.2:/data/bbs 50G 3.5G 44G 8% /mnt

After testing, it can be automatically mounted when booting.

Next we test the automount command under/etc/fstab

Note here, remember to backup the/etc/fstab file before configuring it

[root@localhost ~]# cp /etc/fstab /etc/fstab.ori.bak.20160818

[root@localhost /]# vi /etc/fstab

# /etc/fstab

# Created by anaconda on Fri Aug 19 20:33:46 2016

/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

192.168.1.2:/data/bbs /mnt nfs defaults 0 0

"/etc/fstab" 16L, 833C written

[root@localhost /]# tail -1 /etc/fstab Check configuration

192.168.1.2:/data/bbs /mnt nfs defaults 0 0

Configuration complete, restart system

[root@localhost /]# reboot

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root 18G 3.3G 14G 20% /

tmpfs 491M 72K 491M 1% /dev/shm

/dev/sda1 485M 35M 426M 8% /boot

192.168.1.2:/data/bbs 50G 3.5G 44G 8% /mnt

You can also boot automatically and mount successfully

However, in actual production environments, this is not recommended, because if the NFS server is unavailable, then the client may not be able to start after booting, because the boot sequence is/etc/fatab first,/etc/rc.local after boot, so in actual production environments, to form a certain specification, either put the boot content into/etc/rc.local, or put the boot content into/etc/fatab.

Five: fstab failure causes the boot to fail to start the solution

The operating system is Centos 6.5.

The following prompt appears after boot loading, indicating that an error occurs during boot check

System loading error, unable to start

Method 1:

Prompt for root password or control-D Continue, here we enter administrator password

When editing/etc/fstab, prompt unable to write

Next, execute the following command to modify

[root@localhost ~]# mount -o rw,remount /

[root@localhost ~]# cp /etc/fstab.ori.bak.20160818 /etc/fstab

[root@localhost ~]# reboot

We're good to go.

Method 2:

Use the system CD boot to restore, first set up a good boot from the CD drive

Select rescue mode after restarting the system

Enter and select two default options

Select Do Not Boot from NIC

Select Launch Shell

From the above, we know that the directory is mounted under/mnt/sysimage, so we can restore the backup file above.

Restart the system and set boot to disk boot

Enter user name and password, successfully login system, recovery success.

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report