Linux 光驱挂载管理
1.VMware添加光驱自动更换的原理
前言:在VMware中,一个CentOS 8 的系统,使用 autofs 自动挂载以后,那么此时会有两个配置文件,/etc/auto.maste和/etc/auto.misc,并且我们使用lsblk查看的时候,会有一块sr0的光驱存在,当我们 ls /misc/cd 就会进去到这块CentOS 8的光驱里面。
那么当我们再次添加一块CentOS 7的光驱的时候,当我们重启服务器以后之前CentOS 8对应的光驱编号就变成了sr1,后来添加的CentOS 7的光驱的编号就变成了sr0,但是每次 cd /misc/cd 进入的就是sr0(也就是会进入到CentOS 7的光驱里面,而不是CentOS 8的里面)。这个做实验的时候就很有问题。
原理:在VMware虚拟机中,SR0和SR1代表光驱设备的名称。当你在虚拟机中添加一个新的光驱设备时,VMware会将其分配为SR0,而原来的光驱设备会被重命名为SR1。
这是由于Linux内核规定,在同一总线上,设备的命名顺序是根据它们在总线上的位置来确定的。新添加的光驱设备被视为位于总线的顶部,因此被命名为SR0。原来的光驱设备则被认为是在总线的下方,因此被重命名为SR1。
解决思路:将autofs挂载的目录绑定对应的光驱。因为最新加入的光驱会变成sr0,那么我们将CentOS8对应的sr1绑定autofs就可以了。
#编辑/etc/auto.master文件
[root@centos8 ~]#vi /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# If you have fedfs set up and the related binaries, either
# built as part of autofs or installed from another package,
# uncomment this line to use the fedfs program map to access
# your fedfs mounts.
#/nfs4 /usr/sbin/fedfs-map-nfs4 nobind
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
这里面的关键信息就是 /misc /etc/auto.misc 前面/misc挂载的目录,后面是对应的配置文件
#编辑/etc/auto.misc
[root@centos8 ~]#vi /etc/auto.misc
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# the following entries are samples to pique your imagination
#linux -ro,soft ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom,同理cd是目录跟之前的合在一起就是/misc/cd,意思就是光驱最后是挂载到/misc/cd 这个目录下的,至于为什么每次找到的sr0这个光驱,就是后面的/dev/cdrom,我们将这句话修改成:
cd -fstype=iso9660,ro,nosuid,nodev :/dev/sr1 意思就是这/dev/sr1这个光驱挂载到/misc/cd下,而/dev/sr1就是对应的CentOS 8系统的光驱
#重启autofs服务
[root@centos8 ~]#systemctl restart autofs
#挂载成功
[root@centos8 ~]#ls /misc/cd
AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL
[root@centos8 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 100G 0 part /
├─sda2 8:2 0 50G 0 part /data
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 1G 0 part /boot
sdb 8:16 0 20G 0 disk
sdc 8:32 0 10G 0 disk
sr0 11:0 1 9.5G 0 rom
sr1 11:1 1 10.1G 0 rom /misc/cd
[root@centos8 ~]#
#这里要提到一点sda硬盘会出现这种情况,测试多次发现nvme的磁盘不会,后加的是1,最开始是sr0
[root@CentOS8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10.1G 0 rom
sr1 11:1 1 9.5G 0 rom
nvme0n1 259:0 0 200G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
├─nvme0n1p2 259:2 0 100G 0 part /
├─nvme0n1p3 259:3 0 2G 0 part [SWAP]
├─nvme0n1p4 259:4 0 1K 0 part
├─nvme0n1p5 259:5 0 1G 0 part /home
└─nvme0n1p6 259:6 0 50G 0 part /data
[root@CentOS8 ~]#
2.Mount永久挂载
在本地搭建yum服务器的时候,每次将CentOS 7、8的光驱挂载到/var/www/html/ 对应的目录下,但是重启以后就消失了,因为mount只是临时挂载重启以后就没有了
#查看/dev/sr0、/dev/sr1光驱对应的UUID
[root@CentOS8 ~]# blkid /dev/sr0 /dev/sr1
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-11-13-01-04-26-00" LABEL="CentOS-8-5-2111-x86_64-dvd" TYPE="iso9660" PTUUID="5fb10f71" PTTYPE="dos"
/dev/sr1: BLOCK_SIZE="2048" UUID="2020-11-02-15-15-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTUUID="6b8b4567" PTTYPE="dos"
[root@CentOS8 ~]#
#永久挂载就是要将挂载写在文件中
[root@CentOS8 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Feb 8 15:36:41 2023
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=c01e07b0-beae-4dd0-b526-0d523b6529b9 / xfs defaults 0 0
UUID=6d3cbcc9-3487-4e85-b47d-3202436a1f57 /boot xfs defaults 0 0
UUID=2fc5880a-2c3a-44b7-8c98-ed510c8b7179 /data xfs defaults 0 0
UUID=ffc7d5bf-38d5-4cc0-9d62-e97679bcedc6 /home xfs defaults 0 0
UUID=2cc78375-3da1-44a1-955e-0bb6499459b7 none swap defaults 0 0
#新增两行
UUID=2021-11-13-01-04-26-00 /var/www/html/centos/8 iso9660 defaults 0 0
UUID=2020-11-02-15-15-23-00 /var/www/html/centos/7/os/x86_64 iso9660 defaults 0 0
[root@CentOS8 ~]#
#新增的两行拷贝到文件中,UUID就是/dev/sr0、/dev/sr1对应UUID,这个是唯一的,这里其实也可以将UUID=2021-11-13-01-04-26-00这一列替换成/dev/sr0,但是这样有可能以后光驱的名字改了,那么就绑定错位了。/var/www/html/centos/8 这个地址就是要挂载的地址 后面的是文件类型,就是上面用blkid 查看出来的TYPE,后面是defaults 0 0就行。
#配置文件生效
[root@CentOS8 ~]#mount -a
[root@CentOS8 ~]# mount -a
mount: /var/www/html/centos/8: WARNING: device write-protected, mounted read-only.
mount: /var/www/html/centos/7/os/x86_64: WARNING: device write-protected, mounted read-only.
[root@CentOS8 ~]#
[root@CentOS8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10.1G 0 rom /var/www/html/centos/8
sr1 11:1 1 9.5G 0 rom /var/www/html/centos/7/os/x86_64
nvme0n1 259:0 0 200G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
├─nvme0n1p2 259:2 0 100G 0 part /
├─nvme0n1p3 259:3 0 2G 0 part [SWAP]
├─nvme0n1p4 259:4 0 1K 0 part
├─nvme0n1p5 259:5 0 1G 0 part /home
└─nvme0n1p6 259:6 0 50G 0 part /data
[root@CentOS8 ~]#
#这样就永久挂载成功了
0 Comments