Added creating and mounting of subvolume structure for BTRFS.

This commit is contained in:
Anton Hvornum 2021-10-30 11:00:22 +02:00
parent 68b891837c
commit 76dc426a0f
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
4 changed files with 25 additions and 12 deletions

View File

@ -23,7 +23,9 @@ def mount_subvolume(installation, location :Union[pathlib.Path, str], force=Fals
raise DiskError(f"Cannot mount subvolume to {installation.target/location} because it contains data (non-empty folder target)")
# Mount the logical volume to the physical structure
return SysCommand(f"mount {get_mount_info(installation.target/location)['source']} {installation.target}/{str(location)} -o subvol=@/{str(location)}").exit_code == 0
mount_location = get_mount_info(installation.target/location)['source']
SysCommand(f"umount {mount_location}")
return SysCommand(f"mount {mount_location} {installation.target}/{str(location)} -o subvol=@/{str(location)}").exit_code == 0
def create_subvolume(installation, location :Union[pathlib.Path, str]) -> bool:
"""

View File

@ -132,6 +132,7 @@ class Filesystem:
def raw_parted(self, string: str):
if (cmd_handle := SysCommand(f'/usr/bin/parted -s {string}')).exit_code != 0:
log(f"Parted ended with a bad exit code: {cmd_handle}", level=logging.ERROR, fg="red")
time.sleep(0.5)
return cmd_handle
def parted(self, string: str):

View File

@ -41,18 +41,21 @@ def suggest_single_disk_layout(block_device, default_filesystem=None):
}
})
if default_filesystem == 'btrfs' and input('Would you like to use BTRFS subvolumes? (Y/n)').strip().lower() in ('', 'y', 'yes'):
# https://btrfs.wiki.kernel.org/index.php/FAQ
# https://unix.stackexchange.com/questions/246976/btrfs-subvolume-uuid-clash
# https://github.com/classy-giraffe/easy-arch/blob/main/easy-arch.sh
layout[block_device.path]['partitions'][1]['btrfs'] = {
"subvolumes" : {
'@home' : '/home',
'@log' : '/var/log',
'@pkgs' : '/var/cache/pacman/pkg',
'@.snapshots' : '/.snapshots'
if default_filesystem == 'btrfs' and input('Would you like to use BTRFS subvolumes? (Y/n): ').strip().lower() in ('', 'y', 'yes'):
if input('Do you want to use a recommended structure? (Y/n): ').strip().lower() in ('', 'y', 'yes'):
# https://btrfs.wiki.kernel.org/index.php/FAQ
# https://unix.stackexchange.com/questions/246976/btrfs-subvolume-uuid-clash
# https://github.com/classy-giraffe/easy-arch/blob/main/easy-arch.sh
layout[block_device.path]['partitions'][1]['btrfs'] = {
"subvolumes" : {
'@home' : '/home',
'@log' : '/var/log',
'@pkgs' : '/var/cache/pacman/pkg',
'@.snapshots' : '/.snapshots'
}
}
}
else:
pass #... implement a guided setup
elif block_device.size >= MIN_SIZE_TO_ALLOW_HOME_PART:
# If we don't want to use subvolumes,

View File

@ -5,6 +5,7 @@ from .mirrors import *
from .plugins import plugins
from .storage import storage
from .user_interaction import *
from .disk.btrfs import create_subvolume, mount_subvolume
# Any package that the Installer() is responsible for (optional and the default ones)
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
@ -139,9 +140,15 @@ class Installer:
password = mountpoints[mountpoint]['password']
with luks2(mountpoints[mountpoint]['device_instance'], loopdev, password, auto_unmount=False) as unlocked_device:
unlocked_device.mount(f"{self.target}{mountpoint}")
else:
mountpoints[mountpoint]['device_instance'].mount(f"{self.target}{mountpoint}")
if (subvolumes := mountpoints[mountpoint].get('btrfs', {}).get('subvolumes', {})):
for name, location in subvolumes.items():
create_subvolume(self, location)
mount_subvolume(self, location)
def mount(self, partition, mountpoint, create_mountpoint=True):
if create_mountpoint and not os.path.isdir(f'{self.target}{mountpoint}'):
os.makedirs(f'{self.target}{mountpoint}')