genode/tool/create_grub2
Christian Helmuth da21a3c338 create_grub2: ext2 default parameters for image
The mkfs.ext2 heuristics select the "small" ext2 usage type, which does
not fit well with GiB-sized pen drives. For example, the block size is
just 1024 bytes compared to 4096 for "default". Therefore, we enforce
the default usage type as this fits our use case of dumping the image to
USB sticks better.
2015-03-13 12:17:26 +01:00

77 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
#
# \brief Create hard-disk image bootable via GRUB2
# \author Christian Helmuth
# \date 2014-07-11
#
# We generate a head-image file only. This image contains MBR, label
# (partition table), and one primary partition where GRUB2 is installed. The
# image size fits only the GRUB2 binaries and must be extended later to include
# further binaries and data.
#
# Some parts of this script must be executed with superuser privileges and
# utilize 'sudo' for this purpose.
set -e
#set -x
#
# config
#
head_size="8MiB"
head_img="grub2-head.img"
# generate image file
if [ -f $head_img ]; then
echo "$head_img exists. Exiting..."
exit 1
fi
fallocate -l $head_size $head_img
# prepare label and partition table
parted="parted -s $head_img -- unit MiB"
$parted "mklabel msdos"
$parted "mkpart primary ext2 1MiB -1s"
# loop image as disk (loop0) and partition 1 (loop1)
sudo losetup /dev/loop0 $head_img
sudo losetup /dev/loop1 $head_img -o 1MiB
# initialize ext2 on partition
sudo mkfs.ext2 /dev/loop1 -L GENODE -q -T default
# install GRUB2
mnt=$(mktemp -d)
sudo mount /dev/loop1 $mnt
sudo grub-install --root-directory=$mnt --no-floppy \
--modules="biosdisk part_msdos ext2" /dev/loop0
# generate GRUB2 configuration
cfg=$(mktemp)
cat > $cfg <<EOF
set prefix=(hd0,msdos1)/boot/grub
insmod normal
insmod legacycfg
terminal_input console
terminal_output console
## just legacy load Genode
legacy_configfile /boot/grub/menu.lst
EOF
sudo cp $cfg $mnt/boot/grub/grub.cfg
# cleanup
rm $cfg
sudo umount $mnt
rm -r $mnt
sudo losetup -d /dev/loop1
sudo losetup -d /dev/loop0