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

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.

  • You are right,but why I can directly mount a mounted device without --bind? – illiterate Sep 3 '18 at 13:38
  • because with --bind you mount folder not device – schweik Sep 3 '18 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 Sep 3 '18 at 13:51
  • I'm sorry,but see my example code update @schweik – illiterate Sep 3 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.