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
  • Content of /etc/fstab ?
    – schweik
    Commented Sep 3, 2018 at 12:53
  • see my update. @schweik
    – illiterate
    Commented Sep 3, 2018 at 12:56

2 Answers 2

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
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.

4
  • You are right,but why I can directly mount a mounted device without --bind?
    – illiterate
    Commented Sep 3, 2018 at 13:38
  • because with --bind you mount folder not device
    – schweik
    Commented Sep 3, 2018 at 13:39
  • 1
    A bind mount is analogous to a hard link. They allow to create multiple paths that refer to (portions of) the same filesystem. See unix.stackexchange.com/a/346460/147970 for details.
    – cg909
    Commented Sep 3, 2018 at 13:51
  • I'm sorry,but see my example code update @schweik
    – illiterate
    Commented Sep 3, 2018 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .