Merge pull request #378 from carlroth/master

Fixed broken loader upgrade, see SWL-4234
This commit is contained in:
Jeffrey Townsend
2018-05-15 13:43:21 -07:00
committed by GitHub
7 changed files with 73 additions and 29 deletions

View File

@@ -141,6 +141,9 @@ if has_boot_env onl_installer_debug; then installer_debug=1; fi
if test "$installer_debug"; then
echo "Debug mode"
set -x
installer_wait=30
else
installer_wait=3
fi
# Pickup ONIE defines for this machine.
@@ -254,7 +257,7 @@ if test "${onie_platform}"; then
installer_umount
if installer_reboot; then
if installer_reboot $installer_wait; then
:
else
sync
@@ -587,7 +590,7 @@ trap - 0 1
installer_umount
if test "${onie_platform}"; then
installer_reboot
installer_reboot $installer_wait
fi
exit

View File

@@ -54,6 +54,7 @@ if [ -d /sys/firmware/efi/efivars ]; then
fi
mount --move /sys /newroot/sys
if [ -d /newroot/sys/firmware/efi/efivars ]; then
modprobe efivarfs || :
mount -t efivarfs efivarfs /newroot/sys/firmware/efi/efivars
fi
mount --move /dev /newroot/dev

View File

@@ -36,6 +36,7 @@ trap "restoreconsole; reboot -f" EXIT
mount -t proc proc /proc
mount -t sysfs sysfs /sys
if [ -d /sys/firmware/efi/efivars ]; then
modprobe efivarfs || :
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
mount -o remount,size=1M /dev

View File

@@ -114,6 +114,7 @@ installer_mkchroot() {
fi
mount -t devpts devpts "${rootdir}/dev/pts"
if test -d "${rootdir}/sys/firmware/efi/efivars"; then
modprobe efivarfs || :
mount -t efivarfs efivarfs "${rootdir}/sys/firmware/efi/efivars"
fi

View File

@@ -726,6 +726,9 @@ class GrubInstaller(SubprocessMixin, Base):
ctx['boot_loading_name'] = sysconfig.installer.os_name
if self.isUEFI:
if not self.espFsUuid:
self.log.error("cannnot find ESP UUID")
return 1
ctx['onie_boot_uuid'] = self.espFsUuid
else:
ctx['onie_boot_uuid'] = ""
@@ -846,6 +849,16 @@ class GrubInstaller(SubprocessMixin, Base):
self.blkidParts = BlkidParser(log=self.log.getChild("blkid"))
code = self.findGpt()
if code: return code
if self.isUEFI:
code = self.findEsp()
if code: return code
self.im.grubEnv.__dict__['espPart'] = self.espDevice
else:
self.im.grubEnv.__dict__['espPart'] = None
code = self.installGrubCfg()
if code: return code

View File

@@ -1059,6 +1059,16 @@ class InitrdContext(SubprocessMixin):
cmd = ('mount', '-t', 'sysfs', 'sysfs', dst,)
self.check_call(cmd, vmode=self.V1)
# Hurr, the efivarfs module may not be loaded
with open("/proc/filesystems") as fd:
buf = fd.read()
if "efivarfs" not in buf:
cmd = ('modprobe', 'efivarfs',)
try:
self.check_call(cmd, vmode=self.V1)
except subprocess.CalledProcessError:
pass
dst = os.path.join(self.dir, "sys/firmware/efi/efivars")
if os.path.exists(dst):
cmd = ('mount', '-t', 'efivarfs', 'efivarfs', dst,)

View File

@@ -89,6 +89,8 @@ class LoaderUpgrade_Fit(LoaderUpgradeBase):
path = os.path.join(octx.initrdDir, "etc/machine.conf")
if os.path.exists(path):
machineConf = ConfUtils.MachineConf(path=path)
else:
machineConf = ConfUtils.MachineConf(path='/dev/null')
installerConf = ConfUtils.InstallerConf(path="/dev/null")
# start with an empty installerConf, fill it in piece by piece
@@ -171,41 +173,54 @@ class LoaderUpgrade_x86_64(LoaderUpgradeBase, InstallUtils.SubprocessMixin):
onlPlatform = onl.platform.current.OnlPlatform()
with OnieBootContext(log=self.logger) as octx:
with OnieBootContext(log=self.log) as octx:
octx.ictx.attach()
octx.ictx.unmount()
octx.ictx.detach()
# XXX roth -- here, detach the initrd mounts
octx.detach()
# hold on to the ONIE boot context for grub access
if os.path.exists("/usr/bin/onie-shell"):
machineConf = OnieSysinfo(log=self.logger.getChild("onie-sysinfo"))
else:
path = os.path.join(octx.initrdDir, "etc/machine.conf")
machineConf = ConfUtils.MachineConf(path=path)
if os.path.exists(path):
machineConf = ConfUtils.MachineConf(path=path)
else:
machineConf = ConfUtils.MachineConf(path='/dev/null')
# hold on to the ONIE boot context for grub access
installerConf = ConfUtils.InstallerConf(path="/dev/null")
installerConf = ConfUtils.InstallerConf(path="/dev/null")
# XXX fill in installerConf fields
installerConf.installer_platform = onlPlatform.platform()
installerConf.installer_arch = machineConf.onie_arch
installerConf.installer_platform_dir = os.path.join("/lib/platform-config",
onlPlatform.platform())
# XXX fill in installerConf fields
installerConf.installer_platform = onlPlatform.platform()
installerConf.installer_arch = machineConf.onie_arch
installerConf.installer_platform_dir = os.path.join("/lib/platform-config",
onlPlatform.platform())
mfPath = os.path.join(sysconfig.upgrade.loader.package.dir, "manifest.json")
mf = onl.versions.OnlVersionManifest(mfPath)
installerConf.onl_version = mf.RELEASE_ID
mfPath = os.path.join(sysconfig.upgrade.loader.package.dir, "manifest.json")
mf = onl.versions.OnlVersionManifest(mfPath)
installerConf.onl_version = mf.RELEASE_ID
grubEnv = ConfUtils.ChrootGrubEnv(octx.initrdDir,
bootDir=octx.onieDir,
path="/grub/grubenv",
log=self.logger.getChild("grub"))
grubEnv = ConfUtils.ChrootGrubEnv(octx.initrdDir,
bootDir=octx.onieDir,
path="/grub/grubenv",
log=self.logger.getChild("grub"))
ubootEnv = None
ubootEnv = None
installer = self.installer_klass(machineConf=machineConf,
installerConf=installerConf,
platformConf=onlPlatform.platform_config,
grubEnv=grubEnv,
ubootEnv=ubootEnv,
force=True,
log=self.logger)
installer = self.installer_klass(machineConf=machineConf,
installerConf=installerConf,
platformConf=onlPlatform.platform_config,
grubEnv=grubEnv,
ubootEnv=ubootEnv,
force=True,
log=self.logger)
installer.upgradeBootLoader()
installer.shutdown()
installer.upgradeBootLoader()
installer.shutdown()
self.reboot()