You are not logged in.

#1 2016-11-29 21:40:28

jkarres
Member
Registered: 2013-06-10
Posts: 11

non-recursive bind mounts in fstab

I'd like to have a bind mount of my main filesystem at /mnt/root.  Using the command "mount -B / /mnt/root" accomplishes this without issue.  (Namely, my external backup drive that is mounted at /media/backup is not also mounted at /mnt/root/media/backup.)

I'd like to do this using my fstab, so I added the line

    /     /mnt/root      none bind 0 0

But this results in my external drive being mounted at both /media/backup and /mnt/root/media/backup.  Is this the intended behavior?  How do I keep the bind mount I want (/ -> /mnt/root) without having /media/backup at /mnt/root/media/backup?

(If it matters, I mount the external drive in my fstab:

#
# /etc/fstab: static file system information
#
# <file system>	<dir>	<type>	<options>	<dump>	<pass>

# /dev/mapper/enc
UUID=644f961a-422c-4389-9cc0-b8105868a56c	/         	ext4      	rw,relatime,data=ordered	0 1

# doing this to make backups easier
/     /mnt/root      none bind 0 0

# /dev/nvme0n1p2
UUID=0494-1451      	/boot     	vfat      	rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro	0 2

# doing this to make backups easier
# /boot /mnt/root/boot none ro,bind 0 0

# external backup drive
UUID=5eec9989-e316-4612-b5b8-b76c0e18f969 /media/backup	ext4	rw,relatime,data=ordered,nofail,auto,user	0 2

)

Last edited by jkarres (2016-11-29 21:41:29)

Offline

#2 2016-11-29 22:18:44

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,846
Website

Re: non-recursive bind mounts in fstab

But this results in my external drive being mounted at both /media/backup and /mnt/root/media/backup.  Is this the intended behavior?

It isn't, what you're describing is an rbind, are you sure this is what is happening? What does 'mount' say?

EDIT: I've just tested this on my own PC, and it does the same thing. Perhaps this is expected after all!

EDIT2: Instead of using a bind mount for this, and avoiding the recursion, you could just use a regular mount.

Last edited by WorMzy (2016-11-29 22:25:22)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2016-11-29 22:31:13

jkarres
Member
Registered: 2013-06-10
Posts: 11

Re: non-recursive bind mounts in fstab

WorMzy wrote:

But this results in my external drive being mounted at both /media/backup and /mnt/root/media/backup.  Is this the intended behavior?

It isn't, what you're describing is an rbind, are you sure this is what is happening? What does 'mount' say?

EDIT: I've just tested this on my own PC, and it does the same thing. Perhaps this is expected after all!

I'm glad it's not just me!  But if somebody decided that this is the way things should be, I'm struggling to understand the motivation.

EDIT2: Instead of using a bind mount for this, and avoiding the recursion, you could just use a regular mount.

So do you mean something like

UUID=644f961a-422c-4389-9cc0-b8105868a56c	/         	ext4      	rw,relatime,data=ordered	0 1
UUID=644f961a-422c-4389-9cc0-b8105868a56c	/mnt/root         	ext4      	rw,relatime,data=ordered	

EDIT: chopping off the last column of the second line above.

Well, I tried that and everything seems to be working as desired.  I'd read here that mounting a filesystem at two paths was not possible, but apparently this does not apply here.

One annoying issue is that if I try to change rw to ro on the /mnt/root mount, my computer won't boot.

Last edited by jkarres (2016-11-29 23:14:17)

Offline

#4 2016-11-30 00:32:18

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,846
Website

Re: non-recursive bind mounts in fstab

It may have been true in 2010, but multiple mount points hasn't been a problem for a while.

One annoying issue is that if I try to change rw to ro on the /mnt/root mount, my computer won't boot.

Do you get an error?


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2016-11-30 00:41:53

jkarres
Member
Registered: 2013-06-10
Posts: 11

Re: non-recursive bind mounts in fstab

I get

[FAILED] Failed to mount /mnt/root.

and then dropped into emergency mode.

I tried using this systemd service as a work-around, but I get the exact same behavior there.  I'm on #systemd at the moment seeing if anybody there can figure it out.

Offline

Board footer

Powered by FluxBB