4
# To force curtin to run centos_apply_network_config vmtest, uncomment
5
# _ammend_centos_curthooks: True
9
path: '/root/curtin-send-console-to-serial'
13
# update grub1 and grub2 configs to write to serial console.
14
CONPARM="console=ttyS0,115200"
15
grub1conf="/boot/grub/grub.conf"
16
grub2conf="/boot/grub2/grub.cfg"
17
grub2def="/etc/default/grub"
19
rerror() { perror "$?" "$@"; return $r; }
20
perror() { local r="$1"; shift; error "$@"; return $r; }
21
error() { echo "GRUB_SERIAL:" "ERROR:" "$@" 1>&2; }
22
info() { echo "GRUB_SERIAL:" "$@" 1>&2; }
23
fail() { error "$@"; exit 1; }
25
local ofile="$1" bk="$1.dist.curtin"
27
[ -e "$ofile" ] || return 0
28
cp "$ofile" "$bk" || rerror "failed backup ($ofile -> $bk):" "$@";
34
{ info "no grub1 cfg '$cfg'"; return 0; }
35
bk "$cfg" "grub1 config" || return
36
if ! grep "^serial" "$cfg"; then
39
serial --unit=0 --speed=115200
40
terminal --timeout=2 serial console
44
{ perror $r "failed to append to grub1 cfg '$cfg'"; return; }
46
sed -i -e '/linux16/n' -e '/console=/n' \
47
-e "s/root=\([^ ]*\)/root=\1 ${CONPARM}/" "$cfg" ||
48
{ rerror "failed to update grub1 cfg '$cfg'."; return; }
49
info "updated grub1 cfg '$cfg'."
53
local cfg="$1" defgrub="$2"
54
[ -e "$cfg" ] || { info "no grub2 config '$cfg'"; return 0; }
55
bk "$cfg" "grub2 config" || return
56
sed -i -e '/kernel/n' -e '/console=/n' \
57
-e "s/root=\([^ ]*\)/root=\1 ${CONPARM}/" "$cfg" ||
58
{ rerror "failed to update grub2 '$cfg'"; return; }
60
# update /etc/default/grub. any GRUB_CMDLINE_LINUX remove
61
# any console= and add conparm at the beginning.
62
local var="GRUB_CMDLINE_LINUX" msg="updated grub2 '$cfg'."
63
if [ ! -e "$defgrub" ]; then
64
msg="$msg. no defaults file '$defgrub'."
66
bk "$defgrub" "grub2 defaults file" || return
67
msg="$msg. updated defaults file '$defgrub'."
70
-e 's/console=[^ "]*//g' \
71
-e "s/$var=\"/$var=\"${CONPARM}/" "$defgrub" ||
72
{ rerror "grub2 default update failed on $defgrub"; return; }
77
update_grub1 "$grub1conf" || fail "failed update grub1"
78
update_grub2 "$grub2conf" "$grub2def" || fail "failed update grub2"
81
# centos66 images include grub 0.97 which will detect vmtests' ephemeral disk
82
# and the install disk which leaves grub configured with two disks. When
83
# vmtest reboots into installed disk, there is only one disk and the grub
84
# map is no longer valid. Here in 00_grub, we switch hd1 to hd0. MAAS
85
# is not affected as their ephemeral image (iscsi or http) is not discovered
86
# by grub and therefor the device.map doesn't contain a second device. Cent7
87
# has grub2 which uses root by UUID
88
00_grub1_boot: [curtin, in-target, --, sed, -i.curtin, -e,
89
's|(hd1,0)|(hd0,0)|g', /boot/grub/grub.conf]
90
# vmtest wants output to go to serial console so we update grub inside.
91
00_grub_serial: [curtin, in-target, --, '/root/curtin-send-console-to-serial']