mount mount experiment
The classmates who developed it today called and asked a strange question: Can multiple nas be mounted in the same folder?
My first reaction was no, but I didn't think about why.
Now let's do an experiment to verify:
- Can the same directory mount multiple partitions/hard disks/logical volumes/nas at the same time?
- Can the same partition/hard disk/logical volume/nas be mounted to multiple directories
Environmental preparation
- Experimental Baseline
Operating System: CentOS Linux release 8.4.2105 - The virtual machine creates 3 new hard disks as experimental mounts
- View hard drive
[root@C8-196 ~]# lsblk
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
sdc 8:32 0 5G 0 disk
sdd 8:48 0 5G 0 disk
- Using logical volume partitions
[root@C8-196 ~]# pvcreate /dev/sdb /dev/sdc /dev/sdd
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
Physical volume "/dev/sdd" successfully created.
[root@C8-196 ~]# vgcreate mt /dev/sdb /dev/sdc /dev/sdd
Volume group "mt" successfully created
[root@C8-196 ~]# lvcreate -L +5G mt1_lv mt
Volume group "mt1_lv" not found
Cannot process volume group mt1_lv
[root@C8-196 ~]# lvcreate -L +5G -n mt1_lv mt
Logical volume "mt1_lv" created.
[root@C8-196 ~]# lvcreate -L +5G -n mt2_lv mt
Logical volume "mt2_lv" created.
[root@C8-196 ~]# lvcreate -L +5G -n mt3_lv mt
Volume group "mt" has insufficient free space (1277 extents): 1280 required.
[root@C8-196 ~]# lvcreate -L +4 -n mt3_lv mt
Logical volume "mt3_lv" created.
[root@C8-196 ~]# lsblk
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
└─mt-mt1_lv 253:3 0 5G 0 lvm
sdc 8:32 0 5G 0 disk
├─mt-mt1_lv 253:3 0 5G 0 lvm
├─mt-mt2_lv 253:4 0 5G 0 lvm
└─mt-mt3_lv 253:5 0 4M 0 lvm
sdd 8:48 0 5G 0 disk
└─mt-mt2_lv 253:4 0 5G 0 lvm
[root@C8-196 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home cl -wi-ao---- 126.96g
root cl -wi-ao---- 70.00g
swap cl -wi-ao---- 2.03g
mt1_lv mt -wi-a----- 5.00g
mt2_lv mt -wi-a----- 5.00g
mt3_lv mt -wi-a----- 4.00m
- Create a file system on the three newly created logical volume partitions
mkfs.xfs /dev/mapper/mt-mt1_lv
mkfs.xfs /dev/mapper/mt-mt2_lv
mkfs.ext4 /dev/mapper/mt-mt3_lv
- View partition status
[root@C8-196 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs c17463f3-cf5c-4d9e-b7f8-34e1f09de31c /boot
└─sda2 LVM2_member 5fOYEk-G1PN-Yilu-3PZD-dV92-kCgM-4NQTC4
├─cl-root xfs e88eb208-9984-4cbe-867b-8a0fee022dec /
├─cl-swap swap ad9f0577-fb9a-4e61-99d2-b42473a0e815 [SWAP]
└─cl-home xfs 19122a86-a5b9-43c8-bdb3-6ae3a94702bb /home
sdb LVM2_member vv0NK7-BQXM-Z2dp-QSnp-W3Ff-qdfz-qDkM2K
└─mt-mt1_lv xfs 540120f8-557d-4a7b-95a0-8f3965e212a5
sdc LVM2_member FQRPl7-L1K5-z6PK-o3wR-rTz9-0tGj-hCMB8s
├─mt-mt1_lv xfs 540120f8-557d-4a7b-95a0-8f3965e212a5
├─mt-mt2_lv xfs 01a90cf9-4049-45f3-95c3-acb6f879cba0
└─mt-mt3_lv ext4 597e10e6-e1ad-4d04-ac95-304b0a61de58
sdd LVM2_member 7hKy5j-Yik1-mpdE-NXir-J84W-a4c7-JmTZLE
└─mt-mt2_lv xfs 01a90cf9-4049-45f3-95c3-acb6f879cba0
- Create 3 mount points
[root@C8-196 ~]# mkdir -pv /data/mt{1..3}
mkdir: created directory '/data/mt1'
mkdir: created directory '/data/mt2'
mkdir: created directory '/data/mt3'
[root@C8-196 ~]# ll /data
total 0
drwxr-xr-x 2 root root 6 Mar 10 21:05 mt1
drwxr-xr-x 2 root root 6 Mar 10 21:05 mt2
drwxr-xr-x 2 root root 6 Mar 10 21:05 mt3
drwxr-xr-x 2 root root 6 Dec 17 21:43 spugdata
Test 1: Mount multiple partitions on the same mount point (directory)
- Mount point /data/mt1 mounts 3 partitions respectively
[root@C8-196 ~]# mount /dev/mapper/mt-mt1_lv /data/mt1
[root@C8-196 ~]# df -Th
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 3.6G 67G 6% /
/dev/mapper/cl-home xfs 127G 2.5G 125G 2% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
overlay overlay 70G 3.6G 67G 6% /var/lib/docker/overlay2/dff1098e902038f4105591060554c84a668a85b076f0596f8b144e77ca7a8633/merged
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/mt-mt1_lv xfs 5.0G 68M 5.0G 2% /data/mt1
[root@C8-196 ~]# mount /dev/mapper/mt-mt2_lv /data/mt1
[root@C8-196 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
##上边的省略
/dev/mapper/mt-mt2_lv xfs 5.0G 68M 5.0G 2% /data/mt1
[root@C8-196 ~]# mount /dev/mapper/mt-mt3_lv /data/mt1
[root@C8-196 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
##上边的省略
/dev/mapper/mt-mt3_lv ext4 2.9M 45K 2.6M 2% /data/mt1
- Obviously, it is impossible to mount at the same time,
- When the second partition is mounted, the first partition is dropped
- When the third partition is mounted, the second partition is dropped
- But when I umount something strange happens
[root@C8-196 ~]# umount /data/mt1
[root@C8-196 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
##上边的省略
/dev/mapper/mt-mt2_lv xfs 5.0G 68M 5.0G 2% /data/mt1
- Did you see that, after umount, it does not return to the unmounted state, but returns to the state of the previous mount point
Take a look at the partition
- The truth is, the same directory can mount multiple partitions
[root@C8-196 ~]# lsblk
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
└─mt-mt1_lv 253:3 0 5G 0 lvm /data/mt1
sdc 8:32 0 5G 0 disk
├─mt-mt1_lv 253:3 0 5G 0 lvm /data/mt1
├─mt-mt2_lv 253:4 0 5G 0 lvm /data/mt1
└─mt-mt3_lv 253:5 0 4M 0 lvm
sdd 8:48 0 5G 0 disk
└─mt-mt2_lv 253:4 0 5G 0 lvm /data/mt1
- Let's mount mt-mt3 on /data/mt1
- Obviously, the same mount point can mount multiple partitions at the same time
- Obviously multiple partitions can be mounted on the same mount point at the same time
reading and writing test
- Since they are all hung up, we should write data to all partitions at the same time when we write data to this mount point.
- We now write data to the /data/mt1 folder
[root@C8-196 ~]# touch /data/mt1/mt{1..10}.log
[root@C8-196 ~]# ll /data/mt1
total 12
drwx------ 2 root root 12288 Mar 10 21:02 lost+found
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt10.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt1.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt2.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt3.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt4.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt5.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt6.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt7.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt8.log
-rw-r--r-- 1 root root 0 Mar 10 21:20 mt9.log
[root@C8-196 ~]# ll /data/mt2
total 0
[root@C8-196 ~]# ll /data/mt3
total 0
- At the same time, it can be seen that /data/mt2 and /data/mt3 are empty
- At this time, the three partitions are all mounted on /data/mt1, which means that the three disks should have the same content.
- We dismantle the two partitions and mount them separately
[root@C8-196 ~]# mount /dev/mapper/mt-mt2_lv /data/mt2
[root@C8-196 ~]# mount /dev/mapper/mt-mt3_lv /data/mt3
- Strange things happened again, this time only mt1 and mt3 have data, but there is no data in mt2
- The mount situation at this time is like this
- At this time, the partition situation is like this
- Since there is a supernatural event, we all take it off and remount it
- This time the world is clean
- Re-mount to the corresponding directory to see the data
[root@C8-196 ~]# mount /dev/mapper/mt-mt1_lv /data/mt1
[root@C8-196 ~]# mount /dev/mapper/mt-mt2_lv /data/mt2
[root@C8-196 ~]# mount /dev/mapper/mt-mt3_lv /data/mt3
- As a result, there is only data on mt3
- It also means that the data is written on the partition /dev/mapper/mt-mt3_lv
- That is to say, the last mounted disk /dev/mapper/mt-mt3_lv has actually written data.
- That is to say, one mount point cannot be mounted on multiple partitions at the same time.
Test 2: Mount the same partition to multiple mount points (directories)
- Initialize all mount points and partitions
- Mount mt-mt1_lv to /data/mt1 /data/mt2 /data/mt3 respectively
- We successively mounted 3 directories in the same partition without umount,
- But df shows the same directory, no change
- But when I run lsblk, I see that the partition has been mounted to mt3
-
- We know that the data actually exists on the partition, so let's see if there is any content in the current directory
- We know that the data actually exists on the partition, so let's see if there is any content in the current directory
- All directories are currently empty
- Then let's write the data and see
- write 123 in directory mt1
touch /data/mt1/mt{1..3}.log
- write 456 in directory mt2
touch /data/mt3/mt{4..6}.log
- The time to witness the miracle is here, let's watch mt2
- Although neither df nor lsblk shows the mount status of /data/mt2,
- But we saw that the contents of mt1 and mt3 were written in the original empty directory mt2.
- Then we can be sure that mt1 and mt3 now have the same data as mt2
- My eyes are rulers, no need to watch playback! ! !
Summarize
-
The same directory cannot mount multiple partitions at the same time
. Even if it seems to be mounted on lsblk, only the last mounted one will take effect -
Multiple partitions cannot be mounted on the same directory at the same time.
Even if they can be mounted, the same data will not be written. -
The same partition can be mounted to multiple directories at the same time.
Even if df and lsblk look different, as long as there is no umount, it is considered to be mounted. -
Multiple directories can mount the same partition at the same time
. The data written to any directory is actually written to the same partition.This is the same data in the same partition!
make a metaphor,
- A partition or disk or nfs can be imagined as a house
- The directory, the mount point, can be like a door
- A room can have multiple doors, whichever door enters and exits to this house.
- A door can only be installed on one house, not two houses, only one room can be entered through one door and multiple rooms cannot be entered through one door.