Skip to content

Instantly share code, notes, and snippets.

@ledbettj
Created April 7, 2014 17:15
Show Gist options
  • Select an option

  • Save ledbettj/10024371 to your computer and use it in GitHub Desktop.

Select an option

Save ledbettj/10024371 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
# see http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
PART_TYPE="4f68bce3-e8cd-4db1-96e7-fbcaf984b709"
if [ $# -ne 2 ]; then
echo "Usage: $0 <image-name> <image-size (mb)>"
exit 1
fi
TARGET="$1"
SIZE="$2"
echo -n "creating..."
dd if=/dev/zero of="$TARGET" bs=1M count="$SIZE" &>/dev/null
echo "done"
echo -n "partitioning..."
sgdisk -o -n 1 -t 1:"$PART_TYPE" -c 1:disk "$TARGET" >/dev/null
echo "done"
echo -n "mounting..."
LOOP=$(kpartx -avs "$TARGET" | grep -oE "loop[0-9]p[0-9]+")
echo "done"
echo -n "formatting..."
mkfs.ext2 "/dev/mapper/$LOOP" >/dev/null
echo "done"
TEMP=$(mktemp -d)
echo -n "mounting root partition..."
mount "/dev/mapper/$LOOP" "$TEMP" > /dev/null
echo "done"
echo -n "installing base system..."
pacstrap -c -d "$TEMP" base >/dev/null
echo "done"
echo -n "cleaning up..."
umount "$TEMP" >/dev/null
kpartx -d "$TARGET" >/dev/null
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment