From 3874b4e626852c42fefc32b4aa1ae93e58958233 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 6 May 2022 04:07:41 +0200 Subject: [PATCH] chroot: cleanups, initialize(): unmount everything except / before create_rootfs() --- chroot/__init__.py | 2 -- chroot/abstract.py | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/chroot/__init__.py b/chroot/__init__.py index fd29de4..f01ce48 100644 --- a/chroot/__init__.py +++ b/chroot/__init__.py @@ -8,7 +8,6 @@ from wrapper import enforce_wrap from .abstract import Chroot from .base import get_base_chroot from .build import get_build_chroot, BuildChroot -#from .device import get_device_chroot, DeviceChroot from .helpers import get_chroot_path # export Chroot class @@ -59,4 +58,3 @@ def cmd_chroot(type: str = 'build', arch: str = None, enable_crossdirect=True): chroot.activate() logging.debug(f'Starting shell in {chroot.name}:') chroot.run_cmd('bash', attach_tty=True) - chroot.run_cmd('bash', attach_tty=True) diff --git a/chroot/abstract.py b/chroot/abstract.py index d1c0030..017259e 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -116,11 +116,12 @@ class Chroot(AbstractChroot): if self.initialized and not reset: # chroot must have been initialized already! if fail_if_initialized: - raise Exception(f"Chroot {self.name} is already initialized, this seems like a bug") + raise Exception(f"Chroot {self.name} ({self.uuid}) is already initialized, this seems like a bug") + logging.debug(f"Base chroot {self.name} ({self.uuid}) already initialized") return active_previously = self.active - self.deactivate_core() + self.deactivate(fail_if_inactive=False, ignore_rootfs=True) self.create_rootfs(reset, pacman_conf_target, active_previously) @@ -203,11 +204,11 @@ class Chroot(AbstractChroot): # additional mounts like crossdirect are intentionally left intact. Is such a chroot still `active` afterwards? self.active = False - def deactivate(self, fail_if_inactive: bool = False): + def deactivate(self, fail_if_inactive: bool = False, ignore_rootfs: bool = False): if not self.active: if fail_if_inactive: raise Exception(f"Chroot {self.name} not activated, can't deactivate!") - self.umount_many(self.active_mounts) + self.umount_many([mnt for mnt in self.active_mounts if mnt != '/' or not ignore_rootfs]) self.active = False def run_cmd(