mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
dc2961338d
This provides bootable disk images for x86 platforms via ! RUN_OPT="--target disk" The resulting disk image contains one ext2 partition with binaries from the GRUB2 boot loader and the run scenario. The default disk size fits all binaries, but is configurable via ! --disk-size <size in MiB> in RUN_OPT. The feature depends on an grub2-head.img, which is part of the commit, but may also be generated by executing tool/create_grub2. The script generates a disk image prepared for one partition, which contains files for GRUB2. All image preparation steps that need superuser privileges are conducted by this script. The final step of writing the entire image to a disk must be executed later by sudo dd if=<image file> of=<device> bs=8M conv=fsync Fixes #1203.
78 lines
1.6 KiB
Bash
Executable File
78 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 an 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="4MiB"
|
|
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 4MiB"
|
|
|
|
# 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
|
|
|
|
# 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 switch to partition 2 and legacy load Genode
|
|
#set root=(hd0,msdos1)
|
|
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
|