Skip to content

Instantly share code, notes, and snippets.

@kost
Last active December 27, 2019 14:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kost/1409c2ef13ed6f887cd9bc7855277dc6 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Copy data to the end of the partition, needed for BIOS Next186 by Kost.
# https://gist.github.com/kost
# Example: ./copy_bios_end.sh BIOS_Next186.bin /dev/sdd
if [ "$#" -ne 2 ] ; then
echo "Usage: $0 <BIOSfile> <device>" >&2
echo "Example: $0 BIOS_Next186.bin /dev/sdd" >&2
exit 1
fi
BIOS_INPUT=$1
GIVEN_DEVICE=$2
JUST_DEVICE=$(basename $GIVEN_DEVICE)
SIZE_DEVICE=$(cat /proc/partitions| grep -e "\b$JUST_DEVICE\b" | awk '{print $3}')
# /sys/block/$JUST_DEVICE/queue/hw_sector_size
CLUSTER_SIZE=512
NUM_SECTORS=16
DATA_SIZE=$(expr $NUM_SECTORS \* $CLUSTER_SIZE)
START_OFFSET=$(expr $SIZE_DEVICE - $NUM_SECTORS)
echo "$GIVEN_DEVICE: $JUST_DEVICE of $SIZE_DEVICE sectors"
echo "$GIVEN_DEVICE: offset $START_OFFSET with $DATA_SIZE"
echo dd if=$BIOS_INPUT of=$GIVEN_DEVICE seek=$START_OFFSET bs=$CLUSTER_SIZE
dd if=$BIOS_INPUT of=$GIVEN_DEVICE seek=$START_OFFSET bs=$CLUSTER_SIZE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment