Last active
May 1, 2019 20:22
-
-
Save mattintosh4/d9eb65b92cd2da509bc2 to your computer and use it in GitHub Desktop.
Arch Linux ARM disk image creator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| set -u | |
| set -x | |
| # Environment variables | |
| export PATH=/usr/bin:/bin:/usr/sbin:/bin | |
| export LANG=en_US.UTF-8 | |
| # External commands | |
| BSDTAR=`which bsdtar` | |
| CURL=`which curl` | |
| FALLOCATE=`which fallocate` | |
| FDISK=`which fdisk` | |
| FSCK_VFAT=`which fsck.vfat` | |
| LOSETUP=`which losetup` | |
| MKFS_EXT4=`which mkfs.ext4` | |
| MKFS_VFAT=`which mkfs.vfat` | |
| MKTEMP=`which mktemp` | |
| P7ZIP=`which 7z` | |
| SUDO=`which sudo` | |
| # Files | |
| select name in "Raspberry Pi 1" "Raspberry Pi 2" | |
| do | |
| case ${name} in | |
| "Raspberry Pi 1") | |
| url=http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz | |
| name_prefix=ArchLinuxARM-rpi | |
| ;; | |
| "Raspberry Pi 2") | |
| url=http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz | |
| name_prefix=ArchLinuxARM-rpi-2 | |
| ;; | |
| esac | |
| break | |
| done | |
| src=`basename ${url}` | |
| img=${name_prefix}-`date +%Y%m%d`.img | |
| #------------------------------------------------------------------------------- | |
| test ! -f ${img} || rm ${img} | |
| test -f ${src} || ${CURL} -LO ${url} | |
| ${FALLOCATE} -l 1GB ${img} | |
| ${FDISK} ${img} <<! | |
| o | |
| n | |
| +100M | |
| t | |
| c | |
| n | |
| w | |
| ! | |
| ${FDISK} --list ${img} | |
| ${SUDO} -v | |
| loop_device=`${SUDO} ${LOSETUP} --find --partscan --show ${img}` | |
| loop_device_boot=${loop_device}p1 | |
| loop_device_root=${loop_device}p2 | |
| ${SUDO} ${MKFS_VFAT} ${loop_device_boot} | |
| ${SUDO} ${FSCK_VFAT} -y ${loop_device_boot} | |
| ${SUDO} ${MKFS_EXT4} ${loop_device_root} | |
| mount_point=`${MKTEMP} -d` | |
| ${SUDO} mount ${loop_device_root} ${mount_point} | |
| ${SUDO} mkdir ${mount_point}/boot | |
| ${SUDO} mount ${loop_device_boot} ${mount_point}/boot | |
| ${SUDO} ${BSDTAR} -xpf ${src} -C ${mount_point} | |
| ${SUDO} umount ${loop_device_boot} ${loop_device_root} | |
| rm -r ${mount_point} | |
| ${SUDO} losetup --detach ${loop_device} | |
| ${P7ZIP} a ${img}.zip ${img} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| set -u | |
| set -x | |
| # Environment variables | |
| export PATH=/usr/bin:/bin:/usr/sbin:/bin | |
| export LANG=en_US.UTF-8 | |
| # External commands | |
| BSDTAR=`which bsdtar` | |
| CURL=`which curl` | |
| FALLOCATE=`which fallocate` | |
| FDISK=`which fdisk` | |
| FSCK_VFAT=`which fsck.vfat` | |
| LOSETUP=`which losetup` | |
| MKFS_EXT4=`which mkfs.ext4` | |
| MKFS_VFAT=`which mkfs.vfat` | |
| MKTEMP=`which mktemp` | |
| P7ZIP=`which 7z` | |
| SUDO=`which sudo` | |
| # Files | |
| select name in "Raspberry Pi 1" "Raspberry Pi 2" | |
| do | |
| case ${name} in | |
| "Raspberry Pi 1") | |
| url=http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz | |
| name_prefix=ArchLinuxARM-rpi-QEMU | |
| ;; | |
| "Raspberry Pi 2") | |
| url=http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz | |
| name_prefix=ArchLinuxARM-rpi-2-QEMU | |
| ;; | |
| esac | |
| break | |
| done | |
| src=`basename ${url}` | |
| img=${name_prefix}-`date +%Y%m%d`.img | |
| #------------------------------------------------------------------------------- | |
| test ! -f ${img} || rm ${img} | |
| test -f ${src} || ${CURL} -LO ${url} | |
| ${FALLOCATE} -l 1GB ${img} | |
| ${FDISK} ${img} <<! | |
| o | |
| n | |
| w | |
| ! | |
| ${FDISK} --list ${img} | |
| ${SUDO} -v | |
| loop_device=`${SUDO} ${LOSETUP} --find --partscan --show ${img}` | |
| loop_device_root=${loop_device}p1 | |
| ${SUDO} ${MKFS_EXT4} ${loop_device_root} | |
| mount_point=`${MKTEMP} -d` | |
| ${SUDO} mount ${loop_device_root} ${mount_point} | |
| ${SUDO} ${BSDTAR} -xpf ${src} -C ${mount_point} | |
| ( | |
| cd ${mount_point} | |
| ${SUDO} sed -i "s|^/dev/mmcblk0p1|#\0|" etc/fstab | |
| cat <<! | ${SUDO} tee etc/udev/rules.d/90-qemu.rules | |
| KERNEL=="sda", SYMLINK+="mmcblk0" | |
| KERNEL=="sda?", SYMLINK+="mmcblk0p%n" | |
| ! | |
| ) | |
| ${SUDO} umount ${loop_device_root} | |
| rm -r ${mount_point} | |
| ${SUDO} losetup --detach ${loop_device} | |
| ${P7ZIP} a ${img}.zip ${img} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment