include image size in flavour, centralise fs resizing in image.py

This commit is contained in:
InsanePrawn 2021-09-30 05:04:42 +02:00
parent a3d85cda8c
commit 81f22e67ae
3 changed files with 30 additions and 23 deletions

View file

@ -29,14 +29,15 @@ DEVICES = {
FLAVOURS = { FLAVOURS = {
'barebone': { 'barebone': {
'packages': [] 'packages': [],
}, },
'debug-shell': { 'debug-shell': {
'packages': ['hook-debug-shell'] 'packages': ['hook-debug-shell'],
}, },
'gnome': { 'gnome': {
'packages': ['gnome', 'archlinux-appstream-data', 'gnome-software-packagekit-plugin'], 'packages': ['gnome', 'archlinux-appstream-data', 'gnome-software-packagekit-plugin'],
'post_cmds': ['systemctl enable gdm'] 'post_cmds': ['systemctl enable gdm'],
'size': 8,
}, },
} }

View file

@ -8,6 +8,7 @@ import subprocess
import click import click
import tempfile import tempfile
from wrapper import enforce_wrap from wrapper import enforce_wrap
from image import resize_fs
BOOTIMG = FLASH_PARTS['BOOTIMG'] BOOTIMG = FLASH_PARTS['BOOTIMG']
LK2ND = FLASH_PARTS['LK2ND'] LK2ND = FLASH_PARTS['LK2ND']
@ -58,21 +59,7 @@ def cmd_flash(what, location):
shutil.copyfile(image_name, image_path) shutil.copyfile(image_name, image_path)
result = subprocess.run([ resize_fs(image_path, shrink=True)
'e2fsck',
'-fy',
image_path,
])
if result.returncode != 0:
raise Exception(f'Failed to e2fsck {image_path}')
result = subprocess.run([
'resize2fs',
'-M',
image_path,
])
if result.returncode != 0:
raise Exception(f'Failed to resize2fs {image_path}')
if location.endswith('-file'): if location.endswith('-file'):
part_mount = '/mnt/kupfer/fs' part_mount = '/mnt/kupfer/fs'

View file

@ -11,6 +11,24 @@ from wrapper import enforce_wrap
from signal import pause from signal import pause
def resize_fs(image_path: str, shrink: bool = False):
result = subprocess.run([
'e2fsck',
'-fy',
image_path,
])
if result.returncode != 0:
msg = f'Failed to e2fsck {image_path}'
if shrink:
raise Exception(msg)
else:
logging.warning(msg)
result = subprocess.run(['resize2fs'] + (['-MP'] if shrink else []) + [image_path])
if result.returncode != 0:
raise Exception(f'Failed to resize2fs {image_path}')
def get_device_and_flavour(profile: str = None) -> tuple[str, str]: def get_device_and_flavour(profile: str = None) -> tuple[str, str]:
#config.enforce_config_loaded() #config.enforce_config_loaded()
profile = config.get_profile(profile) profile = config.get_profile(profile)
@ -120,12 +138,11 @@ def cmd_build():
result = subprocess.run([ result = subprocess.run([
'fallocate', 'fallocate',
'-l', '-l',
'4G', f"{FLAVOURS[flavour].get('size',4)}G",
image_name, image_name,
]) ])
if result.returncode != 0: if result.returncode != 0:
logging.fatal(f'Failed to allocate {image_name}') raise Exception(f'Failed to allocate {image_name}')
exit(1)
result = subprocess.run([ result = subprocess.run([
'mkfs.ext4', 'mkfs.ext4',
@ -134,8 +151,10 @@ def cmd_build():
image_name, image_name,
]) ])
if result.returncode != 0: if result.returncode != 0:
logging.fatal(f'Failed to create ext4 filesystem on {image_name}') raise Exception(f'Failed to create ext4 filesystem on {image_name}')
exit(1) else:
resize_fs(image_path=image_name)
chroot_name = f'rootfs_{device}-{flavour}' chroot_name = f'rootfs_{device}-{flavour}'
rootfs_mount = get_chroot_path(chroot_name) rootfs_mount = get_chroot_path(chroot_name)
mount_rootfs_image(image_name, rootfs_mount) mount_rootfs_image(image_name, rootfs_mount)