Skip to content

Commit

Permalink
Remove ubuntu-boot and replace with a simpler mbr
Browse files Browse the repository at this point in the history
  • Loading branch information
valentindavid authored and alfonsosanchezbeato committed Feb 28, 2023
1 parent adadcea commit de30c75
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 83 deletions.
80 changes: 13 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,4 @@
NONSNAP_GRUB_MODULES = \
btrfs \
hfsplus \
iso9660 \
part_apple \
part_msdos \
password_pbkdf2 \
zfs \
zfscrypt \
zfsinfo \
lvm \
mdraid09 \
mdraid1x \
raid5rec \
raid6rec \

# filtered list of modules included in the signed EFI grub image, excluding
# ones that we don't think are useful in snappy.
GRUB_MODULES = \
all_video \
biosdisk \
boot \
cat \
chain \
configfile \
echo \
ext2 \
fat \
font \
gettext \
gfxmenu \
gfxterm \
gfxterm_background \
gzio \
halt \
jpeg \
keystatus \
loadenv \
loopback \
linux \
memdisk \
minicmd \
normal \
part_gpt \
png \
reboot \
regexp \
search \
search_fs_uuid \
search_fs_file \
search_label \
sleep \
squash4 \
test \
true \
video

all:
dd if=/usr/lib/grub/i386-pc/boot.img of=pc-boot.img bs=440 count=1
/bin/echo -n -e '\x90\x90' | dd of=pc-boot.img seek=102 bs=1 conv=notrunc
grub-mkimage -O i386-pc -o pc-core.img -p '(,gpt2)/EFI/ubuntu' $(GRUB_MODULES)
# The first sector of the core image requires an absolute pointer to the
# second sector of the image. Since this is always hard-coded, it means our
# BIOS boot partition must be defined with an absolute offset. The
# particular value here is 2049, or 0x01 0x08 0x00 0x00 in little-endian.
/bin/echo -n -e '\x01\x08\x00\x00' | dd of=pc-core.img seek=500 bs=1 conv=notrunc
all: mbr.img
# We must pull in dualsigned shim & grub with UC20 signature
# Do it by hand, as snapcraft doesn't have support for PPA archives yet
# And yet people try to rebuild this gadget snap
Expand All @@ -74,8 +9,19 @@ all:
cp shim/usr/lib/shim/shimx64.efi.dualsigned shim.efi.signed
cp grub/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed grubx64.efi

legacy-bios/mbr.o: legacy-bios/mbr.s
gcc -Wall -O0 -c -m16 $< -o $@

legacy-bios/mbr.bin: legacy-bios/mbr.o legacy-bios/mbr.ld
ld -melf_i386 -T legacy-bios/mbr.ld legacy-bios/mbr.o -o $@

mbr.img: legacy-bios/mbr.bin
dd if=legacy-bios/mbr.bin of=mbr.img bs=440 count=1

install:
install -m 644 pc-boot.img pc-core.img shim.efi.signed grubx64.efi $(DESTDIR)/
install -m 644 mbr.img shim.efi.signed grubx64.efi $(DESTDIR)/
install -m 644 grub.conf $(DESTDIR)/
install -d $(DESTDIR)/meta
install -m 644 gadget.yaml $(DESTDIR)/meta/

.PHONY: install all
20 changes: 6 additions & 14 deletions gadget.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
volumes:
pc:
schema: gpt
# bootloader configuration is shipped and managed by snapd
bootloader: grub
structure:
Expand All @@ -9,21 +10,12 @@ volumes:
update:
edition: 1
content:
- image: pc-boot.img
- name: BIOS Boot
type: DA,21686148-6449-6E6F-744E-656564454649
size: 1M
offset: 1M
offset-write: mbr+92
update:
edition: 2
content:
- image: pc-core.img
- image: mbr.img
- name: ubuntu-seed
role: system-seed
filesystem: vfat
# UEFI will boot the ESP partition by default first
type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
type: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
size: 1200M
update:
edition: 2
Expand All @@ -37,7 +29,7 @@ volumes:
- name: ubuntu-boot
role: system-boot
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
# whats the appropriate size?
size: 750M
update:
Expand All @@ -50,10 +42,10 @@ volumes:
- name: ubuntu-save
role: system-save
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
size: 32M
- name: ubuntu-data
role: system-data
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
size: 1G
15 changes: 15 additions & 0 deletions legacy-bios/mbr.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OUTPUT_FORMAT("binary");
ENTRY(start);
SECTIONS
{
. = 0x7c00;
.text : AT(0x7c00) {
*(.text);
}
.data : {
*(.data);
}
/DISCARD/ : {
*(*);
}
}
32 changes: 32 additions & 0 deletions legacy-bios/mbr.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.code16
.section .text
.globl start

start:
jmp $0, $.entry
.entry:
cli
xorw %ax, %ax
movw %ax, %ss
movw %ax, %ds
movw $0x7c00, %sp
sti
cld
movw $.message, %si
.print:
lodsb
cmp $0, %al
je .done
push %si
movb $0xe, %ah
movw $0x0007, %bx
int $0x10
pop %si
jmp .print
.done:
cli
hlt

.section .data
.message:
.string "Please boot in EFI mode.\r\n\0"
2 changes: 0 additions & 2 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ parts:
source: .
build-packages:
- ubuntu-dev-tools
- grub-pc-bin
- grub-common
plugin: make

hooks:
Expand Down

0 comments on commit de30c75

Please sign in to comment.