12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- echo "create_hdd_image.sh: Creating virtual disk image... arch=${ARCH}"
- export ARCH=${ARCH:=x86_64}
- DISK_NAME=disk-${ARCH}.img
- format_as_mbr() {
- echo "Formatting as MBR..."
-
- fdisk ${DISK_NAME} << EOF
- o
- n
- a
- w
- EOF
- }
- format_as_gpt() {
- echo "Formatting as GPT..."
- sudo parted ${DISK_NAME} << EOF
- mklabel gpt
- y
- mkpart
- p1
- FAT32
- 0
- -1
- I
- set
- 1
- boot
- on
- print
- q
- EOF
- }
- echo "Creating virtual disk image..."
- ARGS=`getopt -o P: -- "$@"`
- qemu-img create -f raw ${DISK_NAME} 2048M
- eval set -- "${ARGS}"
- case "$1" in
- -P)
- if [ $2 == "MBR" ];
- then
- format_as_mbr
- elif [ $2 == "GPT" ];
- then
- format_as_gpt
- else
- echo "Invalid partition type: $2"
- exit 1
- fi
- ;;
- --)
-
- format_as_mbr
- ;;
- *)
- echo "Invalid option: $1"
- exit 1
- ;;
- esac
- LOOP_DEVICE=$(sudo losetup -f --show -P ${DISK_NAME}) \
- || exit 1
- echo ${LOOP_DEVICE}p1
- sudo mkfs.vfat -F 32 ${LOOP_DEVICE}p1
- sudo losetup -d ${LOOP_DEVICE}
- echo "Successfully created disk image."
- mkdir -p ../bin
- chmod 777 ${DISK_NAME}
- mv ./${DISK_NAME} ../bin/
|