Date: Thu, 9 May 2002 00:51:36 -0700 (PDT) From: Gordon Tetlow <gordont@gnf.org> To: hackers@freebsd.org Subject: nextboot loader diff Message-ID: <Pine.LNX.4.44.0205090040130.558-200000@smtp.gnf.org>
index | next in thread | raw e-mail
[-- Attachment #1 --]
I've finally learned enough forth to put together a diff to implement some
nextboot functionality in the loader.
Basically, the loader peeks into the first line of /boot/nextboot.conf to
see if nextboot_enable="YES" is there. If it is, it reads the entire
config, then rewrites the first line to nextboot_enable="NO"
The difference between this code and Wes Peters' is that this will rewrite
the /boot/nextboot.conf so that if you boot a kernel and it hangs before
entering multi-user, upon the machine resetting, it will then restore back
to the original settings and (hopefully) come back up on a known good
kernel. This should make it easier to test out kernels on machines that
you don't have console access to.
There is a quick shell script called nextboot to manage the
/boot/nextboot.conf file and let's you set 2 common loader arguments. It
was a quick hack and probably needs to be cleaned up before a commit.
To use the patch:
cd /usr/src
patch < /path/to/patch
cd /usr/src/sbin/reboot
make all install
cd /usr/src/sys/boot
make install
Let me know what you think.
-gordon
[-- Attachment #2 --]
--- sbin/reboot/Makefile.orig Thu May 9 00:31:21 2002
+++ sbin/reboot/Makefile Thu May 9 00:30:21 2002
@@ -14,4 +14,6 @@
LINKS= ${BINDIR}/reboot ${BINDIR}/halt ${BINDIR}/reboot ${BINDIR}/fastboot \
${BINDIR}/reboot ${BINDIR}/fasthalt
+SCRIPTS= nextboot
+
.include <bsd.prog.mk>
--- /dev/null Thu May 9 00:22:00 2002
+++ sbin/reboot/nextboot.sh Thu May 9 00:15:47 2002
@@ -0,0 +1,56 @@
+#! /bin/sh
+#
+# Copyright 2002. Gordon Tetlow. All rights reserved.
+#
+# $FreeBSD$
+
+delete="NO"
+force="NO"
+nextboot_file="/boot/nextboot.conf"
+
+display_usage() {
+ echo "Usage: nextboot [-f] [-o options] -k kernel"
+ echo " nextboot -D"
+}
+
+while getopts "Dfk:o:" argument ; do
+ case "${argument}" in
+ D)
+ delete="YES"
+ ;;
+ f)
+ force="YES"
+ ;;
+ k)
+ kernel="${OPTARG}"
+ ;;
+ o)
+ kernel_options="${OPTARG}"
+ ;;
+ *)
+ display_usage
+ exit 1
+ ;;
+ esac
+done
+
+if [ ${delete} = "YES" ]; then
+ rm -f ${nextboot_file}
+ exit 0
+fi
+
+if [ "xxx${kernel}" = "xxx" ]; then
+ display_usage
+ exit 1
+fi
+
+if [ ${force} = "NO" -a ! -d /boot/${kernel} ]; then
+ echo "Error: /boot/${kernel} doesn't exist. Use -f to override."
+ exit 1
+fi
+
+cat > ${nextboot_file} << EOF
+nextboot_enable="YES"
+kernel="${kernel}"
+kernel_options="${kernel_options}"
+EOF
--- sys/boot/forth/loader.4th.orig Sun Dec 16 00:44:40 2001
+++ sys/boot/forth/loader.4th Wed May 8 22:02:36 2002
@@ -134,6 +134,7 @@
: start ( -- ) ( throws: abort & user-defined )
s" /boot/defaults/loader.conf" initialize
include_conf_files
+ include_nextboot_file
\ Will *NOT* try to load kernel and modules if no configuration file
\ was succesfully loaded!
any_conf_read? if
@@ -151,6 +152,7 @@
: initialize ( -- flag )
s" /boot/defaults/loader.conf" initialize
include_conf_files
+ include_nextboot_file
any_conf_read?
;
--- sys/boot/forth/loader.conf.orig Tue Apr 30 22:44:52 2002
+++ sys/boot/forth/loader.conf Wed May 8 23:11:16 2002
@@ -22,7 +22,9 @@
userconfig_script_name="/boot/kernel.conf"
userconfig_script_type="userconfig_script"
-loader_conf_files="/boot/device.hints /boot/loader.conf /boot/loader.conf.local /boot/nextboot.conf"
+loader_conf_files="/boot/device.hints /boot/loader.conf /boot/loader.conf.local"
+nextboot_conf="/boot/nextboot.conf"
+nextboot_enable="NO"
verbose_loading="NO" # Set to YES for verbose loader output
--- sys/boot/forth/support.4th.orig Sun Dec 16 00:44:41 2001
+++ sys/boot/forth/support.4th Wed May 8 23:07:57 2002
@@ -208,10 +208,12 @@
\ Global variables
string conf_files
+string nextboot_conf_file
string password
create module_options sizeof module.next allot 0 module_options !
create last_module_option sizeof module.next allot 0 last_module_option !
0 value verbose?
+0 value nextboot?
\ Support string functions
@@ -660,6 +662,14 @@
s" loader_conf_files" assignment_type?
;
+: nextboot_flag?
+ s" nextboot_enable" assignment_type?
+;
+
+: nextboot_conf?
+ s" nextboot_conf" assignment_type?
+;
+
: verbose_flag?
s" verbose_loading" assignment_type?
;
@@ -713,6 +723,19 @@
conf_files .len ! conf_files .addr !
;
+: set_nextboot_conf
+ nextboot_conf_file .addr @ ?dup if
+ free-memory
+ then
+ value_buffer .addr @ c@ [char] " = if
+ value_buffer .addr @ char+ value_buffer .len @ 2 chars -
+ else
+ value_buffer .addr @ value_buffer .len @
+ then
+ strdup
+ nextboot_conf_file .len ! nextboot_conf_file .addr !
+;
+
: append_to_module_options_list ( addr -- )
module_options @ 0= if
dup module_options !
@@ -863,6 +886,10 @@
then
;
+: set_nextboot_flag
+ yes_value? to nextboot?
+;
+
: set_verbose
yes_value? to verbose?
;
@@ -890,6 +917,8 @@
: process_assignment
name_buffer .len @ 0= if exit then
loader_conf_files? if set_conf_files exit then
+ nextboot_flag? if set_nextboot_flag exit then
+ nextboot_conf? if set_nextboot_conf exit then
verbose_flag? if set_verbose exit then
execute? if execute_command exit then
password? if set_password exit then
@@ -922,6 +951,10 @@
0 value_buffer .len !
;
+: get_nextboot_conf_file ( -- addr len )
+ nextboot_conf_file .addr @ nextboot_conf_file .len @ strdup
+;
+
\ Higher level file processing
support-functions definitions
@@ -939,6 +972,20 @@
repeat
;
+: peek_nextboot_file
+ get_nextboot_conf_file
+ 0 to end_of_file?
+ reset_line_reading
+ O_RDONLY fopen fd !
+ fd @ -1 = if open_error throw then
+ reset_assignment_buffers
+ read_line
+ get_assignment
+ ['] process_assignment catch
+ ['] free_buffers catch
+ fd @ fclose
+;
+
only forth also support-functions definitions
\ Interface to loading conf files
@@ -1099,6 +1146,28 @@
process_conf_errors
recurse_on_conf_files? if recurse then
repeat
+;
+
+: get_nextboot_conf_file ( -- addr len )
+ nextboot_conf_file .addr @ nextboot_conf_file .len @ strdup
+;
+
+: rewrite_nextboot_file ( -- )
+ get_nextboot_conf_file
+ O_WRONLY fopen fd !
+ fd @ -1 = if open_error throw then
+ fd @ s' nextboot_enable="NO" ' fwrite
+ fd @ fclose
+;
+
+: include_nextboot_file
+ ['] peek_nextboot_file catch
+ nextboot? if
+ get_nextboot_conf_file
+ ['] load_conf catch
+ process_conf_errors
+ ['] rewrite_nextboot_file catch
+ then
;
\ Module loading functions
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.44.0205090040130.558-200000>
