mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
run: use GPT for image/disk BIOS legacy
Issue #2778 The "create_grub2" script functionality is moved to the g2fg contrib sources and also the GRUB2 head image (tool/grub2-head.img). The head image is now partitioned as GPT and bootable in BIOS legacy mode.
This commit is contained in:
committed by
Christian Helmuth
parent
6080f4fb56
commit
25f2c44874
@@ -1 +1 @@
|
|||||||
d60b3ee01ee63a0f8c192d188b8a1746acfa37d6
|
cb391d98c9c0229b147f24b148524a3347c1bd46
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ VERSION := git
|
|||||||
DOWNLOADS := g2fg.git
|
DOWNLOADS := g2fg.git
|
||||||
|
|
||||||
URL(g2fg) := https://github.com/alex-ab/g2fg.git
|
URL(g2fg) := https://github.com/alex-ab/g2fg.git
|
||||||
REV(g2fg) := d2b93f99c21d46083c3635d1dff29c45cebbbdb9
|
REV(g2fg) := bec7ffd45be62bb41faf33941c5acbbcf5e594b5
|
||||||
DIR(g2fg) := boot
|
DIR(g2fg) := boot
|
||||||
|
|
||||||
default: $(DOWNLOADS)
|
default: $(DOWNLOADS)
|
||||||
$(VERBOSE)tar -C boot -xjf boot/grub2.tar.bz2
|
$(VERBOSE)tar -C boot -xJf boot/grub2.tar.xz
|
||||||
|
$(VERBOSE)unxz -kf boot/grub2-head.img.xz
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
#!/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
|
|
||||||
|
|
||||||
terminal_input console
|
|
||||||
terminal_output console
|
|
||||||
|
|
||||||
configfile /boot/grub/grub.cfg
|
|
||||||
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
|
|
||||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
|||||||
# \param --image-disk-size disk size in MiB
|
# \param --image-disk-size disk size in MiB
|
||||||
#
|
#
|
||||||
|
|
||||||
source [genode_dir]/tool/run/iso.inc
|
source [genode_dir]/tool/run/grub2.inc
|
||||||
|
|
||||||
|
|
||||||
proc image_disk_size { } { return [get_cmd_arg --image-disk-size 0] }
|
proc image_disk_size { } { return [get_cmd_arg --image-disk-size 0] }
|
||||||
@@ -16,34 +16,64 @@ proc image_disk_size { } { return [get_cmd_arg --image-disk-size 0] }
|
|||||||
proc run_image { {unused ""} } {
|
proc run_image { {unused ""} } {
|
||||||
|
|
||||||
requires_installation_of parted
|
requires_installation_of parted
|
||||||
requires_installation_of resize2fs
|
requires_installation_of e2cp
|
||||||
requires_installation_of fallocate
|
|
||||||
|
# make copy of template grub2 header image
|
||||||
|
exec cp [get_grub2_dir]/boot/grub2-head.img [run_dir].header
|
||||||
|
|
||||||
|
# remove template partition
|
||||||
|
exec parted -a none -s [run_dir].header -- rm 3
|
||||||
|
|
||||||
|
# calculate size of grub2 header and the size of Genode scenario
|
||||||
|
set size_header [expr [regsub {\s.*} [exec du -b [run_dir].header] {}]]
|
||||||
|
set size_run [expr [regsub {\s.*} [exec du -skL [run_dir]] {}]]
|
||||||
|
|
||||||
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]] {}] + 8]
|
|
||||||
if {[image_disk_size] > 0} {
|
if {[image_disk_size] > 0} {
|
||||||
set disk_size [image_disk_size]
|
set disk_size_kb [expr [image_disk_size] * 1024 * 1024]
|
||||||
} else {
|
} else {
|
||||||
set disk_size $run_size
|
set disk_size_kb [expr ($size_run + 256) / 32 * 32]
|
||||||
}
|
}
|
||||||
set part1_size [expr $disk_size - 1]MiB
|
|
||||||
|
|
||||||
# extract and resize partition image
|
# setup partition with content
|
||||||
exec dd if=$grub_img of=$part1_img bs=1M skip=1 2>/dev/null
|
exec dd if=/dev/zero of=[run_dir].partition bs=1k count=$disk_size_kb 2>/dev/null
|
||||||
exec fallocate -l $part1_size $part1_img
|
exec mkfs.ext2 -L GENODE* -q -T default [run_dir].partition
|
||||||
exec resize2fs $part1_img 2>/dev/null
|
|
||||||
|
|
||||||
# populate partition with binaries
|
# copy content to disk image
|
||||||
exec [genode_dir]/tool/rump -F ext2fs -p [run_dir] $part1_img
|
foreach file [exec find [run_dir]] {
|
||||||
|
set filename [string replace $file 0 [string length [run_dir]] ""]
|
||||||
|
if {[string length $filename] == 0} {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if {[file isdirectory $file]} {
|
||||||
|
exec e2mkdir [run_dir].partition:$filename
|
||||||
|
} else {
|
||||||
|
exec e2cp $file [run_dir].partition:$filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# calculate start/end sector of content partition
|
||||||
|
set first_sector [expr $size_header / 512]
|
||||||
|
set last_sector [expr ((($size_header + ($disk_size_kb * 1024)) / 512) - 1)]
|
||||||
|
|
||||||
|
# add free space for the backup gpt at the end of disk
|
||||||
|
set sector_backup [exec parted -s [run_dir].header 'unit s print']
|
||||||
|
set sector_backup [regexp -all -inline { 1 .*BIOSBOOT} $sector_backup]
|
||||||
|
set sector_backup [regexp -all -inline {([0-9]+)} $sector_backup]
|
||||||
|
set sector_backup [lindex $sector_backup 2]
|
||||||
|
|
||||||
|
exec dd if=/dev/zero of=[run_dir].empty bs=512 count=$sector_backup 2>/dev/null
|
||||||
|
|
||||||
# merge final image from GRUB2 head and partition
|
# 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 cat [run_dir].header [run_dir].partition [run_dir].empty > [run_dir].img
|
||||||
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 set 1 boot on
|
|
||||||
|
|
||||||
exec rm -f $part1_img
|
# cleanup
|
||||||
|
exec rm [run_dir].empty
|
||||||
|
exec rm [run_dir].header
|
||||||
|
exec rm [run_dir].partition
|
||||||
|
|
||||||
puts "Created image file $disk_img ($disk_size MiB)"
|
# create partition table entry pointing to the content
|
||||||
|
catch { exec parted -a none [run_dir].img -- mkpart Fix GENODE* ext2 [expr $first_sector]s ${last_sector}s }
|
||||||
|
set size_image [expr [regsub {\s.*} [exec du -sk [run_dir].img] {}]]
|
||||||
|
puts "Created image file [run_dir].img (${size_image}kiB)"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user