Skip to content

Commit

Permalink
ostree: Use bind mounts to setup ostree root
Browse files Browse the repository at this point in the history
Simplify the mounting by using bind instead of tearing down the existing
mounts and remounting them in the ostree root. This also has the benefit
of working with dirinstall when there is no separate device for /boot.
  • Loading branch information
bcl committed Apr 29, 2016
1 parent 9d3a264 commit 664ef7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
28 changes: 5 additions & 23 deletions pyanaconda/packaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,29 +636,11 @@ def writeStorageLate(self):
every payload except for dnf. Payloads should only implement one of
these methods by overriding the unneeded one with a pass.
"""
if not flags.dirInstall:
if iutil.getSysroot() != iutil.getTargetPhysicalRoot():
set_sysroot(iutil.getTargetPhysicalRoot(), iutil.getSysroot())

# Now that we have the FS layout in the target, umount
# things that were in the legacy sysroot, and put them in
# the target root, except for the physical /. First,
# unmount all target filesystems.
self.storage.umount_filesystems()

# Explicitly mount the root on the physical sysroot
rootmnt = self.storage.mountpoints.get('/')
rootmnt.setup()
rootmnt.format.setup(options=rootmnt.format.options, chroot=iutil.getTargetPhysicalRoot())

self.prepareMountTargets(self.storage)

# Everything else goes in the target root, including /boot
# since the bootloader code will expect to find /boot
# inside the chroot.
self.storage.mount_filesystems(skip_root=True)

self.storage.write()
if iutil.getSysroot() != iutil.getTargetPhysicalRoot():
set_sysroot(iutil.getTargetPhysicalRoot(), iutil.getSysroot())
self.prepareMountTargets(self.storage)
if not flags.dirInstall:
self.storage.write()

# Inherit abstract methods from Payload
# pylint: disable=abstract-method
Expand Down
21 changes: 9 additions & 12 deletions pyanaconda/packaging/rpmostreepayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,21 @@ def install(self):
mainctx.pop_thread_default()

def prepareMountTargets(self, storage):
""" Prepare the ostree root """
ostreesetup = self.data.ostreesetup

varroot = iutil.getTargetPhysicalRoot() + '/ostree/deploy/' + ostreesetup.osname + '/var'

# Set up bind mounts as if we've booted the target system, so
# that %post script work inside the target.
binds = [(varroot,
iutil.getSysroot() + '/var'),
(iutil.getSysroot() + '/usr', None)]
binds = [(varroot, iutil.getSysroot() + '/var'),
(iutil.getSysroot() + '/usr', None),
(iutil.getTargetPhysicalRoot(), iutil.getSysroot() + "/sysroot"),
(iutil.getTargetPhysicalRoot() + "/boot", iutil.getSysroot() + "/boot")]

# Bind mount the other filesystems from /mnt/sysimage to the ostree root
for path in ["/dev", "/dev/pts", "/dev/shm", "/proc", "/run", "/sys", "/sys/fs/selinux"]:
binds += [(iutil.getTargetPhysicalRoot()+path, iutil.getSysroot()+path)]

for (src, dest) in binds:
self._safeExecWithRedirect("mount",
Expand All @@ -245,15 +251,6 @@ def prepareMountTargets(self, storage):
self._safeExecWithRedirect("mount",
["--bind", "-o", "remount,ro", src, src])

# We previously bind mounted /mnt/sysimage to
# /mnt/sysimage/.../sysroot, but this caused issues with mount
# path canonicalization. Instead, directly mount the physical
# device at two different paths.
dest = iutil.getSysroot() + "/sysroot"
self._safeExecWithRedirect("mount",
[storage.root_device.format.device, dest])
self._internal_mounts.append(dest)

# Now, ensure that all other potential mount point directories such as
# (/home) are created. We run through the full tmpfiles here in order
# to also allow Anaconda and %post scripts to write to directories like
Expand Down

0 comments on commit 664ef7b

Please sign in to comment.