include image size in flavour, centralise fs resizing in image.py
This commit is contained in:
parent
a3d85cda8c
commit
81f22e67ae
3 changed files with 30 additions and 23 deletions
|
@ -29,14 +29,15 @@ DEVICES = {
|
|||
|
||||
FLAVOURS = {
|
||||
'barebone': {
|
||||
'packages': []
|
||||
'packages': [],
|
||||
},
|
||||
'debug-shell': {
|
||||
'packages': ['hook-debug-shell']
|
||||
'packages': ['hook-debug-shell'],
|
||||
},
|
||||
'gnome': {
|
||||
'packages': ['gnome', 'archlinux-appstream-data', 'gnome-software-packagekit-plugin'],
|
||||
'post_cmds': ['systemctl enable gdm']
|
||||
'post_cmds': ['systemctl enable gdm'],
|
||||
'size': 8,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
17
flash.py
17
flash.py
|
@ -8,6 +8,7 @@ import subprocess
|
|||
import click
|
||||
import tempfile
|
||||
from wrapper import enforce_wrap
|
||||
from image import resize_fs
|
||||
|
||||
BOOTIMG = FLASH_PARTS['BOOTIMG']
|
||||
LK2ND = FLASH_PARTS['LK2ND']
|
||||
|
@ -58,21 +59,7 @@ def cmd_flash(what, location):
|
|||
|
||||
shutil.copyfile(image_name, image_path)
|
||||
|
||||
result = subprocess.run([
|
||||
'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}')
|
||||
resize_fs(image_path, shrink=True)
|
||||
|
||||
if location.endswith('-file'):
|
||||
part_mount = '/mnt/kupfer/fs'
|
||||
|
|
29
image.py
29
image.py
|
@ -11,6 +11,24 @@ from wrapper import enforce_wrap
|
|||
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]:
|
||||
#config.enforce_config_loaded()
|
||||
profile = config.get_profile(profile)
|
||||
|
@ -120,12 +138,11 @@ def cmd_build():
|
|||
result = subprocess.run([
|
||||
'fallocate',
|
||||
'-l',
|
||||
'4G',
|
||||
f"{FLAVOURS[flavour].get('size',4)}G",
|
||||
image_name,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to allocate {image_name}')
|
||||
exit(1)
|
||||
raise Exception(f'Failed to allocate {image_name}')
|
||||
|
||||
result = subprocess.run([
|
||||
'mkfs.ext4',
|
||||
|
@ -134,8 +151,10 @@ def cmd_build():
|
|||
image_name,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to create ext4 filesystem on {image_name}')
|
||||
exit(1)
|
||||
raise Exception(f'Failed to create ext4 filesystem on {image_name}')
|
||||
else:
|
||||
resize_fs(image_path=image_name)
|
||||
|
||||
chroot_name = f'rootfs_{device}-{flavour}'
|
||||
rootfs_mount = get_chroot_path(chroot_name)
|
||||
mount_rootfs_image(image_name, rootfs_mount)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue