Bootable GRUB2 disk image with ext2 partition

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.
This commit is contained in:
Christian Helmuth 2014-07-11 15:43:47 +02:00 committed by Norman Feske
parent f442e64eaf
commit dc2961338d
10 changed files with 147 additions and 7 deletions

View File

@ -120,7 +120,8 @@ proc build_boot_image {binaries} {
puts $fh "timeout 0" puts $fh "timeout 0"
puts $fh "default 0" puts $fh "default 0"
puts $fh "\ntitle Genode on L4/Fiasco" puts $fh "\ntitle Genode on L4/Fiasco"
puts $fh " kernel /fiasco/bootstrap -serial -modaddr=0x02000000" puts $fh " kernel /boot/bender"
puts $fh " module /fiasco/bootstrap -serial -modaddr=0x02000000"
puts $fh " module /fiasco/fiasco -serial -jdb_cmd=JH $fiasco_serial_esc_arg" puts $fh " module /fiasco/fiasco -serial -jdb_cmd=JH $fiasco_serial_esc_arg"
puts $fh " module /fiasco/sigma0" puts $fh " module /fiasco/sigma0"
puts $fh " module /genode/core" puts $fh " module /genode/core"
@ -137,6 +138,7 @@ proc build_boot_image {binaries} {
install_pxe_bootloader_to_run_dir install_pxe_bootloader_to_run_dir
create_iso_image_from_run_dir create_iso_image_from_run_dir
create_disk_image_from_run_dir
# #
# Generate pulsar config file # Generate pulsar config file

View File

@ -161,7 +161,8 @@ proc build_boot_image_x86 {binaries} {
puts $fh "timeout 0" puts $fh "timeout 0"
puts $fh "default 0" puts $fh "default 0"
puts $fh "\ntitle Genode on Fiasco.OC" puts $fh "\ntitle Genode on Fiasco.OC"
puts $fh " kernel /fiasco/bootstrap -modaddr=0x01100000" puts $fh " kernel /boot/bender"
puts $fh " module /fiasco/bootstrap -modaddr=0x01100000"
puts $fh " module /fiasco/fiasco $fiasco_serial_esc_arg" puts $fh " module /fiasco/fiasco $fiasco_serial_esc_arg"
puts $fh " module /fiasco/sigma0" puts $fh " module /fiasco/sigma0"
puts $fh " module /genode/core" puts $fh " module /genode/core"
@ -174,6 +175,7 @@ proc build_boot_image_x86 {binaries} {
install_pxe_bootloader_to_run_dir install_pxe_bootloader_to_run_dir
create_iso_image_from_run_dir create_iso_image_from_run_dir
create_disk_image_from_run_dir
# #
# Generate pulsar config file # Generate pulsar config file

View File

@ -83,6 +83,7 @@ proc build_boot_image {binaries} {
install_pxe_bootloader_to_run_dir install_pxe_bootloader_to_run_dir
create_iso_image_from_run_dir create_iso_image_from_run_dir
create_disk_image_from_run_dir
# #
# Generate pulsar config file # Generate pulsar config file

View File

@ -200,11 +200,13 @@ proc build_boot_image {binaries} {
puts $fh "default 0" puts $fh "default 0"
puts $fh "hiddenmenu" puts $fh "hiddenmenu"
puts $fh "\ntitle Genode on OKL4" puts $fh "\ntitle Genode on OKL4"
puts $fh "kernel /image.elf" puts $fh " kernel /boot/bender"
puts $fh "vbeset 0x117" puts $fh " module /image.elf"
puts $fh " vbeset 0x117"
close $fh close $fh
create_iso_image_from_run_dir create_iso_image_from_run_dir
create_disk_image_from_run_dir
# #
# Generate pulsar config file # Generate pulsar config file

View File

@ -115,6 +115,7 @@ proc build_boot_image {binaries} {
install_pxe_bootloader_to_run_dir install_pxe_bootloader_to_run_dir
create_iso_image_from_run_dir create_iso_image_from_run_dir
create_disk_image_from_run_dir
# #
# Generate pulsar config file # Generate pulsar config file

View File

@ -23,6 +23,19 @@ of Genode.
This simple tool helps to build bootable ISO images from your build of This simple tool helps to build bootable ISO images from your build of
Genode. For getting usage information, start the tool without arguments. Genode. For getting usage information, start the tool without arguments.
:'create_grub2':
This tool prepares a partitioned disk image with GRUB2 as boot
loader.
:'grub2-head.img':
This file is the head part of a partioned disk image including an
installation of GRUB2 as boot loader. GRUB2 is available from
http://www.gnu.org/software/grub/ and in major Linux distributions.
Steps to reproduce the image creation can be found in
'create_grub2'.
:'beautify': :'beautify':
Beautify is a coding-style checking tool that analyzes source code for its Beautify is a coding-style checking tool that analyzes source code for its

View File

@ -13,7 +13,7 @@ code respectively the download source of binaries are described below.
http://os.inf.tu-dresden.de/~us15/pulsar. http://os.inf.tu-dresden.de/~us15/pulsar.
:'chain.c32', 'isolinux.bin' :'chain.c32', 'isolinux.bin'
These files are part of the 'Syslinux Project' hosting several bootloaders. These files are part of the 'Syslinux Project' hosting several bootloaders.
The sources has been obtained from http://www.syslinux.org. The sources has been obtained from http://www.syslinux.org.

77
tool/create_grub2 Executable file
View File

@ -0,0 +1,77 @@
#!/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

BIN
tool/grub2-head.img Normal file

Binary file not shown.

View File

@ -451,6 +451,48 @@ proc create_iso_image_from_run_dir { } {
} }
} }
##
# Create disk image with the content of the run directory
#
# optional parameter: --disk-size <n> ... disk size in MiB
#
proc create_disk_image_from_run_dir { } {
global run_target
if {![regexp "disk" $run_target]} { return }
requires_installation_of parted
requires_installation_of resize2fs
requires_installation_of fallocate
set grub_img "[genode_dir]/tool/grub2-head.img"
set disk_img "[run_dir].img"
set part1_img "[run_dir]-part1.img"
set run_size [expr [regsub {\s.*} [exec du -sm [run_dir]] {}] + 4]
set disk_size [get_cmd_arg --disk-size $run_size]
set part1_size [expr $disk_size - 1]MiB
# extract and resize partition image
exec dd if=$grub_img of=$part1_img bs=1M skip=1 2>/dev/null
exec fallocate -l $part1_size $part1_img
exec resize2fs $part1_img 2>/dev/null
# populate partition with binaries
exec [genode_dir]/tool/rump -F ext2fs -p [run_dir] $part1_img
# merge final image from GRUB2 head and partition
exec dd if=$grub_img of=$disk_img status=noxfer bs=1M count=1 2>/dev/null
exec dd if=$part1_img of=$disk_img status=noxfer bs=1M seek=1 2>/dev/null
exec parted -s $disk_img -- rm 1 mkpart primary 2048s -1s
exec rm -f $part1_img
puts "Created image file $disk_img ($disk_size MiB)"
}
## ##
# Wait for a specific output of a already running spawned process # Wait for a specific output of a already running spawned process
# #
@ -572,7 +614,7 @@ proc is_amt_available { } {
if {![have_spec x86] || ![regexp "amt" $run_target]} { return false } if {![have_spec x86] || ![regexp "amt" $run_target]} { return false }
if {[info exists ::env(AMT_TEST_MACHINE_IP)] && if {[info exists ::env(AMT_TEST_MACHINE_IP)] &&
[info exists ::env(AMT_TEST_MACHINE_PWD)] && [info exists ::env(AMT_TEST_MACHINE_PWD)] &&
[have_installed amtterm] && [have_installed amtterm] &&
[have_installed amttool]} { [have_installed amttool]} {
@ -596,7 +638,7 @@ proc is_serial_available { } {
## ##
# Execute scenario using Intel's AMT # Execute scenario using Intel's AMT
# #
proc spawn_amt { wait_for_re timeout_value } { proc spawn_amt { wait_for_re timeout_value } {
global spawn_id global spawn_id