Accessing the lower mount of an overlay root fs

1

0

I use Linux overlay fs as root filesystem to keep the real root partition read-only and write changes to another fs (e.g., tmpfs or another partition).

However, when the root filesystem is finally in place (after 'pivot root'), the original mounts (let's say at /dev/sda at /mnt/root-write-protected) is hidden in the initial root (eg. init ramdisk), but still actively mounted. However, it is not visible from inside the root filesystem anymore, nor can the original device be mounted again in a writeable fashion, as mount says:

mount: /dev/sda is already mounted

despite no entry is listed by mount or cat /etc/mtab.

How can I access (e.g., read from, remount) this hidden mount?

dronus

Posted 2018-09-12T11:01:57.913

Reputation: 1 482

Off topic, How are you doing this "I use Linux overlay fs as root filesystem to keep the real root partition read-only and write changes to another fs (e.g., tmpfs ..." ? – Anwar – 2019-07-06T17:46:07.460

For Debian like Distros (like Ubuntu) there is a package overlayroot, that installs all scripts needed. Also there are older scripts lurking in the internet, that can be installed to the initrd to write-protect the root partition. If you try to do it manually, it's quite involved as you have to do it in early boot (when the kernel mounts the root partition) and therefore you need to do scripting in the initrd. – dronus – 2019-07-10T13:11:03.537

I installed the package but couldn't find helpful scripts. All scripts was for accessing files under an overlay mounted fs – Anwar – 2019-07-12T06:45:30.703

After installing the package, you have to set up some configurations eg. edit /etc/overlayroot.conf. There is some documentation inside. – dronus – 2019-07-13T09:52:33.640

Answers

0

Before the pivot-root happens, mount --bind the filesystem into a place that you'll be able to reach.

For example:

  1. Mount sda2 on /mnt/root-write-protected.
  2. Mount overlayfs on /mnt/new-root.
  3. Added step: Bind /mnt/root-write-protected on /mnt/new-root/raw-disk.
  4. Pivot into /mnt/new-root.
  5. Now you have sda2 accessible at /raw-disk.

user1686

Posted 2018-09-12T11:01:57.913

Reputation: 283 655

So this means once the mount is buried by pivot_root is it can't be recovered in anyway while still blocking a remount of the underlying device? So I need to interfere with early startup before pivot_root ? – dronus – 2018-09-26T23:03:40.597