Linux设置开机自动挂载

创建挂载目录/media/cdrom:

[root@CactiEZ ~]# mkdir /media/cdrom

临时挂载:

[root@CactiEZ cdrom]# mount /dev/cdrom /media/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only

设置开机自动挂载方法:


#
# /etc/fstab
# Created by anaconda on Thu Sep 21 15:04:57 2017
#
# 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/vg_cactiezv10-LogVol00 /                       ext4    defaults        1 1
UUID=c6cbe736-b33b-414f-a3da-ca00fec75387 /boot                   ext4    defaults        1 2
/dev/mapper/vg_cactiezv10-LogVol01 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
/dev/cdrom              /media/cdrom            iso9660 defaults        0 0

增加最后一行:

/dev/cdrom              /media/cdrom            iso9660     defaults        0     0
挂载文件                 挂载目录                 文件类型    默认            默认  默认

小技巧:想知道文件类型,可以手动挂载后用mount命令即可查询

查看挂载成功的命令:mount

[root@CactiEZ cdrom]# mount
/dev/mapper/vg_cactiezv10-LogVol00 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /media/cdrom type iso9660 (ro)

可以看到最后一行(这里就有文件类型):

/dev/sr0 on /media/cdrom type iso9660 (ro)

重启服务器查看是否挂载成功:

[root@CactiEZ cdrom]# reboot

Broadcast message from [email protected]
	(/dev/pts/1) at 10:03 ...

The system is going down for reboot NOW!
Connecting to 192.168.1.195:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Wed Sep 19 10:04:14 2018 from 192.168.1.126
[root@CactiEZ ~]# mount
/dev/mapper/vg_cactiezv10-LogVol00 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /media/cdrom type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

成功挂载:

/dev/sr0 on /media/cdrom type iso9660 (ro)

注意:/dev/cdrom和/dev/sr0是一个文件

[root@CactiEZ ~]# ll /dev/cdrom 
lrwxrwxrwx 1 root root 3 Sep 19 10:09 /dev/cdrom -> sr0

好了,开机成功挂载文件目录

你可能感兴趣的:(Linux)