diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-03-05 17:48:51 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-03-05 17:48:51 +0000 |
commit | c972e5747b01767625f9754a31fed50f8ee61fca (patch) | |
tree | 1f8c49dd1655cad41eff8e9b39f6c1df8976d4c8 /mkimage.sh | |
parent | 6936b552db1ae0d385ee3635f4d0c4df38d0e9be (diff) | |
download | morph-c972e5747b01767625f9754a31fed50f8ee61fca.tar.gz |
Replace use of parted with sfdisk.
Add some inline documentation of what's happening.
Diffstat (limited to 'mkimage.sh')
-rwxr-xr-x | mkimage.sh | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -70,35 +70,45 @@ fi img="$1" shift +# Create an empty file (a hole) as the raw disk image file. dd if=/dev/zero of="$img" bs=16G seek=1 count=0 -parted -s "$img" mklabel msdos -parted -s "$img" mkpart primary 0% 100% -parted -s "$img" set 1 boot on -install-mbr "$img" +# Partition. See the sfdisk(8) manpage for an explanation of the input. +sfdisk "$img" <<EOF +1,,83,* +EOF +# Install the master boot record boot loader. +install-mbr "$img" + +# Access the partition inside the raw disk image file. part=$(dummy_kpartx_add "$img") trap "dummy_kpartx_delete $img" EXIT -# mapper may not yet be ready -while test ! -e "$part"; do :; done - -mkfs -t ext4 -q "$part" +# Create filesystem. Note that for some reason sfdisk and mkfs when used +# on the loop device from dummy_kpartx_add get the image size wrong by +# about one block, which makes things break. So we force a filesystem +# size that fits (even if it doesn't quite fill the image). +mkfs -t ext4 -q "$part" 4194304 +# Mount the filesystem. mp="$(mktemp -d)" mount "$part" "$mp" trap "umount $part; dummy_kpartx_delete $img" EXIT +# Unpack all the strata that are to be installed. for stratum do tar -C "$mp" -xf "$stratum" done -cat <<EOF | tee "$mp/etc/fstab" > /dev/null +# Configure fstab for the new system. +cat <<EOF > "$mp/etc/fstab" /dev/sda1 / ext4 errors=remount-ro 0 1 EOF -cat <<EOF | tee "$mp/extlinux.conf" > /dev/null +# Install extlinux as the bootloader. +cat <<EOF > "$mp/extlinux.conf" default linux timeout 1 @@ -107,7 +117,7 @@ kernel /boot/vmlinuz append root=/dev/sda1 init=/sbin/init rw EOF -sudo extlinux --install "$mp" +extlinux --install "$mp" sync sleep 2 |