#!/bin/sh set -e if [ -z "$2" ]; then echo "Usage: $0 [stage2 start sector]" exit 1 fi # Variables. DEVICE="$2" MBR="$(mktemp)" BINARY_SECT_SRC="$(mktemp)" BINARY_SECT_BIN="$(mktemp)" QLOADER2="$1" if [ -z "$3" ]; then STAGE2_SECT=1 else STAGE2_SECT="$3" fi echo "dd $STAGE2_SECT" > "$BINARY_SECT_SRC" nasm "$BINARY_SECT_SRC" -f bin -o "$BINARY_SECT_BIN" # Copy the loader to the device. dd if="$DEVICE" of="$MBR" bs=1 count=64 skip=446 2>/dev/null dd if="$QLOADER2" of="$DEVICE" bs=512 count=1 conv=notrunc 2>/dev/null dd if="$QLOADER2" of="$DEVICE" bs=512 count=63 skip=1 seek=$(( $STAGE2_SECT )) conv=notrunc 2>/dev/null dd if="$BINARY_SECT_BIN" of="$DEVICE" bs=1 count=4 seek=$(( 0x1b0 )) conv=notrunc 2>/dev/null dd if="$MBR" of="$DEVICE" bs=1 count=64 seek=446 conv=notrunc 2>/dev/null rm "$MBR" "$BINARY_SECT_SRC" "$BINARY_SECT_BIN"