84 lines
1.7 KiB
Python
84 lines
1.7 KiB
Python
import subprocess
|
|
|
|
config = {
|
|
"qcow_disk": "/home/me/work/config/mize/parts/mos/build/stick.qcow2",
|
|
"root_dir": "/home/me/work/config/mize/parts/mos/build/root",
|
|
"target": "/dev/nbd0",
|
|
"partitions": [
|
|
{
|
|
"type": "fat32" ,
|
|
"size": "200M",
|
|
"flags": [ "esp" ]
|
|
},
|
|
{
|
|
"type": "ext4" ,
|
|
"size": "100%",
|
|
},
|
|
],
|
|
"isofs": {
|
|
"volid": "archiso-project",
|
|
},
|
|
}
|
|
|
|
def set_config(path, val):
|
|
config[path] = val
|
|
|
|
|
|
def get_config(path):
|
|
return config[path]
|
|
|
|
|
|
def connect_qemu_nbd():
|
|
disk = get_config("qcow_disk")
|
|
sh(f"sudo qemu-nbd --connect=/dev/nbd0 -f qcow2 {disk}")
|
|
|
|
|
|
def disconnect_qemu_nbd():
|
|
sh(f"sudo qemu-nbd --disconnect=/dev/nbd0")
|
|
|
|
def make_busybod_root_from_nixpkgs():
|
|
path = sub
|
|
pass
|
|
|
|
def flash_isofs():
|
|
volid = get_config("isofs.volid")
|
|
isolinux = get_config("isofs.linux")
|
|
boot_cat = get_config("isofs.boot_cat")
|
|
isohybrid_mbr = get_config("isofs.hybrid_mbr") # /usr/lib/syslinux/bios/isohdpfx.bin"
|
|
efiboot_img = get_config("isofs.efiboot.img")
|
|
output = get_config("target")
|
|
root_fs = get_config("root_dir")
|
|
subprocess.run([
|
|
"xorriso", "as", "mkisofs",
|
|
"-iso-level", "3", "-full-iso9660-filenames",
|
|
"-volid", volid,
|
|
"-eltorito-boot", isolinux,
|
|
"-eltorito-catalog", boot_cat,
|
|
"-no-emul-boot", "-boot-load-size", "4", "-boot-info-table",
|
|
"-isohybrid-mbr", isohybrid_mbr,
|
|
"-eltorito-alt-boot",
|
|
"-e", efiboot_img,
|
|
"-no-emul-boot",
|
|
"-isohybrid-gpt-basdat",
|
|
"-output", output,
|
|
root_fs,
|
|
])
|
|
|
|
def sh(cmd):
|
|
subprocess.run(["sh", "-c", cmd])
|
|
|
|
def provision():
|
|
try:
|
|
connect_qemu_nbd()
|
|
|
|
|
|
finally:
|
|
disconnect_qemu_nbd()
|
|
|
|
def main():
|
|
provision()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|