mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-25 13:35:09 +03:00
Revert "chroot: allow mounting the device rootfs (MR 2252)"
This reverts commit f331b95824
.
This commit is contained in:
parent
feae3c8a20
commit
393f7e3616
7 changed files with 10 additions and 64 deletions
|
@ -1,6 +1,5 @@
|
||||||
# Copyright 2023 Oliver Smith
|
# Copyright 2023 Oliver Smith
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
from pmb.core.chroot import ChrootType
|
|
||||||
from pmb.core.pkgrepo import pkgrepo_default_path
|
from pmb.core.pkgrepo import pkgrepo_default_path
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
import os
|
import os
|
||||||
|
@ -8,40 +7,12 @@ from pathlib import Path
|
||||||
import pmb.chroot.binfmt
|
import pmb.chroot.binfmt
|
||||||
import pmb.config
|
import pmb.config
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
import pmb.install.losetup
|
|
||||||
import pmb.helpers.mount
|
import pmb.helpers.mount
|
||||||
from pmb.core import Chroot
|
from pmb.core import Chroot
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
from pmb.init import sandbox
|
from pmb.init import sandbox
|
||||||
|
|
||||||
|
|
||||||
def mount_chroot_image(chroot: Chroot) -> None:
|
|
||||||
"""Mount an IMAGE type chroot, to modify an existing rootfs image. This
|
|
||||||
doesn't support split images yet!"""
|
|
||||||
# Make sure everything is nicely unmounted just to be super safe
|
|
||||||
# this is definitely overkill
|
|
||||||
pmb.chroot.shutdown()
|
|
||||||
pmb.install.losetup.detach_all()
|
|
||||||
|
|
||||||
chroot_native = Chroot.native()
|
|
||||||
pmb.chroot.init(chroot_native)
|
|
||||||
|
|
||||||
loopdev = pmb.install.losetup.mount(
|
|
||||||
Path("/") / Path(chroot.name).relative_to(chroot_native.path)
|
|
||||||
)
|
|
||||||
pmb.helpers.mount.bind_file(loopdev, chroot_native / "dev/install")
|
|
||||||
# Set up device mapper bits
|
|
||||||
pmb.chroot.root(["kpartx", "-u", "/dev/install"], chroot_native)
|
|
||||||
chroot.path.mkdir(exist_ok=True)
|
|
||||||
# # The name of the IMAGE chroot is the path to the rootfs image
|
|
||||||
pmb.helpers.run.root(["mount", "/dev/mapper/install2", chroot.path])
|
|
||||||
pmb.helpers.run.root(["mount", "/dev/mapper/install1", chroot.path / "boot"])
|
|
||||||
|
|
||||||
pmb.config.workdir.chroot_save_init(chroot)
|
|
||||||
|
|
||||||
logging.info(f"({chroot}) mounted {chroot.name}")
|
|
||||||
|
|
||||||
|
|
||||||
def mount_dev_tmpfs(chroot: Chroot = Chroot.native()) -> None:
|
def mount_dev_tmpfs(chroot: Chroot = Chroot.native()) -> None:
|
||||||
"""
|
"""
|
||||||
Mount tmpfs inside the chroot's dev folder to make sure we can create
|
Mount tmpfs inside the chroot's dev folder to make sure we can create
|
||||||
|
@ -59,12 +30,7 @@ def mount_dev_tmpfs(chroot: Chroot = Chroot.native()) -> None:
|
||||||
devop.execute("/", str(chroot.path))
|
devop.execute("/", str(chroot.path))
|
||||||
|
|
||||||
|
|
||||||
def mount(chroot: Chroot) -> None:
|
def mount(chroot: Chroot):
|
||||||
if chroot.type == ChrootType.IMAGE and not pmb.mount.ismount(chroot.path):
|
|
||||||
mount_chroot_image(chroot)
|
|
||||||
|
|
||||||
if not chroot.path.exists():
|
|
||||||
os.mkdir(str(chroot.path))
|
|
||||||
# Mount tmpfs as the chroot's /dev
|
# Mount tmpfs as the chroot's /dev
|
||||||
mount_dev_tmpfs(chroot)
|
mount_dev_tmpfs(chroot)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ class ChrootType(enum.Enum):
|
||||||
BUILDROOT = "buildroot"
|
BUILDROOT = "buildroot"
|
||||||
INSTALLER = "installer"
|
INSTALLER = "installer"
|
||||||
NATIVE = "native"
|
NATIVE = "native"
|
||||||
IMAGE = "image"
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -58,15 +57,12 @@ class Chroot:
|
||||||
if self.__type == ChrootType.NATIVE and self.__name != "":
|
if self.__type == ChrootType.NATIVE and self.__name != "":
|
||||||
raise ValueError(f"The native suffix can't have a name but got: '{self.__name}'")
|
raise ValueError(f"The native suffix can't have a name but got: '{self.__name}'")
|
||||||
|
|
||||||
if self.__type == ChrootType.IMAGE and not Path(self.__name).exists():
|
|
||||||
raise ValueError(f"Image file '{self.__name}' does not exist")
|
|
||||||
|
|
||||||
# rootfs suffixes must have a valid device name
|
# rootfs suffixes must have a valid device name
|
||||||
if self.__type == ChrootType.ROOTFS and (len(self.__name) < 3 or "-" not in self.__name):
|
if self.__type == ChrootType.ROOTFS and (len(self.__name) < 3 or "-" not in self.__name):
|
||||||
raise ValueError(f"Invalid device name: '{self.__name}'")
|
raise ValueError(f"Invalid device name: '{self.__name}'")
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
if len(self.__name) > 0 and self.type != ChrootType.IMAGE:
|
if len(self.__name) > 0:
|
||||||
return f"{self.__type.value}_{self.__name}"
|
return f"{self.__type.value}_{self.__name}"
|
||||||
else:
|
else:
|
||||||
return self.__type.value
|
return self.__type.value
|
||||||
|
|
|
@ -66,14 +66,11 @@ def _parse_flavor(device: str, autoinstall: bool = True) -> str:
|
||||||
|
|
||||||
def _parse_suffix(args: PmbArgs) -> Chroot:
|
def _parse_suffix(args: PmbArgs) -> Chroot:
|
||||||
deviceinfo = pmb.parse.deviceinfo()
|
deviceinfo = pmb.parse.deviceinfo()
|
||||||
if getattr(args, "image", None):
|
|
||||||
rootfs = Chroot.native() / f"home/pmos/rootfs/{deviceinfo.codename}.img"
|
|
||||||
return Chroot(ChrootType.IMAGE, str(rootfs))
|
|
||||||
if getattr(args, "rootfs", None):
|
if getattr(args, "rootfs", None):
|
||||||
return Chroot(ChrootType.ROOTFS, get_context().config.device)
|
return Chroot(ChrootType.ROOTFS, get_context().config.device)
|
||||||
elif args.buildroot:
|
elif args.buildroot:
|
||||||
if args.buildroot == "device":
|
if args.buildroot == "device":
|
||||||
return Chroot.buildroot(deviceinfo.arch)
|
return Chroot.buildroot(pmb.parse.deviceinfo().arch)
|
||||||
else:
|
else:
|
||||||
return Chroot.buildroot(Arch.from_str(args.buildroot))
|
return Chroot.buildroot(Arch.from_str(args.buildroot))
|
||||||
elif args.suffix:
|
elif args.suffix:
|
||||||
|
@ -145,18 +142,11 @@ def chroot(args: PmbArgs) -> None:
|
||||||
# Suffix
|
# Suffix
|
||||||
chroot = _parse_suffix(args)
|
chroot = _parse_suffix(args)
|
||||||
user = args.user
|
user = args.user
|
||||||
if (
|
if user and chroot != Chroot.native() and chroot.type != ChrootType.BUILDROOT:
|
||||||
user
|
|
||||||
and chroot != Chroot.native()
|
|
||||||
and chroot.type not in [ChrootType.BUILDROOT, ChrootType.IMAGE]
|
|
||||||
):
|
|
||||||
raise RuntimeError("--user is only supported for native or buildroot_* chroots.")
|
raise RuntimeError("--user is only supported for native or buildroot_* chroots.")
|
||||||
if args.xauth and chroot != Chroot.native():
|
if args.xauth and chroot != Chroot.native():
|
||||||
raise RuntimeError("--xauth is only supported for native chroot.")
|
raise RuntimeError("--xauth is only supported for native chroot.")
|
||||||
|
|
||||||
if chroot.type == ChrootType.IMAGE:
|
|
||||||
pmb.chroot.mount(chroot)
|
|
||||||
|
|
||||||
# apk: check minimum version, install packages
|
# apk: check minimum version, install packages
|
||||||
pmb.chroot.apk.check_min_version(chroot)
|
pmb.chroot.apk.check_min_version(chroot)
|
||||||
if args.add:
|
if args.add:
|
||||||
|
|
|
@ -48,6 +48,11 @@ def mount(img_path: Path, _sector_size: int | None = None) -> Path:
|
||||||
losetup_cmd += ["-b", str(int(sector_size))]
|
losetup_cmd += ["-b", str(int(sector_size))]
|
||||||
|
|
||||||
pmb.chroot.root(losetup_cmd, check=False)
|
pmb.chroot.root(losetup_cmd, check=False)
|
||||||
|
try:
|
||||||
|
device_by_back_file(img_path)
|
||||||
|
return
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return device_by_back_file(img_path)
|
return device_by_back_file(img_path)
|
||||||
|
@ -100,6 +105,5 @@ def detach_all() -> None:
|
||||||
work = get_context().config.work
|
work = get_context().config.work
|
||||||
for loopdevice in losetup["loopdevices"]:
|
for loopdevice in losetup["loopdevices"]:
|
||||||
if Path(loopdevice["back-file"]).is_relative_to(work):
|
if Path(loopdevice["back-file"]).is_relative_to(work):
|
||||||
pmb.helpers.run.root(["kpartx", "-d", loopdevice["name"]], check=False)
|
pmb.chroot.root(["losetup", "-d", loopdevice["name"]])
|
||||||
pmb.helpers.run.root(["losetup", "-d", loopdevice["name"]])
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -1040,11 +1040,6 @@ def get_parser() -> argparse.ArgumentParser:
|
||||||
" 'background'. Details: pmb/helpers/run_core.py",
|
" 'background'. Details: pmb/helpers/run_core.py",
|
||||||
default="tui",
|
default="tui",
|
||||||
)
|
)
|
||||||
chroot.add_argument(
|
|
||||||
"--image",
|
|
||||||
help="Mount the rootfs image and treat it like a normal chroot.",
|
|
||||||
action="store_true",
|
|
||||||
)
|
|
||||||
chroot.add_argument(
|
chroot.add_argument(
|
||||||
"--usb",
|
"--usb",
|
||||||
help="Make USB devices accessible inside the chroot.",
|
help="Make USB devices accessible inside the chroot.",
|
||||||
|
|
|
@ -419,10 +419,6 @@ def run(args: PmbArgs) -> None:
|
||||||
)
|
)
|
||||||
arch = pmb.parse.deviceinfo().arch
|
arch = pmb.parse.deviceinfo().arch
|
||||||
|
|
||||||
# Make sure the rootfs image isn't mounted
|
|
||||||
pmb.mount.umount_all(Chroot(ChrootType.IMAGE, "").path)
|
|
||||||
pmb.install.losetup.detach_all()
|
|
||||||
|
|
||||||
img_path = system_image(device)
|
img_path = system_image(device)
|
||||||
img_path_2nd = None
|
img_path_2nd = None
|
||||||
if args.second_storage:
|
if args.second_storage:
|
||||||
|
|
|
@ -161,7 +161,6 @@ class PmbArgs(Namespace):
|
||||||
http: bool
|
http: bool
|
||||||
ignore_depends: bool
|
ignore_depends: bool
|
||||||
image_size: str
|
image_size: str
|
||||||
image: bool
|
|
||||||
install_base: bool
|
install_base: bool
|
||||||
install_blockdev: bool
|
install_blockdev: bool
|
||||||
install_cgpt: bool
|
install_cgpt: bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue