Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for /home reuse to automatic partitioning #5814

Merged
merged 8 commits into from
Oct 10, 2024
53 changes: 53 additions & 0 deletions pyanaconda/modules/common/structures/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self):
self._partitioning_scheme = conf.storage.default_scheme
self._file_system_type = ""
self._excluded_mount_points = []
self._reformatted_mount_points = []
self._reused_mount_points = []
self._removed_mount_points = []
self._hibernation = False

self._encrypted = False
Expand Down Expand Up @@ -113,6 +116,56 @@ def hibernation(self, value: Bool):
def excluded_mount_points(self, mount_points: List[Str]):
self._excluded_mount_points = mount_points

@property
def reformatted_mount_points(self) -> List[Str]:
"""Reformatted mount points.

Reformat and reuse existing devices for the mount points.

For example: /

:return: a list of mount points
"""
return self._reformatted_mount_points

@reformatted_mount_points.setter
def reformatted_mount_points(self, mount_points: List[Str]):
self._reformatted_mount_points = mount_points

@property
def reused_mount_points(self) -> List[Str]:
"""Reused mount points.

Reuse existing devices for the mount points.

For example: /home

:return: a list of mount points
"""
return self._reused_mount_points

@reused_mount_points.setter
def reused_mount_points(self, mount_points: List[Str]):
self._reused_mount_points = mount_points

@property
def removed_mount_points(self) -> List[Str]:
"""Removed mount points.

Destroy the devices for the mount points if they exist.

Supported only for plain partition mount points

For example: /boot

:return: a list of mount points
"""
return self._removed_mount_points

@removed_mount_points.setter
def removed_mount_points(self, mount_points: List[Str]):
self._removed_mount_points = mount_points

@property
def encrypted(self) -> Bool:
"""Should devices be encrypted?
Expand Down
29 changes: 24 additions & 5 deletions pyanaconda/modules/storage/devicetree/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _find_existing_installations(devicetree):
continue

architecture, product, version = get_release_string(chroot=sysroot)
(mounts, devices) = _parse_fstab(devicetree, chroot=sysroot)
(mounts, devices, mountopts) = _parse_fstab(devicetree, chroot=sysroot)
blivet_util.umount(mountpoint=sysroot)

if not mounts and not devices:
Expand All @@ -137,6 +137,7 @@ def _find_existing_installations(devicetree):
arch=architecture,
devices=devices,
mounts=mounts,
mountopts=mountopts,
))

return roots
Expand Down Expand Up @@ -249,16 +250,17 @@ def _parse_fstab(devicetree, chroot):

:param devicetree: a device tree
:param chroot: a path to the target OS installation
:return: a tuple of a mount dict and a device list
:return: a tuple of a mount dict, device list, mount options
"""
mounts = {}
devices = []
mountopts = {}

path = "%s/etc/fstab" % chroot
if not os.access(path, os.R_OK):
# XXX should we raise an exception instead?
log.info("cannot open %s for read", path)
return mounts, devices
return mounts, devices, mountopts

blkid_tab = BlkidTab(chroot=chroot)
try:
Expand Down Expand Up @@ -306,17 +308,18 @@ def _parse_fstab(devicetree, chroot):

if fstype != "swap":
mounts[mountpoint] = device
mountopts[mountpoint] = options

devices.append(device)

return mounts, devices
return mounts, devices, mountopts


class Root(object):
"""A root represents an existing OS installation."""

def __init__(self, name=None, product=None, version=None, arch=None, devices=None,
mounts=None):
mounts=None, mountopts=None):
"""Create a new OS representation.

:param name: a name of the OS or None
Expand All @@ -325,13 +328,15 @@ def __init__(self, name=None, product=None, version=None, arch=None, devices=Non
:param arch: a machine's architecture or None
:param devices: a list of all devices
:param mounts: a dictionary of mount points and devices
:param mountopts: a dictionary of mount points and its mount options
"""
self._name = name
self._product = product
self._version = version
self._arch = arch
self._devices = devices or []
self._mounts = mounts or {}
self._mountopts = mountopts or {}

@property
def name(self):
Expand Down Expand Up @@ -377,6 +382,14 @@ def mounts(self):
"""
return self._mounts

@property
def mountopts(self):
"""Mount point options of mount points defined by the OS.

:return: a dictionary of mount points and their mount options
"""
return self._mountopts

def copy(self, storage):
"""Create a copy with devices of the given storage model.

Expand All @@ -392,6 +405,12 @@ def _get_mount(i):
m, d = i[0], _get_device(i[1])
return (m, d) if m and d else None

def _get_mount_opt(i):
m, d = i[0], _get_device(i[1])
return (m, self._mountopts[m]) if m and d and m in self._mountopts else None

new_root._devices = list(filter(None, map(_get_device, new_root._devices)))
new_root._mounts = dict(filter(None, map(_get_mount, new_root._mounts.items())))
new_root._mountopts = dict(filter(None, map(_get_mount_opt,
new_root._mounts.items())))
return new_root
Loading
Loading