Skip to content

Commit 8207c34

Browse files
committed
bootloader: Reject module2 without multiboot2
GRUB2 will fail if module2 is used without a previous call to multiboot2 so raise an exception instead of pretending that it is actually a hypervisor. Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
1 parent d5e6697 commit 8207c34

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

tests/data/grub-no-multiboot.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
serial --unit=0 --speed=115200
2+
terminal_input serial console
3+
terminal_output serial console
4+
set default=0
5+
set timeout=5
6+
menuentry 'XCP-ng' {
7+
search --label --set root root-vgdorj
8+
module2 /boot/vmlinuz-4.19-xen root=LABEL=root-vgdorj ro nolvm hpet=disable console=hvc0 console=tty0 quiet vga=785 splash plymouth.ignore-serial-consoles
9+
module2 /boot/initrd-4.19-xen.img
10+
}

tests/test_bootloader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def test_grub2(self):
2525
proc.stdout.close()
2626
proc.wait()
2727

28+
def test_no_multiboot(self):
29+
# A module2 line without a multiboot2 line is an error
30+
with self.assertRaises(RuntimeError):
31+
Bootloader.readGrub2("tests/data/grub-no-multiboot.cfg")
32+
2833
class TestLinuxBootloader(unittest.TestCase):
2934
def setUp(self):
3035
self.tmpdir = mkdtemp(prefix="testbl")

xcp/bootloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ def parse_boot_entry(line):
195195
hypervisor, hypervisor_args = parse_boot_entry(l)
196196
elif l.startswith("module2"):
197197
if not hypervisor:
198-
hypervisor, hypervisor_args = parse_boot_entry(l)
199-
elif kernel:
198+
raise RuntimeError("Need a multiboot2 kernel")
199+
if kernel:
200200
initrd = l.split(None, 1)[1]
201201
else:
202202
kernel, kernel_args = parse_boot_entry(l)

0 commit comments

Comments
 (0)