Skip to content

Commit

Permalink
[installer] Use the Grub version comes from ONL OS
Browse files Browse the repository at this point in the history
The Grub in ONiE OS is always out of date.  Reinstalling ONiE and ONL for
upgrading Grub is quite complex and takes a lot of time.

In ONL runtime, it can upgrade the Grub directly by performing grub-install
command with appropriate arguments.

This patch changes the ONL installer to include libraries come from ONL root
filesystem for grub-install.  A fresh installed ONL will have the Grub version
from ONL OS immediately.

Signed-off-by: david_yang <[email protected]>
  • Loading branch information
david56 committed Dec 4, 2024
1 parent 28f52e6 commit 65aaee1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions builds/any/installer/grub/builds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ DEBIAN_VERSION_ID := $(shell echo $(VERSION_ID))
include $(ONL)/make/versions/version-onl.mk
INSTALLER_NAME=$(FNAME_PRODUCT_VERSION)_ONL-OS$(DEBIAN_VERSION_ID)_$(FNAME_BUILD_ID)_$(UARCH)_$(BOOTMODE)_INSTALLER

ifeq ($(ARCH),amd64)
MKINSTALLER_OPTS_ARCH = \
--add-dir $(ONL)/builds/$(ARCH)/rootfs/builds/$(ONL_DEBIAN_SUITE)/rootfs-$(ARCH).d/usr/lib/grub/i386-pc \
--add-dir $(ONL)/builds/$(ARCH)/rootfs/builds/$(ONL_DEBIAN_SUITE)/rootfs-$(ARCH).d/usr/lib/grub/x86_64-efi
endif

MKINSTALLER_OPTS = \
--onl-version "$(VERSION_STRING)" \
--arch $(ARCH) \
Expand All @@ -25,6 +31,7 @@ MKINSTALLER_OPTS = \
--postinstall-script $(ONL)/builds/any/installer/sample-postinstall.sh \
--plugin $(ONL)/builds/any/installer/sample-preinstall.py \
--plugin $(ONL)/builds/any/installer/sample-postinstall.py \
$(MKINSTALLER_OPTS_ARCH) \
# THIS LINE INTENTIONALLY LEFT BLANK

WORK_DIR := $(ONL_DEBIAN_SUITE)
Expand Down
1 change: 1 addition & 0 deletions builds/any/rootfs/buster/common/amd64-base-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- parted
- smartmontools
- grub2
- grub-efi-amd64-bin
- onl-upgrade
- onl-kernel-4.9-lts-x86-64-all-modules
- onl-kernel-4.14-lts-x86-64-all-modules
Expand Down
1 change: 1 addition & 0 deletions builds/any/rootfs/jessie/common/amd64-base-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- parted
- smartmontools
- grub2
- grub-efi-amd64-bin
- onl-upgrade
- hw-management
- sx-kernel
Expand Down
1 change: 1 addition & 0 deletions builds/any/rootfs/stretch/common/amd64-base-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- parted
- smartmontools
- grub2
- grub-efi-amd64-bin
- onl-upgrade
- hw-management
- onl-kernel-4.9-lts-x86-64-all-modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def installLoader(self):

kernels = []
for f in set(os.listdir(self.im.installerConf.installer_dir) + self.zf.namelist()):
if 'kernel' in f:
if f.startswith('kernel'):
kernels.append(f)

initrd = None
Expand All @@ -706,6 +706,20 @@ def _cp(b, dstname=None):
[_cp(e) for e in kernels]
_cp(initrd, "%s.cpio.gz" % self.im.installerConf.installer_platform)

d = None
if self.isUEFI:
d = 'x86_64-efi/'
else:
d = 'i386-pc/'
dirs = os.path.join(ctx.dir, 'onl-loader', 'grub', d)
if not os.path.isdir(dirs):
os.makedirs(dirs)
for f in self.zf.namelist():
if f.startswith(d) and f != d:
dst = os.path.join(dirs, os.path.basename(f))
if not os.path.exists(dst):
self.installerCopy(f, dst)

return 0

def installGrubCfg(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def install(self, device):
self.check_output((self.EFIBOOTMGR, '-b', uidx, '-B',))

grubOpts = []
directory = None
if self.isUEFI:
grubOpts.append('--target=x86_64-efi')
grubOpts.append('--no-nvram')
Expand All @@ -213,14 +214,19 @@ def install(self, device):
grubOpts.append('--bootloader-id=ONL')
# All ONL-derived distros should be able to use
# the same profile
directory = "--directory=%s/onl-loader/grub/x86_64-efi"
else:
directory = "--directory=%s/onl-loader/grub/i386-pc"

def _install():
if self.bootDir is not None:
grubOpts.append(directory % self.bootDir)
self.check_call([self.INSTALL, '--boot-directory=' + self.bootDir,]
+ grubOpts
+ [device,])
elif self.bootPart is not None:
with self.mountCtx(self.bootPart) as ctx:
grubOpts.append(directory % ctx.dir)
self.check_call([self.INSTALL, '--boot-directory=' + ctx.dir,]
+ grubOpts
+ [device,])
Expand Down Expand Up @@ -402,12 +408,16 @@ def install(self, device):
cmds.append("%s -b %s -B || sts=$?" % (self.EFIBOOTMGR, bidx,))

grubOpts = []
directory = None
if self.isUEFI:
grubOpts.append('--target=x86_64-efi')
grubOpts.append('--no-nvram')
grubOpts.append('--bootloader-id=ONL')
grubOpts.append('--efi-directory=/boot/efi')
grubOpts.append('--recheck')
directory = "--directory=%s/onl-loader/grub/x86_64-efi"
else:
directory = "--directory=%s/onl-loader/grub/i386-pc"

cmds = []

Expand All @@ -424,17 +434,20 @@ def install(self, device):
if self.bootDir and self.chroot:
p = os.pat.join(self.installerConf.installer_chroot,
self.bootDir.lstrip('/'))
grubOpts.append(directory % p)
cmd = ([self.INSTALL, '--boot-directory=' + p,]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
elif self.bootDir:
p = self.bootDir
grubOpts.append(directory % p)
cmd = ([self.INSTALL, '--boot-directory=' + p,]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
elif self.bootPart:
grubOpts.append(directory % "$bootMpt")
cmd = ([self.INSTALL, '--boot-directory=\"$bootMpt\"',]
+ grubOpts
+ [device,])
Expand Down

0 comments on commit 65aaee1

Please sign in to comment.