2

Why can I (or cannot) mount a mounted device again? What is happening?
For example:

/tmp/test$ sudo mount /dev/sda5 ./1;echo ${?}
0
/tmp/test$ sudo mount /dev/sda5 ./2;echo ${?}
0
/tmp/test$ sudo mount | grep test
/dev/sda5 on /tmp/test/1 type ext4 (rw,relatime,data=ordered)
/dev/sda5 on /tmp/test/2 type ext4 (rw,relatime,data=ordered)
/tmp/test$ sudo umount ./1 ./2;echo ${?}
0
/tmp/test$ sudo losetup
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE          DIO
/dev/loop0         0      0         0  0 /tmp/test/grub.iso   0
/tmp/test$ sudo mount /dev/loop0 ./1;echo ${?}
mount: /dev/loop0 is write-protected, mounting read-only
0
/tmp/test$ sudo mount /dev/loop0 ./2;echo ${?}
mount: /dev/loop0 is already mounted or /tmp/test/2 busy
       /dev/loop0 is already mounted on /tmp/test/1
32
/tmp/test$ sudo mount | grep test
/dev/loop0 on /tmp/test/1 type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048)
/tmp/test$ 

2 Answers2

1

Seem this reason is the -w and -r flag for multiple locations mount need same.

For example(/dev/sda5 is already mounted with -o rw):

$ sudo mount -r ./grub.iso ./1;echo $?
0
$ sudo mount -r ./grub.iso ./2;echo $?
0
$ sudo mount -r ./grub.iso ./3;echo $?
0
$ sudo umount ./1 ./2 ./3;echo $?
0
$ sudo mount -r /dev/sda5 /mnt;echo $?
mount: /dev/sda5 is already mounted or /mnt busy
       /dev/sda5 is already mounted on /home/xx/yy
32

Also see man mount for stretch:

-w, --rw, --read-write
          Mount the filesystem read/write.  This is the default.  A synonym is -o rw.

This is(seem) why you can mount /dev/sda5 on multiple locations with defaults options,but cannot mount grub.iso with defaults options on multiple locations

  • 1
    Nice. If you specify some other filesystem options on the second mount, including acl/noacl, I think they end up ignored. Maybe ro/rw are handled differently. https://lwn.net/Articles/762355/ / https://lwn.net/ml/linux-kernel/87d0uqpba5.fsf@xmission.com/ – sourcejedi Sep 05 '18 at 09:32
0

Judging on the evidence: the /dev/sda2 was originaly mounted as the / (file system root). But the fstab was completely disabled and the main mount is done in your my_init script file. There the first mount add the complete /dev/sda2 which contents the original root file system, the next line mounts to the same /home/ only /home/home/ by --bind option in ought to hide the rest of the original root filesystem. If you do umount /home/ once, you should see (as I wrote) the whole original root filesystem in the /home/ folder, i.e. ls /home/ then gives: bin boot dev etc home ...

Do not ask me, why somebody did it so.

schweik
  • 1,250