blob: 1cab710c2555a7f6d2de84807cb57961081dba09 [file] [log] [blame]
John Voltzab063ab2008-03-06 17:52:37 +00001#!/bin/sh
2
3BLOCKSIZE=516096
4WORKING_DIR=`pwd`
5
6echo "This script will create a bootable ext3 image from buildroot."
7
8echo "Enter the path to the image (${WORKING_DIR})"
9read IMG_PATH
10
11if [ "${IMAGE_PATH}" = "" ]; then
12 IMAGE_PATH=${WORKING_DIR}
13fi
14
15echo "Enter the name of the image file (buildroot.img)"
16read IMG_NAME
17
18if [ "${IMAGE_NAME}" = "" ]; then
19 IMAGE_NAME="buildroot.img"
20fi
21
22IMAGE=${IMAGE_PATH}/${IMAGE_NAME}
23
John Voltz7c98bd32008-05-01 15:21:47 +000024echo "Enter the path and filename for the root filesystem"
25echo "tarball that you want to install into the image"
John Voltzab063ab2008-03-06 17:52:37 +000026read ROOT_PATH
27
28if [ "${ROOT_PATH}" = "" ]; then
29 echo "Error: you must specify a path."
30 exit 1
31fi
32
33CYLINDERS=`du --summarize --block-size=${BLOCKSIZE} ${ROOT_PATH}`
34BYTE_SIZE=`du --summarize --block-size=${BLOCKSIZE} --human-readable ${ROOT_PATH}`
35
36CYLINDERS=${CYLINDERS%${ROOT_PATH}}
37BYTE_SIZE=${BYTE_SIZE%${ROOT_PATH}}
38
John Voltz7c98bd32008-05-01 15:21:47 +000039CYLINDERS=`expr ${CYLINDERS} "*" 2`
John Voltzab063ab2008-03-06 17:52:37 +000040
41echo "Now I will create an ext3 image file"
42echo "using ${CYLINDERS} cylinders, with ${BLOCKSIZE} bytes per block"
43echo "in other words, ${BYTE_SIZE}bytes..."
44
45 dd if=/dev/zero of=${IMAGE} bs=${BLOCKSIZE}c count=${CYLINDERS}
46
47# Create file partition and filesystem
48
49 # STEP 1. create partition
50 /sbin/losetup /dev/loop3 ${IMAGE}
51 # probably should figure out how to use GNU parted to do this non-interactively
52 /sbin/fdisk -u -C${CYLINDERS} -S63 -H16 /dev/loop3
53 /sbin/losetup -d /dev/loop3
54
55 # STEP 2. make file system (ext3)
56 /sbin/losetup -o 32256 /dev/loop3 ${IMAGE}
57 /sbin/mkfs.ext3 /dev/loop3
58 /sbin/losetup -d /dev/loop3
59
60# Install Software to the image
61 mkdir -p ${IMAGE_PATH}/temp
62 mount -o offset=32256,loop ${IMAGE} ${IMAGE_PATH}/temp
John Voltz7c98bd32008-05-01 15:21:47 +000063 tar -xvf ${ROOT_PATH} --directory ${IMAGE_PATH}/temp
John Voltzab063ab2008-03-06 17:52:37 +000064 # make sure to unmount the image
65 umount ${IMAGE_PATH}/temp
66 rm -rf ${IMAGE_PATH}/temp
67
68# Create a VMware .vmx file
69cat > ${IMAGE_PATH}/buildroot.vmx <<EOF
70config.version = "8"
71virtualHW.version = "3"
72
73uuid.location = "56 4d 5c cc 3d 4a 43 29-55 89 5c 28 1e 7e 06 58"
74uuid.bios = "56 4d 5c cc 3d 4a 43 29-55 89 5c 28 1e 7e 06 58"
75
76uuid.action = "create"
77checkpoint.vmState = ""
78
79displayName = "Buildroot"
80annotation = ""
81guestinfo.vmware.product.long = ""
82guestinfo.vmware.product.url = "http://dcgrendel.be/vmbuilder/"
83
84guestOS = "linux"
85numvcpus = "1"
86memsize = "256"
87paevm = "FALSE"
88sched.mem.pshare.enable = "TRUE"
89MemAllowAutoScaleDown = "FALSE"
90
91MemTrimRate = "-1"
92
93nvram = "nvram"
94
95mks.enable3d = "FALSE"
96vmmouse.present = "TRUE"
97
98tools.syncTime = "TRUE"
99tools.remindinstall = "FALSE"
100
101isolation.tools.hgfs.disable = "FALSE"
102isolation.tools.dnd.disable = "FALSE"
103isolation.tools.copy.enable = "TRUE"
104isolation.tools.paste.enabled = "TRUE"
105gui.restricted = "FALSE"
106
107ethernet0.present = "TRUE"
108ethernet0.connectionType = "bridged"
109ethernet0.addressType = "generated"
110ethernet0.generatedAddress = "00:0c:29:7e:06:58"
111ethernet0.generatedAddressOffset = "0"
112
113usb.present = "TRUE"
114usb.generic.autoconnect = "FALSE"
115
116sound.present = "TRUE"
117sound.virtualdev = "es1371"
118
119ide0:0.present = "TRUE"
120ide0:0.fileName = "buildroot.vmdk"
121ide0:0.deviceType = "disk"
122ide0:0.mode = ""
123ide0:0.redo = ""
124ide0:0.writeThrough = "FALSE"
125ide0:0.startConnected = "TRUE"
126
John Voltz7c98bd32008-05-01 15:21:47 +0000127ide1:0.present = "FALSE"
John Voltzab063ab2008-03-06 17:52:37 +0000128ide1:0.fileName = ""
129ide1:0.deviceType = "disk"
130ide1:0.mode = ""
131ide1:0.redo = ""
132ide1:0.writeThrough = "FALSE"
133ide1:0.startConnected = "FALSE"
134
135floppy0.present = "FALSE"
136
137serial0.present = "FALSE"
138
139serial1.present = "FALSE"
140
141parallel0.present = "FALSE"
142
143EOF
144
145# Install GRUB
146 /sbin/grub --no-floppy --batch <<EOT
147 device (hd0) ${IMAGE}
148 geometry (hd0) ${CYLINDERS} 16 63
149 root (hd0,0)
150 setup (hd0)
151 quit
152 EOT