disk: add support for creating swap partitions (#3129)
This commit is contained in:
parent
8d923ff09e
commit
19c390e072
|
|
@ -151,6 +151,8 @@ class DeviceHandler:
|
||||||
) -> FilesystemType | None:
|
) -> FilesystemType | None:
|
||||||
try:
|
try:
|
||||||
if partition.fileSystem:
|
if partition.fileSystem:
|
||||||
|
if partition.fileSystem.type == FilesystemType.LinuxSwap.parted_value:
|
||||||
|
return FilesystemType.LinuxSwap
|
||||||
return FilesystemType(partition.fileSystem.type)
|
return FilesystemType(partition.fileSystem.type)
|
||||||
elif lsblk_info is not None:
|
elif lsblk_info is not None:
|
||||||
return FilesystemType(lsblk_info.fstype) if lsblk_info.fstype else None
|
return FilesystemType(lsblk_info.fstype) if lsblk_info.fstype else None
|
||||||
|
|
@ -259,6 +261,7 @@ class DeviceHandler:
|
||||||
additional_parted_options: list[str] = []
|
additional_parted_options: list[str] = []
|
||||||
) -> None:
|
) -> None:
|
||||||
mkfs_type = fs_type.value
|
mkfs_type = fs_type.value
|
||||||
|
command = None
|
||||||
options = []
|
options = []
|
||||||
|
|
||||||
match fs_type:
|
match fs_type:
|
||||||
|
|
@ -277,10 +280,15 @@ class DeviceHandler:
|
||||||
options.append('--fast')
|
options.append('--fast')
|
||||||
case FilesystemType.Reiserfs:
|
case FilesystemType.Reiserfs:
|
||||||
pass
|
pass
|
||||||
|
case FilesystemType.LinuxSwap:
|
||||||
|
command = "mkswap"
|
||||||
case _:
|
case _:
|
||||||
raise UnknownFilesystemFormat(f'Filetype "{fs_type.value}" is not supported')
|
raise UnknownFilesystemFormat(f'Filetype "{fs_type.value}" is not supported')
|
||||||
|
|
||||||
cmd = [f'mkfs.{mkfs_type}', *options, *additional_parted_options, str(path)]
|
if not command:
|
||||||
|
command = f'mkfs.{mkfs_type}'
|
||||||
|
|
||||||
|
cmd = [command, *options, *additional_parted_options, str(path)]
|
||||||
|
|
||||||
debug('Formatting filesystem:', ' '.join(cmd))
|
debug('Formatting filesystem:', ' '.join(cmd))
|
||||||
|
|
||||||
|
|
@ -536,7 +544,8 @@ class DeviceHandler:
|
||||||
length=length_sector.value
|
length=length_sector.value
|
||||||
)
|
)
|
||||||
|
|
||||||
filesystem = FileSystem(type=part_mod.safe_fs_type.value, geometry=geometry)
|
fs_value = part_mod.safe_fs_type.parted_value
|
||||||
|
filesystem = FileSystem(type=fs_value, geometry=geometry)
|
||||||
|
|
||||||
partition = Partition(
|
partition = Partition(
|
||||||
disk=disk,
|
disk=disk,
|
||||||
|
|
@ -549,7 +558,7 @@ class DeviceHandler:
|
||||||
partition.setFlag(flag.flag_id)
|
partition.setFlag(flag.flag_id)
|
||||||
|
|
||||||
debug(f'\tType: {part_mod.type.value}')
|
debug(f'\tType: {part_mod.type.value}')
|
||||||
debug(f'\tFilesystem: {part_mod.safe_fs_type.value}')
|
debug(f'\tFilesystem: {fs_value}')
|
||||||
debug(f'\tGeometry: {start_sector.value} start sector, {length_sector.value} length')
|
debug(f'\tGeometry: {start_sector.value} start sector, {length_sector.value} length')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -723,6 +732,13 @@ class DeviceHandler:
|
||||||
|
|
||||||
disk.commit()
|
disk.commit()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def swapon(path: Path) -> None:
|
||||||
|
try:
|
||||||
|
SysCommand(['swapon', str(path)])
|
||||||
|
except SysCallError as err:
|
||||||
|
raise DiskError(f'Could not enable swap {path}:\n{err.message}')
|
||||||
|
|
||||||
def mount(
|
def mount(
|
||||||
self,
|
self,
|
||||||
dev_path: Path,
|
dev_path: Path,
|
||||||
|
|
|
||||||
|
|
@ -728,6 +728,7 @@ class PartitionFlag(PartitionFlagDataMixin, Enum):
|
||||||
XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot"
|
XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot"
|
||||||
ESP = parted.PARTITION_ESP
|
ESP = parted.PARTITION_ESP
|
||||||
LINUX_HOME = parted.PARTITION_LINUX_HOME, "linux-home"
|
LINUX_HOME = parted.PARTITION_LINUX_HOME, "linux-home"
|
||||||
|
SWAP = parted.PARTITION_SWAP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
|
|
@ -767,6 +768,7 @@ class FilesystemType(Enum):
|
||||||
Ntfs = 'ntfs'
|
Ntfs = 'ntfs'
|
||||||
Reiserfs = 'reiserfs'
|
Reiserfs = 'reiserfs'
|
||||||
Xfs = 'xfs'
|
Xfs = 'xfs'
|
||||||
|
LinuxSwap = 'linux-swap'
|
||||||
|
|
||||||
# this is not a FS known to parted, so be careful
|
# this is not a FS known to parted, so be careful
|
||||||
# with the usage from this enum
|
# with the usage from this enum
|
||||||
|
|
@ -785,6 +787,10 @@ class FilesystemType(Enum):
|
||||||
case _:
|
case _:
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parted_value(self) -> str:
|
||||||
|
return self.value + '(v1)' if self == FilesystemType.LinuxSwap else self.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def installation_pkg(self) -> str | None:
|
def installation_pkg(self) -> str | None:
|
||||||
match self:
|
match self:
|
||||||
|
|
@ -969,6 +975,9 @@ class PartitionModification:
|
||||||
or PartitionFlag.LINUX_HOME in self.flags
|
or PartitionFlag.LINUX_HOME in self.flags
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def is_swap(self) -> bool:
|
||||||
|
return self.fs_type == FilesystemType.LinuxSwap
|
||||||
|
|
||||||
def is_modify(self) -> bool:
|
def is_modify(self) -> bool:
|
||||||
return self.status == ModificationStatus.Modify
|
return self.status == ModificationStatus.Modify
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,10 @@ def select_partitions_to_encrypt(
|
||||||
|
|
||||||
# do not allow encrypting the boot partition
|
# do not allow encrypting the boot partition
|
||||||
for mod in modification:
|
for mod in modification:
|
||||||
partitions += [p for p in mod.partitions if p.mountpoint != Path('/boot')]
|
partitions += [
|
||||||
|
p for p in mod.partitions
|
||||||
|
if p.mountpoint != Path('/boot') and not p.is_swap()
|
||||||
|
]
|
||||||
|
|
||||||
# do not allow encrypting existing partitions that are not marked as wipe
|
# do not allow encrypting existing partitions that are not marked as wipe
|
||||||
avail_partitions = [p for p in partitions if not p.exists()]
|
avail_partitions = [p for p in partitions if not p.exists()]
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,7 @@ class PartitioningList(ListManager):
|
||||||
fs_type = self._prompt_partition_fs_type()
|
fs_type = self._prompt_partition_fs_type()
|
||||||
|
|
||||||
mountpoint = None
|
mountpoint = None
|
||||||
if fs_type != FilesystemType.Btrfs:
|
if fs_type not in (FilesystemType.Btrfs, FilesystemType.LinuxSwap):
|
||||||
mountpoint = self._prompt_mountpoint()
|
mountpoint = self._prompt_mountpoint()
|
||||||
|
|
||||||
partition = PartitionModification(
|
partition = PartitionModification(
|
||||||
|
|
@ -486,6 +486,8 @@ class PartitioningList(ListManager):
|
||||||
partition.set_flag(PartitionFlag.BOOT)
|
partition.set_flag(PartitionFlag.BOOT)
|
||||||
if self._using_gpt:
|
if self._using_gpt:
|
||||||
partition.set_flag(PartitionFlag.ESP)
|
partition.set_flag(PartitionFlag.ESP)
|
||||||
|
elif partition.is_swap():
|
||||||
|
partition.set_flag(PartitionFlag.SWAP)
|
||||||
|
|
||||||
return partition
|
return partition
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -315,17 +315,21 @@ class Installer:
|
||||||
}
|
}
|
||||||
|
|
||||||
def _mount_partition(self, part_mod: disk.PartitionModification) -> None:
|
def _mount_partition(self, part_mod: disk.PartitionModification) -> None:
|
||||||
|
if not part_mod.dev_path:
|
||||||
|
return
|
||||||
|
|
||||||
# it would be none if it's btrfs as the subvolumes will have the mountpoints defined
|
# it would be none if it's btrfs as the subvolumes will have the mountpoints defined
|
||||||
if part_mod.mountpoint and part_mod.dev_path:
|
if part_mod.mountpoint:
|
||||||
target = self.target / part_mod.relative_mountpoint
|
target = self.target / part_mod.relative_mountpoint
|
||||||
disk.device_handler.mount(part_mod.dev_path, target, options=part_mod.mount_options)
|
disk.device_handler.mount(part_mod.dev_path, target, options=part_mod.mount_options)
|
||||||
|
elif part_mod.fs_type == disk.FilesystemType.Btrfs:
|
||||||
if part_mod.fs_type == disk.FilesystemType.Btrfs and part_mod.dev_path:
|
|
||||||
self._mount_btrfs_subvol(
|
self._mount_btrfs_subvol(
|
||||||
part_mod.dev_path,
|
part_mod.dev_path,
|
||||||
part_mod.btrfs_subvols,
|
part_mod.btrfs_subvols,
|
||||||
part_mod.mount_options
|
part_mod.mount_options
|
||||||
)
|
)
|
||||||
|
elif part_mod.is_swap():
|
||||||
|
disk.device_handler.swapon(part_mod.dev_path)
|
||||||
|
|
||||||
def _mount_lvm_vol(self, volume: disk.LvmVolume) -> None:
|
def _mount_lvm_vol(self, volume: disk.LvmVolume) -> None:
|
||||||
if volume.fs_type != disk.FilesystemType.Btrfs:
|
if volume.fs_type != disk.FilesystemType.Btrfs:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue