Support new Archiso layout in UFD sections

This commit is contained in:
2Shirt 2021-05-13 21:21:34 -06:00
parent a5b0758d30
commit f3e3483b46
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
4 changed files with 46 additions and 43 deletions

View file

@ -22,9 +22,9 @@ BOOT_ENTRIES = {
'/sources/boot.wim': 'UFD-WINPE', '/sources/boot.wim': 'UFD-WINPE',
} }
BOOT_FILES = { BOOT_FILES = {
# Directory: extension # Directory: extension
'/arch/boot/syslinux': 'cfg', '/syslinux': 'cfg',
'/EFI/boot': 'conf', '/EFI/boot': 'conf',
} }
# Definitions: Sources and Destinations # Definitions: Sources and Destinations
@ -32,34 +32,33 @@ BOOT_FILES = {
## Sources use rsync's trailing slash syntax ## Sources use rsync's trailing slash syntax
ITEMS = { ITEMS = {
'Extra Dir': ( 'Extra Dir': (
('/', '/'), ('/', '/'),
), ),
'Linux': ( 'Linux': (
('/arch', '/'), ('/arch', '/'),
('/isolinux', '/'), ('/EFI/boot', '/EFI/'),
('/EFI/boot', '/EFI/'), ('/syslinux', '/'),
('/EFI/memtest86', '/EFI/'),
), ),
'Linux (Minimal)': ( 'Linux (Minimal)': (
('/arch/boot/x86_64/archiso.img', '/arch_minimal/'), ('/arch/boot/x86_64/initramfs-linux.img', '/arch_minimal/'),
('/arch/boot/x86_64/vmlinuz', '/arch_minimal/'), ('/arch/boot/x86_64/vmlinuz-linux', '/arch_minimal/'),
('/arch/pkglist.x86_64.txt', '/arch_minimal/'), ('/arch/pkglist.x86_64.txt', '/arch_minimal/'),
('/arch/x86_64', '/arch_minimal/'), ('/arch/x86_64', '/arch_minimal/'),
), ),
'Main Kit': ( 'Main Kit': (
('/', f'/{KIT_NAME_FULL}/'), ('/', f'/{KIT_NAME_FULL}/'),
), ),
'WinPE': ( 'WinPE': (
('/bootmgr', '/'), ('/bootmgr', '/'),
('/bootmgr.efi', '/'), ('/bootmgr.efi', '/'),
('/en_us', '/'), ('/en_us', '/'),
('/Boot/', '/boot/'), ('/Boot/', '/boot/'),
('/EFI/Boot/', '/EFI/Microsoft/'), ('/EFI/Boot/', '/EFI/Microsoft/'),
('/EFI/Microsoft/', '/EFI/Microsoft/'), ('/EFI/Microsoft/', '/EFI/Microsoft/'),
('/Boot/BCD', '/sources/'), ('/Boot/BCD', '/sources/'),
('/Boot/boot.sdi', '/sources/'), ('/Boot/boot.sdi', '/sources/'),
('/bootmgr', '/sources/'), ('/bootmgr', '/sources/'),
('/sources/boot.wim', '/sources/'), ('/sources/boot.wim', '/sources/'),
), ),
} }
ITEMS_HIDDEN = ( ITEMS_HIDDEN = (
@ -67,7 +66,7 @@ ITEMS_HIDDEN = (
'arch', 'arch',
'arch_minimal', 'arch_minimal',
'EFI', 'EFI',
'isolinux', 'syslinux',
# Main Kit # Main Kit
f'{KIT_NAME_FULL}/.bin', f'{KIT_NAME_FULL}/.bin',
f'{KIT_NAME_FULL}/.cbin', f'{KIT_NAME_FULL}/.cbin',

View file

@ -19,7 +19,8 @@ from wk.os import linux
DOCSTRING = '''WizardKit: Build UFD DOCSTRING = '''WizardKit: Build UFD
Usage: Usage:
build-ufd [options] --ufd-device PATH --linux PATH build-ufd [options] --ufd-device PATH
[--linux PATH]
[--linux-minimal PATH] [--linux-minimal PATH]
[--main-kit PATH] [--main-kit PATH]
[--winpe PATH] [--winpe PATH]
@ -34,6 +35,7 @@ Options:
-u PATH, --ufd-device PATH -u PATH, --ufd-device PATH
-w PATH, --winpe PATH -w PATH, --winpe PATH
-d --debug Enable debug mode
-h --help Show this page -h --help Show this page
-M --use-mbr Use real MBR instead of GPT w/ Protective MBR -M --use-mbr Use real MBR instead of GPT w/ Protective MBR
-F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION! -F --force Bypass all confirmation messages. USE WITH EXTREME CAUTION!
@ -48,9 +50,11 @@ UFD_LABEL = f'{KIT_NAME_SHORT}_UFD'
def build_ufd(): def build_ufd():
"""Build UFD using selected sources.""" """Build UFD using selected sources."""
args = docopt(DOCSTRING) args = docopt(DOCSTRING)
if args['--debug']:
log.enable_debug_mode()
log.update_log_path(dest_name='build-ufd', timestamp=True) log.update_log_path(dest_name='build-ufd', timestamp=True)
try_print = std.TryAndPrint() try_print = std.TryAndPrint()
try_print.add_error(FileNotFoundError) try_print.add_error('FileNotFoundError')
try_print.catch_all = False try_print.catch_all = False
try_print.verbose = True try_print.verbose = True
try_print.indent = 2 try_print.indent = 2
@ -93,12 +97,13 @@ def build_ufd():
dev_path=ufd_dev, dev_path=ufd_dev,
label=UFD_LABEL, label=UFD_LABEL,
) )
ufd_dev_first_partition = find_first_partition(ufd_dev)
# Mount UFD # Mount UFD
try_print.run( try_print.run(
message='Mounting UFD...', message='Mounting UFD...',
function=linux.mount, function=linux.mount,
source=find_first_partition(ufd_dev), source=ufd_dev_first_partition,
mount_point='/mnt/UFD', mount_point='/mnt/UFD',
read_write=True, read_write=True,
) )
@ -113,6 +118,10 @@ def build_ufd():
# Copy sources # Copy sources
std.print_standard(' ') std.print_standard(' ')
std.print_info('Copy Sources') std.print_info('Copy Sources')
try_print.run(
'Copying Memtest86...', io.recursive_copy,
'/usr/share/memtest86-efi/', '/mnt/UFD/EFI/Memtest86/', overwrite=True,
)
for s_label, s_path in sources.items(): for s_label, s_path in sources.items():
try_print.run( try_print.run(
message='Copying {}...'.format(s_label), message='Copying {}...'.format(s_label),
@ -134,7 +143,7 @@ def build_ufd():
try_print.run( try_print.run(
message='Syslinux (partition)...', message='Syslinux (partition)...',
function=install_syslinux_to_partition, function=install_syslinux_to_partition,
partition=find_first_partition(ufd_dev), partition=ufd_dev_first_partition,
) )
# Unmount UFD # Unmount UFD
@ -158,7 +167,7 @@ def build_ufd():
try_print.run( try_print.run(
message='Hiding items...', message='Hiding items...',
function=hide_items, function=hide_items,
ufd_dev=ufd_dev, ufd_dev_first_partition=ufd_dev_first_partition,
items=ITEMS_HIDDEN, items=ITEMS_HIDDEN,
) )
@ -231,11 +240,7 @@ def create_table(dev_path, use_mbr=False):
def find_first_partition(dev_path): def find_first_partition(dev_path):
"""Find path to first partition of dev, returns str. """Find path to first partition of dev, returns str."""
NOTE: This assumes the dev was just partitioned with
a single partition.
"""
cmd = [ cmd = [
'lsblk', 'lsblk',
'--list', '--list',
@ -247,7 +252,7 @@ def find_first_partition(dev_path):
# Run cmd # Run cmd
proc = run_program(cmd) proc = run_program(cmd)
part_path = proc.stdout.splitlines()[-1].strip() part_path = proc.stdout.splitlines()[1].strip()
# Done # Done
return part_path return part_path
@ -281,17 +286,16 @@ def get_uuid(path):
return proc.stdout.strip() return proc.stdout.strip()
def hide_items(ufd_dev, items): def hide_items(ufd_dev_first_partition, items):
"""Set FAT32 hidden flag for items.""" """Set FAT32 hidden flag for items."""
first_partition = find_first_partition(ufd_dev)
with open('/root/.mtoolsrc', 'w') as _f: with open('/root/.mtoolsrc', 'w') as _f:
_f.write(f'drive U: file="{first_partition}"\n') _f.write(f'drive U: file="{ufd_dev_first_partition}"\n')
_f.write('mtools_skip_check=1\n') _f.write('mtools_skip_check=1\n')
# Hide items # Hide items
for item in items: for item in items:
cmd = [f'yes | sudo mattrib +h "U:/{item}"'] cmd = [f'yes | sudo mattrib +h "U:/{item}"']
run_program(cmd, shell=True) run_program(cmd, shell=True, check=False)
def install_syslinux_to_dev(ufd_dev, use_mbr): def install_syslinux_to_dev(ufd_dev, use_mbr):
@ -314,7 +318,7 @@ def install_syslinux_to_partition(partition):
'syslinux', 'syslinux',
'--install', '--install',
'--directory', '--directory',
'/arch/boot/syslinux/', '/syslinux/',
partition, partition,
] ]
run_program(cmd) run_program(cmd)

View file

@ -122,8 +122,8 @@ function update_live_env() {
# Boot config (legacy) # Boot config (legacy)
mkdir -p "$PROFILE_DIR/arch" mkdir -p "$PROFILE_DIR/arch"
cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/arch/pxelinux.png" cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/syslinux/pxelinux.png"
cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/arch/syslinux.png" cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/syslinux/syslinux.png"
sed -i -r "s/__+/$KIT_NAME_FULL/" "$PROFILE_DIR/syslinux/syslinux.cfg" sed -i -r "s/__+/$KIT_NAME_FULL/" "$PROFILE_DIR/syslinux/syslinux.cfg"
mkdir -p "$TEMP_DIR" 2>/dev/null mkdir -p "$TEMP_DIR" 2>/dev/null
curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip" curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip"

View file

@ -5,4 +5,4 @@ A live Windows environment
ENDTEXT ENDTEXT
MENU LABEL Windows PE MENU LABEL Windows PE
COM32 linux.c32 COM32 linux.c32
APPEND /%INSTALL_DIR%/boot/wimboot gui initrdfile=/sources/bootmgr,/sources/BCD,/sources/boot.sdi,/sources/boot.wim APPEND wimboot gui initrdfile=/sources/bootmgr,/sources/BCD,/sources/boot.sdi,/sources/boot.wim