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