aboutsummaryrefslogtreecommitdiffstats
path: root/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py
diff options
context:
space:
mode:
Diffstat (limited to 'rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py')
-rwxr-xr-xrpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py
new file mode 100755
index 0000000..3d1b295
--- /dev/null
+++ b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py
@@ -0,0 +1,61 @@
+#!/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: {} <device>'.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()