From 9c77e2ffe3763b2beb8a98e319b5c7c7c3c9b0e9 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 6 Jan 2023 05:50:56 +0100 Subject: [PATCH 1/3] chroot: detect existing root mounts better --- chroot/base.py | 7 +++---- chroot/device.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chroot/base.py b/chroot/base.py index 37ed943..48fdea3 100644 --- a/chroot/base.py +++ b/chroot/base.py @@ -2,12 +2,11 @@ import logging import os from glob import glob -from shutil import rmtree from typing import ClassVar from constants import Arch from exec.cmd import run_root_cmd -from exec.file import makedir, root_makedir +from exec.file import makedir, remove_file, root_makedir from config.state import config from .abstract import Chroot, get_chroot @@ -19,10 +18,10 @@ class BaseChroot(Chroot): _copy_base: ClassVar[bool] = False def create_rootfs(self, reset, pacman_conf_target, active_previously): - if reset: + if reset and os.path.exists(self.path): logging.info(f'Resetting {self.name}') for dir in glob(os.path.join(self.path, '*')): - rmtree(dir) + remove_file(dir, recursive=True) makedir(config.get_path('chroots')) root_makedir(self.get_path()) diff --git a/chroot/device.py b/chroot/device.py index bd04467..25730d0 100644 --- a/chroot/device.py +++ b/chroot/device.py @@ -42,7 +42,7 @@ class DeviceChroot(BuildChroot): really_active.append(mnt) if really_active: raise Exception(f'{self.name}: Chroot has submounts active: {really_active}') - if os.path.ismount(self.path): + if os.path.ismount(self.path) or check_findmnt(self.path): raise Exception(f'{self.name}: There is already something mounted at {self.path}, not mounting over it.') if os.path.exists(os.path.join(self.path, 'usr/bin')): raise Exception(f'{self.name}: {self.path}/usr/bin exists, not mounting over existing rootfs.') From 9e1348cbce99f00ca1f14be61bb7df43e66f7521 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 6 Jan 2023 05:51:34 +0100 Subject: [PATCH 2/3] chroot/abstract: initialize(): if nothing is mounted at /, bind-mount over itself --- chroot/abstract.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chroot/abstract.py b/chroot/abstract.py index 9c10d83..c94b0fb 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -123,7 +123,11 @@ class Chroot(AbstractChroot): active_previously = self.active self.deactivate(fail_if_inactive=False, ignore_rootfs=True) - + if not (os.path.ismount(self.path) or check_findmnt(self.path)): + makedir(os.path.dirname(self.path)) + root_makedir(self.path) + logging.debug(f"Bind-mounting {self.name} ({self.uuid}) over itself") # needed for pacman space calculation + self.mount(self.path, '/', options=['rbind']) self.create_rootfs(reset, pacman_conf_target, active_previously) def get_path(self, *joins: str) -> str: From 21bf0cf29337431d501797085431cd4053d99998 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 6 Jan 2023 05:59:38 +0100 Subject: [PATCH 3/3] config/state: re-enable pacman checkspace now that chroots bind-mount themselfes --- config/state.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/state.py b/config/state.py index 0395baa..d0e1f54 100644 --- a/config/state.py +++ b/config/state.py @@ -31,7 +31,7 @@ CONFIG_DEFAULTS_DICT = { }, 'pacman': { 'parallel_downloads': 4, - 'check_space': False, # TODO: investigate why True causes issues + 'check_space': True, 'repo_branch': DEFAULT_PACKAGE_BRANCH, }, 'paths': {