Commit 4c76e8f0 authored by Mike Hibler's avatar Mike Hibler

You can now interact with grub on the d430s!

Apparently, specifying "--unit==1" to grub did not work because grub
didn't think it had a unit 1 (aka, COM2), so it rejected the "serial"
command. Output still worked due to redirection (I think), but it was
expecting input from the keyboard.

It looks like the number of valid serial ports is compiled into grub and
who knows how it was built for Ubuntu. Anyway, by specifying "--port=0x2F8"
in addition, that will override the unit test and all is well. Strange.

Also enhanced the Linux slicefix to deal with fixing /etc/default/grub so
that those wacky console settings will remain in effect even if grub is
re-configured (which some packages do).
parent d7bc919d
...@@ -194,6 +194,23 @@ if [ $CONSOLE = "unknown" ]; then ...@@ -194,6 +194,23 @@ if [ $CONSOLE = "unknown" ]; then
CONSOLE=sio1 CONSOLE=sio1
fi fi
# Console ISA port
PORT=
case $CONSOLE in
sio1)
PORT="0x3F8"
;;
sio2)
PORT="0x2F8"
;;
sio3)
PORT="0x3E8"
;;
sio4)
PORT="0x2E8"
;;
esac
# DOM0MEM is optional # DOM0MEM is optional
DOM0MEM=$SLICEFIX_DOM0MEM DOM0MEM=$SLICEFIX_DOM0MEM
...@@ -652,25 +669,21 @@ EOF0 ...@@ -652,25 +669,21 @@ EOF0
sio1) sio1)
cname="comconsole" cname="comconsole"
unit=0 unit=0
port=0x3F8
irq=4 irq=4
;; ;;
sio2) sio2)
cname="comconsole" cname="comconsole"
unit=1 unit=1
port=0x2F8
irq=3 irq=3
;; ;;
sio3) sio3)
cname="comconsole" cname="comconsole"
unit=2 unit=2
port=0x3E8
irq=5 irq=5
;; ;;
sio4) sio4)
cname="comconsole" cname="comconsole"
unit=3 unit=3
port=0x2E8
irq=9 irq=9
;; ;;
esac esac
...@@ -704,14 +717,14 @@ EOF1 ...@@ -704,14 +717,14 @@ EOF1
if [ $drv != "none" ]; then if [ $drv != "none" ]; then
# put in the new info # put in the new info
cat <<EOF2 >>/mnt/boot/loader.conf cat <<EOF2 >>/mnt/boot/loader.conf
comconsole_port="$port" comconsole_port="$PORT"
comconsole_speed="$SPEED" comconsole_speed="$SPEED"
hint.$drv.0.flags="0x0" hint.$drv.0.flags="0x0"
hint.$drv.1.flags="0x0" hint.$drv.1.flags="0x0"
hint.$drv.2.flags="0x0" hint.$drv.2.flags="0x0"
hint.$drv.3.flags="0x0" hint.$drv.3.flags="0x0"
hint.$drv.$unit.at="isa" hint.$drv.$unit.at="isa"
hint.$drv.$unit.port="$port" hint.$drv.$unit.port="$PORT"
hint.$drv.$unit.irq="$irq" hint.$drv.$unit.irq="$irq"
hint.$drv.$unit.flags="0x10" hint.$drv.$unit.flags="0x10"
hint.$drv.$unit.disabled="0" hint.$drv.$unit.disabled="0"
...@@ -1109,7 +1122,14 @@ dolinux() { ...@@ -1109,7 +1122,14 @@ dolinux() {
# terminal_input serial # grub2 # terminal_input serial # grub2
# terminal_output serial # grub2 # terminal_output serial # grub2
# #
# XXX we have a situation where SOL redirection puts the console
# at --unit=1, but grub does not recognize that as a valid unit
# and the result is that grub does not accept console input.
# But if we specify --port=0x2F8 it works fine. So we put both
# (this is documented, --port takes precedence).
#
echo " setting console to $CONSOLE" echo " setting console to $CONSOLE"
pstr=""
case $CONSOLE in case $CONSOLE in
null|vid) null|vid)
# comment out any "serial" line # comment out any "serial" line
...@@ -1167,8 +1187,13 @@ dolinux() { ...@@ -1167,8 +1187,13 @@ dolinux() {
u=`expr ${CONSOLE#sio} - 1` u=`expr ${CONSOLE#sio} - 1`
s=$SPEED s=$SPEED
# XXX we only put in the --port=NNN option if this is grub2
if grep -q '^terminal_input' $tgconf 2>/dev/null; then
pstr="--port=$PORT"
fi
# put back the "serial" line # put back the "serial" line
sstr="serial --unit=$u --speed=$s" sstr="serial --unit=$u $pstr --speed=$s"
if ! grep -q -- "^$sstr" $tgconf 2>/dev/null; then if ! grep -q -- "^$sstr" $tgconf 2>/dev/null; then
sed -E -i '' -e "s;^#?serial.*;$sstr;" $tgconf sed -E -i '' -e "s;^#?serial.*;$sstr;" $tgconf
fi fi
...@@ -1248,60 +1273,62 @@ dolinux() { ...@@ -1248,60 +1273,62 @@ dolinux() {
fi fi
rm -f $tgconf rm -f $tgconf
fi fi
fi
# #
# Handle default settings file for grub since package installation # Handle default settings file for grub since package installation
# might cause the grub.cfg file to get recreated. # might cause the grub.cfg file to get recreated.
# #
# We just append variable definitions to the end of the file and # We just append variable definitions to the end of the file and
# override any existing settings. This would only adversely affect the # override any existing settings. This would only adversely affect
# GRUB_CMDLINE_LINUX param if it was being used for some other options. # the GRUB_CMDLINE_LINUX param if it was being used for some other
# For vid or null we add: # options.
# #
# GRUB_CMDLINE_LINUX="console=tty0" # For vid or null we add:
# GRUB_TERMINAL=console #
# GRUB_SERIAL_COMMAND="" # GRUB_CMDLINE_LINUX="console=tty0"
# # GRUB_TERMINAL=console
# and for sio[1-3] we add: # GRUB_SERIAL_COMMAND=""
# #
# GRUB_CMDLINE_LINUX="console=ttySN,S" # and for sio[1-3] we add:
# GRUB_TERMINAL=serial #
# GRUB_SERIAL_COMMAND="serial --speed=S --unit=N" # GRUB_CMDLINE_LINUX="console=ttySN,S"
# # GRUB_TERMINAL=serial
gdef="/mnt/etc/default/grub" # GRUB_SERIAL_COMMAND="serial --speed=S --unit=N"
if [ -e "$gdef" ]; then #
echo " updating /etc/default/grub" gdef="/mnt/etc/default/grub"
echo " setting console to $CONSOLE" if [ -e "$gdef" ]; then
esig="# The remaining lines were added by Emulab slicefix" echo " updating /etc/default/grub"
if ! grep -q "^$esig" $gdef; then echo " setting console to $CONSOLE"
cp -p $gdef $gdef.preemulab esig="# The remaining lines were added by Emulab slicefix"
else if ! grep -q "^$esig" $gdef; then
sed -i '' -e "/^$esig/,$$d" $gdef cp -p $gdef $gdef.preemulab
fi else
cat <<EOF5 >>$gdef sed -i '' -e "/^$esig/,$$d" $gdef
fi
cat <<EOF5 >>$gdef
$esig $esig
# DO NOT ADD ANYTHING AFTER THIS POINT AS IT WILL GET REMOVED. # DO NOT ADD ANYTHING AFTER THIS POINT AS IT WILL GET REMOVED.
EOF5 EOF5
case $CONSOLE in case $CONSOLE in
null|vid) null|vid)
cat <<EOF6 >>$gdef cat <<EOF6 >>$gdef
GRUB_CMDLINE_LINUX="console=tty0" GRUB_CMDLINE_LINUX="console=tty0"
GRUB_TERMINAL=console GRUB_TERMINAL=console
GRUB_SERIAL_COMMAND="" GRUB_SERIAL_COMMAND=""
EOF6 EOF6
;; ;;
sio*) sio*)
u=`expr ${CONSOLE#sio} - 1` u=`expr ${CONSOLE#sio} - 1`
s=$SPEED s=$SPEED
cat <<EOF7 >>$gdef cat <<EOF7 >>$gdef
GRUB_CMDLINE_LINUX="console=ttyS$u,$s" GRUB_CMDLINE_LINUX="console=ttyS$u,$s"
GRUB_TERMINAL=serial GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=$s --unit=$u" GRUB_SERIAL_COMMAND="serial --unit=$u $pstr --speed=$s"
EOF7 EOF7
;; ;;
esac esac
needfsck=1 needfsck=1
fi
fi fi
# #
......
...@@ -855,7 +855,7 @@ sub update_random_seed ...@@ -855,7 +855,7 @@ sub update_random_seed
sub fix_console sub fix_console
{ {
my ($imageroot, $file) = @_; my ($imageroot, $bloader, $file) = @_;
my $console = $ENV{"SLICEFIX_CONSOLE"}; my $console = $ENV{"SLICEFIX_CONSOLE"};
if (!$console) { if (!$console) {
...@@ -873,11 +873,18 @@ sub fix_console ...@@ -873,11 +873,18 @@ sub fix_console
} }
my $sunit = -1; my $sunit = -1;
my $sport = "";
if ($console =~ /^sio(\d+)$/) { if ($console =~ /^sio(\d+)$/) {
$sunit = ($1 > 1) ? $1 - 1 : 0; $sunit = ($1 > 1) ? $1 - 1 : 0;
if ($bloader eq 'grub2' && $sunit < 4) {
my @smap = ("0x3F8", "0x2F8", "0x3E8", "0x2E8");
$sport = $smap[$sunit];
}
} }
fix_grub_console($imageroot, $file, $console, $sunit, $sspeed); fix_grub_console($imageroot, $file, $console, $sunit, $sspeed, $sport);
fix_grub_defaults($imageroot, $console, $sunit, $sspeed, $sport);
# XXX we don't bother with /etc/inittab, only RHLnn-STD used it # XXX we don't bother with /etc/inittab, only RHLnn-STD used it
...@@ -921,9 +928,79 @@ sub fix_console ...@@ -921,9 +928,79 @@ sub fix_console
} }
} }
#
# Handle default settings file for grub since package installation
# might cause the grub.cfg file to get recreated.
#
# We just append variable definitions to the end of the file and
# override any existing settings. This would only adversely affect the
# GRUB_CMDLINE_LINUX param if it was being used for some other options.
# For vid or null we add:
#
# GRUB_CMDLINE_LINUX="console=tty0"
# GRUB_TERMINAL=console
# GRUB_SERIAL_COMMAND=""
#
# and for sio[1-3] we add:
#
# GRUB_CMDLINE_LINUX="console=ttySN,S"
# GRUB_TERMINAL=serial
# GRUB_SERIAL_COMMAND="serial --speed=S --unit=N"
#
sub fix_grub_defaults
{
my ($imageroot, $console, $sunit, $sspeed, $sport) = @_;
my $gdef = "$imageroot/etc/default/grub";
if (! -e $gdef) {
return;
}
if (! -e "$gdef.preemulab") {
system("cp -p $gdef $gdef.preemulab");
}
if (!open(FILE, "+<$gdef")) {
return;
}
my $esig = "# The remaining lines were added by Emulab slicefix";
my @buffer = ();
while (<FILE>) {
if (/^$esig/) {
last;
}
push @buffer, $_;
}
# append our info
push @buffer, "$esig\n";
push @buffer, "# DO NOT ADD ANYTHING AFTER THIS POINT AS IT WILL GET REMOVED.\n";
if ($sunit < 0) {
push @buffer, "GRUB_CMDLINE_LINUX=\"console=tty0\"\n";
push @buffer, "GRUB_TERMINAL=console\n";
push @buffer, "GRUB_SERIAL_COMMAND=\"\"\n";
} else {
push @buffer, "GRUB_CMDLINE_LINUX=\"console=ttyS$sunit,$sspeed\"\n";
push @buffer, "GRUB_TERMINAL=serial\n";
if ($sport) {
push @buffer, "GRUB_SERIAL_COMMAND=\"serial --unit=$sunit --port=$sport --speed=$sspeed\"\n";
} else {
push @buffer, "GRUB_SERIAL_COMMAND=\"serial --unit=$sunit --speed=$sspeed\"\n";
}
}
seek FILE, 0, 0;
truncate FILE, 0;
print FILE @buffer;
close FILE;
}
sub fix_grub_console sub fix_grub_console
{ {
my ($imageroot, $file, $console, $sunit, $sspeed) = @_; my ($imageroot, $file, $console, $sunit, $sspeed, $sport) = @_;
my $comunit = $sunit + 1; my $comunit = $sunit + 1;
open FILE, "+<$imageroot/$file" || open FILE, "+<$imageroot/$file" ||
...@@ -944,6 +1021,8 @@ sub fix_grub_console ...@@ -944,6 +1021,8 @@ sub fix_grub_console
} else { } else {
push @buffer, "#$_"; push @buffer, "#$_";
} }
} elsif ($sport) {
push @buffer, "serial --unit=$sunit --port=$sport --speed=$sspeed\n";
} else { } else {
push @buffer, "serial --unit=$sunit --speed=$sspeed\n"; push @buffer, "serial --unit=$sunit --speed=$sspeed\n";
} }
...@@ -1360,7 +1439,7 @@ sub main ...@@ -1360,7 +1439,7 @@ sub main
set_grub2_root_device($imageroot, $grub_config, $root); set_grub2_root_device($imageroot, $grub_config, $root);
} }
fix_grub_dom0mem($imageroot, $grub_config); fix_grub_dom0mem($imageroot, $grub_config);
fix_console($imageroot, $grub_config); fix_console($imageroot, $bootloader, $grub_config);
fix_swap_partitions($imageroot, $root, fix_swap_partitions($imageroot, $root,
$kernel_has_ide ? $old_root : undef ); $kernel_has_ide ? $old_root : undef );
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Copyright (c) 2000-2015 University of Utah and the Flux Group. # Copyright (c) 2000-2016 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -49,6 +49,7 @@ my $VARACCTDIR = "/var/account"; ...@@ -49,6 +49,7 @@ my $VARACCTDIR = "/var/account";
my $VARACCTSDIR = "/var/log/sa"; my $VARACCTSDIR = "/var/log/sa";
my $IFTAB = "/etc/iftab"; my $IFTAB = "/etc/iftab";
my $ANACRON = "/usr/sbin/anacron"; my $ANACRON = "/usr/sbin/anacron";
my $GRUBDEF = "/etc/default/grub";
# #
# Dead wood in $BINDIR # Dead wood in $BINDIR
...@@ -353,6 +354,11 @@ if (-f $driftfile) { ...@@ -353,6 +354,11 @@ if (-f $driftfile) {
close(DRIFT); close(DRIFT);
} }
if (-f "$GRUBDEF.preemulab") {
print "Restoring original $GRUBDEF file ...\n";
system("cp -p $GRUBDEF.preemulab $GRUBDEF");
}
print "Clearing out $RUNDIR ...\n"; print "Clearing out $RUNDIR ...\n";
system("rm -rf $RUNDIR/*.pid $RUNDIR/sudo/* $RUNDIR/pump.sock"); system("rm -rf $RUNDIR/*.pid $RUNDIR/sudo/* $RUNDIR/pump.sock");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment