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

View file

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

View file

@ -122,8 +122,8 @@ function update_live_env() {
# Boot config (legacy)
mkdir -p "$PROFILE_DIR/arch"
cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/arch/pxelinux.png"
cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/arch/syslinux.png"
cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/syslinux/pxelinux.png"
cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/syslinux/syslinux.png"
sed -i -r "s/__+/$KIT_NAME_FULL/" "$PROFILE_DIR/syslinux/syslinux.cfg"
mkdir -p "$TEMP_DIR" 2>/dev/null
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
MENU LABEL Windows PE
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