build-ext3-img 3.6 KB

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