summaryrefslogtreecommitdiff
path: root/mkimage.sh
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-02-27 11:45:44 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-02-27 11:45:44 +0000
commit384744b859f9c55d3801397b131af7d055dff32f (patch)
treec0fc48ed82d15cfa1279b4af0fe6193d737ecd61 /mkimage.sh
parent2d9c31272d2ab42844bee3afbe54a66b3e49f346 (diff)
downloadmorph-384744b859f9c55d3801397b131af7d055dff32f.tar.gz
mkimage.sh: add script
baserock-bootstrap does not make system images any more I copied the part of the script out and made some changes These should be in version control
Diffstat (limited to 'mkimage.sh')
-rwxr-xr-xmkimage.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/mkimage.sh b/mkimage.sh
new file mode 100755
index 00000000..0c137bf8
--- /dev/null
+++ b/mkimage.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+usage(){
+cat >&2 <<EOF
+Make a system image called DEST filled with the contents of TARBALL...
+usage: $0 DEST TARBALL...
+EOF
+}
+
+if [ "$#" -le 1 ]; then
+ usage
+ exit 1
+fi
+
+img="$1"
+shift
+
+sudo qemu-img create -f raw "$img" 16G
+sudo parted -s "$img" mklabel msdos
+sudo parted -s "$img" mkpart primary 0% 100%
+sudo parted -s "$img" set 1 boot on
+sudo install-mbr "$img"
+part=/dev/mapper/$(sudo kpartx -av "$img" | awk '/^add map/ { print $3 }' | head -n1)
+trap "sudo kpartx -dv $img" EXIT
+# mapper may not yet be ready
+while test ! -e "$part"; do :; done
+sudo mkfs -t ext4 "$part"
+mp="$(mktemp -d)"
+sudo mount "$part" "$mp"
+trap "sudo umount $part; sudo kpartx -dv $img" EXIT
+
+for stratum; do
+ sudo tar -C "$mp" -xf "$stratum"
+done
+
+cat <<EOF | sudo tee "$mp/etc/fstab"
+/dev/sda1 / ext4 errors=remount-ro 0 1
+EOF
+
+cat <<EOF | sudo tee "$mp/extlinux.conf"
+default linux
+timeout 1
+
+label linux
+kernel /boot/vmlinuz
+append root=/dev/sda1 init=/sbin/init quiet rw
+EOF
+
+sudo extlinux --install "$mp"
+sync
+sleep 2