Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/make_fake_device.sh
diff options
context:
space:
mode:
authorMartin Dengler <martin@martindengler.com>2009-06-29 21:31:30 (GMT)
committer Martin Dengler <martin@martindengler.com>2009-06-30 11:35:31 (GMT)
commit0ae1da97a8da1f25c8d4cba1135e1f4cc9b17db8 (patch)
tree10e97b686c618c651be009ecb288865145240c25 /make_fake_device.sh
parent628648f8d89fe8322e2867a5a56a673900683206 (diff)
refactor build process into smaller, more sensible, more restartable scripts
Diffstat (limited to 'make_fake_device.sh')
-rwxr-xr-xmake_fake_device.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/make_fake_device.sh b/make_fake_device.sh
new file mode 100755
index 0000000..c44a0e0
--- /dev/null
+++ b/make_fake_device.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+PATH=/usr/sbin:/sbin:$PATH
+
+SAFE_SIZE_4G=3758096384 #3584mb
+SAFE_SIZE_2G=1879048192 #1/2 4g safe size
+SAFE_SIZE_1G=939524096 #1/2 2g safe size
+
+DISK_SIZE=$SAFE_SIZE_4G
+LOOP_DEV=$(losetup -f)
+
+usage() {
+ echo "make_fake_device.sh [--4G|--2G|--1G] <loop device backing store filename>"
+ echo " outputs a loop device whose backing store is a partitioned disk "
+ echo " image using a sparse file of the specified size (default is --4G)"
+ exit 1
+}
+
+while [ $# -gt 1 ]; do
+ case $1 in
+ --4G)
+ DISK_SIZE=$SAFE_SIZE_4G
+ shift
+ ;;
+ --2G)
+ DISK_SIZE=$SAFE_SIZE_2G
+ shift
+ ;;
+ --1G)
+ DISK_SIZE=$SAFE_SIZE_2G
+ shift
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+IMG=$1
+
+
+BLOCK_SIZE=512
+NUM_HEADS=16
+NUM_SECTORS_PER_TRACK=62
+NUM_BLOCKS=$(($DISK_SIZE / $BLOCK_SIZE))
+NUM_CYLINDERS=$(($NUM_BLOCKS / $NUM_HEADS / $NUM_SECTORS_PER_TRACK))
+IMAGE_SIZE=$(($NUM_CYLINDERS * $NUM_HEADS * $NUM_SECTORS_PER_TRACK * $BLOCK_SIZE))
+OS_PART1_BEGIN=$(($NUM_SECTORS_PER_TRACK * $BLOCK_SIZE))
+
+dd if=/dev/zero of=$IMG bs=$BLOCK_SIZE count=0 seek=$(($IMAGE_SIZE / $BLOCK_SIZE)) > /dev/null 2>&1 || exitclean
+/sbin/fdisk -b $BLOCK_SIZE -C $NUM_CYLINDERS -S $NUM_SECTORS_PER_TRACK -H $NUM_HEADS $IMG > /dev/null 2>&1 <<EOF
+n
+p
+1
+
+
+t
+83
+p
+w
+q
+EOF
+
+losetup -d $LOOP_DEV > /dev/null 2>&1 || /bin/true
+losetup -o $OS_PART1_BEGIN $LOOP_DEV $IMG
+
+mke2fs -O dir_index -L OLPCRoot -F $LOOP_DEV > /dev/null 2>&1 || exitclean
+echo $LOOP_DEV
+