#!/usr/bin/python3 import sys import subprocess def run(*l, **d): print('run:', *l, d) return subprocess.run(*l, **d) def main(): if len(sys.argv) < 2: print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) raise SystemExit(1) device = sys.argv[1] # use this without check first, in some condition double invokation is # needed... run([ 'sudo', 'sgdisk', '--zap-all', device, ]) run([ 'sudo', 'sgdisk', '--set-alignment=8192', '--new=1:4M:+100M', '--change-name=1:boot', '--typecode=1:EF00', '--largest-new=2', '--change-name=2:root', '--typecode=2:8300', '--hybrid=1', '--print', '--print-mbr', device, ], check=True) run([ 'sudo', 'mkfs.vfat', '-F', '32', '-n', 'boot', device + '1', ], check=True) run([ 'sudo', 'mkfs.vfat', '-n', 'boot', device + '1', ], check=True) run([ 'sudo', 'mkfs.ext4', '-q', '-L', 'root', device + '2' ], check=True) if __name__ == '__main__': main()