挂载点可以是目录众所周知,挂载点可不可以是软连接呢?
mount挂载点实验
测试环境
- OS:CentOS 8
- mount from util-linux 2.32.1 (libmount 2.32.1: selinux, btrfs, debug)
新添加磁盘一个
- 虚拟机新添加磁盘一个
分区并建立文件系统
- 习惯创建逻辑卷取代传统fdisk分区方式
pvcreate /dev/sdb&&vgcreate mvg /dev/sdb && lvcreate -l +100%FREE -n mlv mvg&&lsblk
[root@C8-196 ~]
Physical volume "/dev/sdb" successfully created.
Volume group "mvg" successfully created
Invalid argument for --extents: +100FREE
Error during parsing of command line.
[root@C8-196 ~]
Can't initialize physical volume "/dev/sdb" of volume group "mvg" without -ff
/dev/sdb: physical volume not initialized.
[root@C8-196 ~]
Logical volume "mlv" created.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 199G 0 part
├─cl-root 253:0 0 70G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 127G 0 lvm /home
sdb 8:16 0 5G 0 disk
└─mvg-mlv 253:3 0 5G 0 lvm
[root@C8-196 ~]
lrwxrwxrwx 1 root root 7 Mar 31 18:52 /dev/mapper/mvg-mlv -> ../dm-3
[root@C8-196 ~]
meta-data=/dev/mapper/mvg-mlv isize=512 agcount=4, agsize=327424 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1309696, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
创建目录挂载点并挂载
[root@C8-196 ~]
mkdir -pv /mtest/mdir && mount /dev/mapper/mvg-mlv /dev/mapper/mvg-mlv&&df -Th
mkdir: created directory '/mtest'
mkdir: created directory '/mtest/mdir'
mount: /dev/mapper/mvg-mlv: mount point is not a directory.
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/mvg-mlv xfs 5.0G 68M 5.0G 2% /mtest/mdir
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/mvg-mlv xfs 5.0G 68M 5.0G 2% /mtest/mdir
[root@C8-196 ~]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 199G 0 part
├─cl-root 253:0 0 70G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 127G 0 lvm /home
sdb 8:16 0 5G 0 disk
└─mvg-mlv 253:3 0 5G 0 lvm
对目录创建一个软连接并尝试挂载
[root@C8-196 ~]
total 0
lrwxrwxrwx 1 root root 11 Mar 31 19:05 ldir -> /mtest/mdir
drwxr-xr-x 2 root root 18 Mar 31 19:01 mdir
[root@C8-196 ~]
[root@C8-196 ~]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 199G 0 part
├─cl-root 253:0 0 70G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 127G 0 lvm /home
sdb 8:16 0 5G 0 disk
└─mvg-mlv 253:3 0 5G 0 lvm /mtest/mdir
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/mvg-mlv xfs 5.0G 68M 5.0G 2% /mtest/mdir
总结
- 软链接可以作为挂载点
- 通过软链接进行挂载会直接挂载到链接到的原始目录
- 也就是说用软链接当作挂载点就和直接挂载原始目录是一样一样的
- 还记得删除软链接导致原始目录的数据被删除的例子么?
删除测试
- 我们首先在原目录中创建一些测试文件
[root@C8-196 ~]
total 0
-rw-r--r-- 1 root root 0 Mar 31 19:14 1.log
-rw-r--r-- 1 root root 0 Mar 31 19:14 2.log
-rw-r--r-- 1 root root 0 Mar 31 19:14 3.log
-rw-r--r-- 1 root root 0 Mar 31 19:14 4.log
-rw-r--r-- 1 root root 0 Mar 31 19:14 5.log
- 使用rm删除软链接的错误方式–使用table补齐
- 我们常常习惯使用table补齐,这使操作变得简单,同时也带来风险
- 在使用rm -rf试图删除软链接ldir的时候,table补齐使这个操作变成了灾难
- rm -rf /mtest/ldir/ 会删除原始目录下的所有文件,如果这是生产数据,你就可以去死了
[root@C8-196 ~]
total 0
lrwxrwxrwx 1 root root 11 Mar 31 19:05 ldir -> /mtest/mdir
drwxr-xr-x 2 root root 71 Mar 31 19:14 mdir
[root@C8-196 ~]
[root@C8-196 ~]
total 0
lrwxrwxrwx 1 root root 11 Mar 31 19:05 ldir -> /mtest/mdir
drwxr-xr-x 2 root root 6 Mar 31 19:16 mdir
[root@C8-196 ~]
total 0
- 正确删除软链接的姿势
[root@C8-196 ~]
total 0
lrwxrwxrwx 1 root root 11 Mar 31 19:05 ldir -> /mtest/mdir
drwxr-xr-x 2 root root 6 Mar 31 19:16 mdir
[root@C8-196 ~]
rm: remove symbolic link '/mtest/ldir'? y
[root@C8-196 ~]
total 0
drwxr-xr-x 2 root root 6 Mar 31 19:16 mdir
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/mvg-mlv xfs 5.0G 68M 5.0G 2% /mtest/mdir
[root@C8-196 ~]
rm: cannot remove '/mtest/mdir/': Device or resource busy
|