John Voltz | ab063ab | 2008-03-06 17:52:37 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | BLOCKSIZE=516096 |
| 4 | WORKING_DIR=`pwd` |
| 5 | |
| 6 | echo "This script will create a bootable ext3 image from buildroot." |
| 7 | |
| 8 | echo "Enter the path to the image (${WORKING_DIR})" |
| 9 | read IMG_PATH |
| 10 | |
| 11 | if [ "${IMAGE_PATH}" = "" ]; then |
| 12 | IMAGE_PATH=${WORKING_DIR} |
| 13 | fi |
| 14 | |
| 15 | echo "Enter the name of the image file (buildroot.img)" |
| 16 | read IMG_NAME |
| 17 | |
| 18 | if [ "${IMAGE_NAME}" = "" ]; then |
| 19 | IMAGE_NAME="buildroot.img" |
| 20 | fi |
| 21 | |
| 22 | IMAGE=${IMAGE_PATH}/${IMAGE_NAME} |
| 23 | |
John Voltz | 7c98bd3 | 2008-05-01 15:21:47 +0000 | [diff] [blame] | 24 | echo "Enter the path and filename for the root filesystem" |
| 25 | echo "tarball that you want to install into the image" |
John Voltz | ab063ab | 2008-03-06 17:52:37 +0000 | [diff] [blame] | 26 | read ROOT_PATH |
| 27 | |
| 28 | if [ "${ROOT_PATH}" = "" ]; then |
| 29 | echo "Error: you must specify a path." |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | CYLINDERS=`du --summarize --block-size=${BLOCKSIZE} ${ROOT_PATH}` |
| 34 | BYTE_SIZE=`du --summarize --block-size=${BLOCKSIZE} --human-readable ${ROOT_PATH}` |
| 35 | |
| 36 | CYLINDERS=${CYLINDERS%${ROOT_PATH}} |
| 37 | BYTE_SIZE=${BYTE_SIZE%${ROOT_PATH}} |
| 38 | |
John Voltz | 7c98bd3 | 2008-05-01 15:21:47 +0000 | [diff] [blame] | 39 | CYLINDERS=`expr ${CYLINDERS} "*" 2` |
John Voltz | ab063ab | 2008-03-06 17:52:37 +0000 | [diff] [blame] | 40 | |
| 41 | echo "Now I will create an ext3 image file" |
| 42 | echo "using ${CYLINDERS} cylinders, with ${BLOCKSIZE} bytes per block" |
| 43 | echo "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 Voltz | 7c98bd3 | 2008-05-01 15:21:47 +0000 | [diff] [blame] | 63 | tar -xvf ${ROOT_PATH} --directory ${IMAGE_PATH}/temp |
John Voltz | ab063ab | 2008-03-06 17:52:37 +0000 | [diff] [blame] | 64 | # make sure to unmount the image |
| 65 | umount ${IMAGE_PATH}/temp |
| 66 | rm -rf ${IMAGE_PATH}/temp |
| 67 | |
| 68 | # Create a VMware .vmx file |
| 69 | cat > ${IMAGE_PATH}/buildroot.vmx <<EOF |
| 70 | config.version = "8" |
| 71 | virtualHW.version = "3" |
| 72 | |
| 73 | uuid.location = "56 4d 5c cc 3d 4a 43 29-55 89 5c 28 1e 7e 06 58" |
| 74 | uuid.bios = "56 4d 5c cc 3d 4a 43 29-55 89 5c 28 1e 7e 06 58" |
| 75 | |
| 76 | uuid.action = "create" |
| 77 | checkpoint.vmState = "" |
| 78 | |
| 79 | displayName = "Buildroot" |
| 80 | annotation = "" |
| 81 | guestinfo.vmware.product.long = "" |
| 82 | guestinfo.vmware.product.url = "http://dcgrendel.be/vmbuilder/" |
| 83 | |
| 84 | guestOS = "linux" |
| 85 | numvcpus = "1" |
| 86 | memsize = "256" |
| 87 | paevm = "FALSE" |
| 88 | sched.mem.pshare.enable = "TRUE" |
| 89 | MemAllowAutoScaleDown = "FALSE" |
| 90 | |
| 91 | MemTrimRate = "-1" |
| 92 | |
| 93 | nvram = "nvram" |
| 94 | |
| 95 | mks.enable3d = "FALSE" |
| 96 | vmmouse.present = "TRUE" |
| 97 | |
| 98 | tools.syncTime = "TRUE" |
| 99 | tools.remindinstall = "FALSE" |
| 100 | |
| 101 | isolation.tools.hgfs.disable = "FALSE" |
| 102 | isolation.tools.dnd.disable = "FALSE" |
| 103 | isolation.tools.copy.enable = "TRUE" |
| 104 | isolation.tools.paste.enabled = "TRUE" |
| 105 | gui.restricted = "FALSE" |
| 106 | |
| 107 | ethernet0.present = "TRUE" |
| 108 | ethernet0.connectionType = "bridged" |
| 109 | ethernet0.addressType = "generated" |
| 110 | ethernet0.generatedAddress = "00:0c:29:7e:06:58" |
| 111 | ethernet0.generatedAddressOffset = "0" |
| 112 | |
| 113 | usb.present = "TRUE" |
| 114 | usb.generic.autoconnect = "FALSE" |
| 115 | |
| 116 | sound.present = "TRUE" |
| 117 | sound.virtualdev = "es1371" |
| 118 | |
| 119 | ide0:0.present = "TRUE" |
| 120 | ide0:0.fileName = "buildroot.vmdk" |
| 121 | ide0:0.deviceType = "disk" |
| 122 | ide0:0.mode = "" |
| 123 | ide0:0.redo = "" |
| 124 | ide0:0.writeThrough = "FALSE" |
| 125 | ide0:0.startConnected = "TRUE" |
| 126 | |
John Voltz | 7c98bd3 | 2008-05-01 15:21:47 +0000 | [diff] [blame] | 127 | ide1:0.present = "FALSE" |
John Voltz | ab063ab | 2008-03-06 17:52:37 +0000 | [diff] [blame] | 128 | ide1:0.fileName = "" |
| 129 | ide1:0.deviceType = "disk" |
| 130 | ide1:0.mode = "" |
| 131 | ide1:0.redo = "" |
| 132 | ide1:0.writeThrough = "FALSE" |
| 133 | ide1:0.startConnected = "FALSE" |
| 134 | |
| 135 | floppy0.present = "FALSE" |
| 136 | |
| 137 | serial0.present = "FALSE" |
| 138 | |
| 139 | serial1.present = "FALSE" |
| 140 | |
| 141 | parallel0.present = "FALSE" |
| 142 | |
| 143 | EOF |
| 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 |