summaryrefslogtreecommitdiff
path: root/sub/disk-image
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-05-22 21:56:04 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-05-22 21:56:04 +0000
commit82d0f92ab8b84466ae20ab919c1f9c3577b5cecb (patch)
tree776015ae6c6a386125b2d39e13b62f91b99548f8 /sub/disk-image
downloadlh-bootstrap-82d0f92ab8b84466ae20ab919c1f9c3577b5cecb.tar.xz
Initial commit
Diffstat (limited to 'sub/disk-image')
-rwxr-xr-xsub/disk-image/make-disk-image107
1 files changed, 107 insertions, 0 deletions
diff --git a/sub/disk-image/make-disk-image b/sub/disk-image/make-disk-image
new file mode 100755
index 0000000..64d2c40
--- /dev/null
+++ b/sub/disk-image/make-disk-image
@@ -0,0 +1,107 @@
+#!/bin/sh -e
+
+# umount is given with -l because some operating systems have triggers that will launch processes keep file descriptors open to the mount, preventing unmounting
+
+output="$1"
+rootfs_size="$2"
+swap_size="$3"
+rwfs_size="$4"
+userfs_size="$5"
+extra_size="$6"
+
+totalsize=$(s6-expr ${rootfs_size} + ${swap_size} + ${rwfs_size} + ${userfs_size} + ${extra_size} + 4)
+
+# prepare extlinux.conf
+
+if s6-test ${KERNEL_GENERIC_ARCH} = x86 ; then
+ consolearg="console=ttyS0,115200n8"
+ if ${USE_GRAPHIC} ; then
+ consolearg=
+ fi
+ if s6-test ${KERNEL_ARCH} = x86_64 ; then
+ bootpartition=/dev/sda1
+ else
+ bootpartition=/dev/hda1
+ fi
+ s6-cat > ${output}/rootfs/boot/extlinux.conf <<EOF
+serial 0 115200
+console 0
+prompt 0
+default linux
+totaltimeout 1200
+say extlinux booting
+label linux
+ linux /boot/vmlinuz
+ initrd /boot/initramfs.gz
+ append ro root=$bootpartition rootfstype=ext4 loglevel=4 initrd=/boot/initramfs.gz $consolearg
+EOF
+fi
+
+s6-rmrf "$output/disk-image.raw"
+setuidgid ${NORMALUSER} dd if=/dev/zero of=$output/disk-image.raw bs=1 count=0 seek=${totalsize}M
+
+fdisk $output/disk-image.raw <<EOF
+n
+
+
+
++${rootfs_size}M
+n
+
+
+
++${swap_size}M
+t
+2
+82
+n
+
+
+
++${rwfs_size}M
+n
+
+
+
+n
+
++${userfs_size}M
+n
+
+
+a
+1
+w
+EOF
+
+loop=$(losetup -f)
+losetup -P "$loop" "$output/disk-image.raw"
+
+{
+ mkfs.ext4 -O ^huge_file ${loop}p1
+ mkswap ${loop}p2
+ mkfs.ext4 -O ^huge_file ${loop}p3
+ mkfs.ext4 -O ^huge_file ${loop}p5
+ mkfs.ext4 -O ^huge_file ${loop}p6
+
+
+ s6-mkdir -p "$output/tmp/rootfs" "$output/tmp/rwfs" "$output/tmp/userfs" "$output/tmp/stagingfs"
+ mount -t ext4 ${loop}p1 "$output/tmp/rootfs"
+ s6-hiercopy "$output/rootfs" "$output/tmp/rootfs"
+ if s6-test ${KERNEL_GENERIC_ARCH} = x86 ; then
+ dd if=${output}/build-build/opt/syslinux/usr/share/syslinux/mbr.bin of=${loop}
+ extlinux -i "$output/tmp/rootfs/boot"
+ fi
+ umount -l "$output/tmp/rootfs"
+ mount -t ext4 ${loop}p3 "$output/tmp/rwfs"
+ s6-hiercopy "$output/rwfs" "$output/tmp/rwfs"
+ umount -l "$output/tmp/rwfs"
+ mount -t ext4 ${loop}p5 "$output/tmp/userfs"
+ s6-hiercopy "$output/userfs" "$output/tmp/userfs"
+ umount -l "$output/tmp/userfs"
+ mount -t ext4 ${loop}p6 "$output/tmp/stagingfs"
+ s6-hiercopy "$output/stagingfs" "$output/tmp/stagingfs"
+ umount -l "$output/tmp/stagingfs"
+} || { losetup -d "$loop" ; exit 1 ; }
+
+losetup -d "$loop"