Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 3 | # Add a partition table to an ext2 image file |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2006-2007 OpenedHand Ltd. |
| 6 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 7 | # SPDX-License-Identifier: GPL-2.0-or-later |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | |
| 10 | IMAGE=$1 |
| 11 | IMAGEOUT=$2 |
| 12 | |
| 13 | echo $IMAGE |
| 14 | echo $IMAGEOUT |
| 15 | |
| 16 | size=`ls -l $IMAGE | awk '{ print $5}'` |
| 17 | size2=`expr $size / 512 / 16 / 63` |
| 18 | |
| 19 | echo $size |
| 20 | echo $size2 |
| 21 | |
| 22 | # MBR Size = 512 * 63 bytes |
| 23 | dd if=/dev/zero of=$IMAGEOUT count=63 |
| 24 | |
| 25 | echo "x" > /tmp/fdisk.cmds |
| 26 | echo "c" >> /tmp/fdisk.cmds |
| 27 | echo "1024" >> /tmp/fdisk.cmds |
| 28 | echo "h" >> /tmp/fdisk.cmds |
| 29 | echo "16" >> /tmp/fdisk.cmds |
| 30 | echo "r" >> /tmp/fdisk.cmds |
| 31 | echo "n" >> /tmp/fdisk.cmds |
| 32 | echo "p" >> /tmp/fdisk.cmds |
| 33 | echo "1" >> /tmp/fdisk.cmds |
| 34 | echo "1" >> /tmp/fdisk.cmds |
| 35 | echo "$size2" >> /tmp/fdisk.cmds |
| 36 | echo "w" >> /tmp/fdisk.cmds |
| 37 | |
| 38 | /sbin/fdisk $IMAGEOUT < /tmp/fdisk.cmds |
| 39 | cat $IMAGE >> $IMAGEOUT |