8 echo "Usage: ${APP} <image_file> <kernel_elf>"
12 TMP
=`getopt -o hp:k:i: --long help,partition:,kernel:,image: -n ${APP} -- "$@"`
13 [ $?
!= 0 ] && usage
1
17 -h|
--help) usage
0 ; shift ;;
20 "gpt"|
"mbr") PT
=$2 ; shift 2 ;;
21 *) echo "Unsupported partition type '$2'" >&2 ; exit 1 ;;
23 -k|
--kernel) KERNEL_ELF
=$2 ; shift 2 ;;
24 -i|
--image) IMAGE_FILE
=$2 ; shift 2 ;;
26 *) echo "Internal error!" ; exit 1 ;;
30 [ -z ${IMAGE_FILE} ] &&
32 [ $# -gt 0 ] || usage
1
37 [ -z ${KERNEL_ELF} ] &&
39 [ $# -gt 0 ] || usage
1
44 dd if=/dev
/zero of
=${IMAGE_FILE} bs
=8192 count
=65536
47 sfdisk
-D ${IMAGE_FILE} <<-EOF
53 sgdisk
-a 1 -n 0:0:-4096K -a 1 -n 0:0:0 -t 2:ef02
${IMAGE_FILE} ;
54 # sgdisk -h 1 ${IMAGE_FILE} ;
55 # sfdisk -A2 ${IMAGE_FILE} ;
58 *) echo "Unexpected partition type '${PT}'" >&2 ; exit 1 ;;
61 BLOCK_DEVICE
=`losetup --partscan --find --show ${IMAGE_FILE}`
62 mke2fs
-b 1024 -t ext2
${BLOCK_DEVICE}p1
63 MOUNT_POINT
=`mktemp --directory`
64 mount
-t ext2
${BLOCK_DEVICE}p1
${MOUNT_POINT}
65 grub2-install
--boot-directory=${MOUNT_POINT}/boot --modules="${MODS} ext2" ${BLOCK_DEVICE}
66 #grub2-install --target=i386-multiboot --boot-directory=${MOUNT_POINT}/boot --force --modules="${MODS} ext2 multiboot multiboot2" --debug ${BLOCK_DEVICE}
67 #grub2-mkimage -O i386-multiboot -o ${MOUNT_POINT}/boot/grub2/i386-multiboot/core.img -v
68 #grub2-bios-setup -s -m /dev/null -d /usr/lib/grub -b i386-pc/boot.img -c ../../..${MOUNT_POINT}/boot/grub2/i386-multiboot/core.img -v ${BLOCK_DEVICE}
69 install ${KERNEL_ELF} ${MOUNT_POINT}/boot
/
70 NAME
=`basename ${KERNEL_ELF}`
71 cat > ${MOUNT_POINT}/boot
/grub
2/grub.cfg
<<EOF
76 if terminal_output gfxterm ; then true ; else terminal gfxterm; fi
77 set color_normal=black/white
78 set menu_color_normal=green/light-blue
79 set menu_color_highlight=yellow/blue
80 menuentry "MString kernel" {
83 search -n -f /boot/grub2/grub.cfg -s
84 multiboot /boot/${NAME}
88 NAME
=`basename ${MOD}`
89 install ${MOD} ${MOUNT_POINT}/boot/ && echo -e "\t\tmodule /boot/${NAME}" >> ${MOUNT_POINT}/boot
/grub
2/grub.cfg
91 echo -e "\t}\n" >> ${MOUNT_POINT}/boot
/grub
2/grub.cfg
94 losetup
--detach ${BLOCK_DEVICE}