Date: Mon, 10 Jun 2019 15:46:19 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348865 - in stable/12/stand: common i386/zfsboot Message-ID: <201906101546.x5AFkJDH097624@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Mon Jun 10 15:46:19 2019 New Revision: 348865 URL: https://svnweb.freebsd.org/changeset/base/348865 Log: MFC r348569: [zfsboot] Fix boot env back compat (#190) * Fix boot env back compat zfsboot must try zfsloader before loader in order to remain compatible with boot environments created prior to zfs functionality being rolled into loader proper. * Improve comments in zfsboot Explain the significance of the load path order, and put the comment about looping through the paths in the appropriate scope. Modified: stable/12/stand/common/paths.h stable/12/stand/i386/zfsboot/zfsboot.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/common/paths.h ============================================================================== --- stable/12/stand/common/paths.h Mon Jun 10 15:44:09 2019 (r348864) +++ stable/12/stand/common/paths.h Mon Jun 10 15:46:19 2019 (r348865) @@ -33,6 +33,7 @@ #define PATH_CONFIG "/boot/config" #define PATH_LOADER "/boot/loader" #define PATH_LOADER_EFI "/boot/loader.efi" +#define PATH_LOADER_ZFS "/boot/zfsloader" #define PATH_KERNEL "/boot/kernel/kernel" #endif /* _PATHS_H_ */ Modified: stable/12/stand/i386/zfsboot/zfsboot.c ============================================================================== --- stable/12/stand/i386/zfsboot/zfsboot.c Mon Jun 10 15:44:09 2019 (r348864) +++ stable/12/stand/i386/zfsboot/zfsboot.c Mon Jun 10 15:46:19 2019 (r348865) @@ -87,6 +87,24 @@ static const unsigned char flags[NOPT] = { }; uint32_t opts; +/* + * Paths to try loading before falling back to the boot2 prompt. + * + * /boot/zfsloader must be tried before /boot/loader in order to remain + * backward compatible with ZFS boot environments where /boot/loader exists + * but does not have ZFS support, which was the case before FreeBSD 12. + * + * If no loader is found, try to load a kernel directly instead. + */ +static const struct string { + const char *p; + size_t len; +} loadpath[] = { + { PATH_LOADER_ZFS, sizeof(PATH_LOADER_ZFS) }, + { PATH_LOADER, sizeof(PATH_LOADER) }, + { PATH_KERNEL, sizeof(PATH_KERNEL) }, +}; + static const unsigned char dev_maj[NDEV] = {30, 4, 2}; static char cmd[512]; @@ -838,16 +856,17 @@ main(void) if (nextboot && !autoboot) reboot(); - /* - * Try to exec /boot/loader. If interrupted by a keypress, - * or in case of failure, try to load a kernel directly instead. - */ - if (autoboot && !*kname) { - memcpy(kname, PATH_LOADER, sizeof(PATH_LOADER)); - if (!keyhit(3)) { + /* + * Iterate through the list of loader and kernel paths, trying to load. + * If interrupted by a keypress, or in case of failure, drop the user + * to the boot2 prompt. + */ + for (i = 0; i < nitems(loadpath); i++) { + memcpy(kname, loadpath[i].p, loadpath[i].len); + if (keyhit(3)) + break; load(); - memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL)); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906101546.x5AFkJDH097624>