Commit cbd68e9e authored by Mike Hibler's avatar Mike Hibler

More overhaul of the Linux fixup code.

parent 88c686b2
......@@ -669,10 +669,30 @@ dolinux() {
esac
dunit=`echo $dunit | sed -e 'y/01234567/abcdefgh/'`;
ldisk=$dtype$dunit
rootdev=/dev/${disk}s${part}
#
# See if there is a valid filesystem UUID to use in fstab and grub.
#
RUUID=""
if [ -x /usr/local/sbin/dumpe2fs ]; then
RUUID=`dumpe2fs $rootdev 2>/dev/null | grep UUID: | sed -e 's/.*UUID: *\([^ ]*\).*/\1/'`
#
# To be pedantic, we should do the following (generate a new
# UUID, but this seems to be causing strange problems with the
# UUID not always being updated. It will also cause the root FS
# to be fsck'ed everytime (see needfsck below).
#
if false && [ -n "$RUUID" -a -x /usr/local/sbin/tune2fs ]; then
# generate/install a new random UUID with tune2fs
echo " setting new root FS UUID"
tune2fs -U random $rootdev 2>/dev/null
RUUID=`dumpe2fs $rootdev 2>/dev/null | grep UUID: | sed -e 's/.*UUID: *\([^ ]*\).*/\1/'`
fi
fi
# attempt to mount filesystem
rootdev=/dev/${disk}s${part}
echo "fixing Linux root partition ${disk}s${part}"
echo " fixing Linux root partition ${disk}s${part}"
mount -t ext2fs $rootdev /mnt || {
# might need a journal recovery, try fsck
echo "EXT2FS mount failed, trying recovery..."
......@@ -694,22 +714,32 @@ dolinux() {
fi
# change the devices in fstab
echo " updating /etc/fstab"
sed -i .preemulab -e "s;^/dev/[hs]d.\([0-7]\);/dev/${ldisk}\1;" /mnt/etc/fstab || {
echo "Failed to update /etc/fstab"
umount $rootdev
return 1
}
# XXX look for newer UUID= for rootdev
sed -E -i '' -e "s;^UUID=[^ ]+ +/ ;/dev/${ldisk}${part} / ;" /mnt/etc/fstab || {
echo "Failed to update /etc/fstab"
umount $rootdev
return 1
}
#
# If filesystem has a UUID, make sure that is used in fstab.
#
# Note that we will only use the UUID if it is already being used
# in the image we just downloaded. This is just because I don't want
# to chance breaking some really old image.
#
if [ -n "$RUUID" ]; then
sed -E -i '' -e "s;^UUID=[^ ]+ +/ ;UUID=$RUUID / ;" /mnt/etc/fstab || {
echo "Failed to update /etc/fstab"
umount $rootdev
return 1
}
fi
#
# If there's a GRUB config file, update all root=X kernel params.
#
needfsck=0
fgconf=""
for f in grub.conf grub.cfg menu.lst; do
if [ -z "$fgconf" -a -r /mnt/boot/grub/$f ]; then
......@@ -717,15 +747,40 @@ dolinux() {
gconf=/mnt$fgconf
fi
done
if [ -r $gconf ]; then
if [ -n "$fgconf" -a -r "$gconf" ]; then
echo " updating $fgconf"
sed -i .preemulab \
-e "s;\([br]oot=/dev\)/[hs]d.[0-7];\1/${ldisk}${part};" \
-e "s;\([br]oot=\)UUID=[^ ]* ;\1/dev/${ldisk}${part} ;" \
$gconf || {
#
# We go out of our way to avoid changing grub.conf if we don't
# have to, since it might require us to fsck the filesystem
# afterward (see "XXX woeful hack" below).
#
tgconf="$gconf.tmp"
rm -f $tgconf
cp $gconf $tgconf || {
echo "Cannot copy $fgconf, will change in place"
cp -p $gconf $gconf.preemulab
# XXX only do this if it appears that selinux is installed
if [ -e /mnt/etc/selinux/config ]; then
needfsck=1
fi
tgconf=gconf
}
sed -i '' -e "s;\([br]oot=/dev\)/[hs]d.[0-7];\1/${ldisk}${part};" $tgconf || {
echo "Failed to update $fgconf"
}
#
# Again, replace UUID if we have one and grub conf uses it already.
#
if [ -n "$RUUID" ]; then
sed -i '' -e "s;\([br]oot=\)UUID=[^ ]* ;\1UUID=$RUUID ;" $tgconf || {
echo "Failed to update UUIDs in $fgconf"
}
fi
#
# Tweak grub's notion of root.
# Note that grub's partition numbering is zero-based.
......@@ -740,9 +795,80 @@ dolinux() {
if [ $FLASHBOOT -eq 1 ]; then
gdisk=`expr $gdisk + 1`
fi
sed -i '' -e "s;root (hd[0-9],[0-9]);root (hd${gdisk},${gpart});" $gconf || {
# grub1
sed -i '' -e "s;root (hd[0-9],[0-9]);root (hd${gdisk},${gpart});" $tgconf || {
echo "Failed to update root in $fgconf"
}
# grub2 (note 'part' and not 'gpart'; no -1 in grub2)
sed -i '' -e "s;set root='(hd[0-9],[^)]*)';set root='(hd${gdisk},${part})';" $tgconf || {
echo "Failed to update root in $fgconf"
}
#
# Console. If there is no serial console, need to modify the
# grub config to use the vga only.
#
if [ $VGAONLY = "yes" ]; then
grep -E '^terminal.*serial' $tgconf >/dev/null 2>&1
case $? in
0)
echo " changing grub terminal to console"
sed -i '' -e "s;^terminal;#terminal;" $tgconf || {
echo "Failed to update terminal line in $fgconf"
}
echo "terminal --timeout=5 console" >> $tgconf
;;
*)
;;
esac
# Added by Hussam to disable the serial line defination
grep -E '^serial.*--speed' $tgconf >/dev/null 2>&1
case $? in
0)
echo " disabling serial line config in grub"
sed -i '' -e "s;^serial;#serial;" $tgconf || {
echo "Failed to update serial line in $fgconf"
}
;;
*)
;;
esac
grep -E "console=ttyS" $tgconf >/dev/null 2>&1
case $? in
0)
echo " changing grub kernel command to console"
sed -i '' -e 's;ttyS[^ ]*;tty0;' $tgconf || {
echo "Failed to update console in $fgconf"
}
;;
*)
;;
esac
fi
#
# If we had to change something, then move the new version into
# place and mark that we did so.
#
if [ "$tgconf" != "$gconf" ]; then
cmp -s $tgconf $gconf 2>/dev/null
if [ $? -ne 0 ]; then
cp -p $gconf $gconf.preemulab
mv $tgconf $gconf || {
echo "Failed to update $fgconf"
mv $gconf.preemulab $gconf
}
# XXX only do this if it appears that selinux is installed
if [ -e /mnt/etc/selinux/config ]; then
needfsck=1
fi
fi
rm -f $tgconf
fi
fi
#
......@@ -784,56 +910,6 @@ dolinux() {
esac
done
#
# Console. If there is no serial console, need to modify the
# grub config to use the vga only.
#
if [ $VGAONLY = "yes" ]; then
grep -E '^terminal.*serial' $gconf >/dev/null 2>&1
case $? in
0)
echo " changing grub terminal to console"
sed -i .preemulab -e "s;^terminal;#terminal;" $gconf || {
echo "Failed to update terminal line in $gconf"
umount $rootdev
return 1
}
echo "terminal --timeout=5 console" >> $gconf
;;
*)
;;
esac
# Added by Hussam to disable the serial line defination
grep -E '^serial.*--speed' $gconf >/dev/null 2>&1
case $? in
0)
echo " disabling serial line config in grub"
sed -i .preemulab -e "s;^serial;#serial;" $gconf || {
echo "Failed to update serial line in $gconf"
umount $rootdev
return 1
}
;;
*)
;;
esac
grep -E "console=ttyS" $gconf >/dev/null 2>&1
case $? in
0)
echo " changing grub kernel command to console"
sed -i .preemulab -e 's;ttyS[^ ]*;tty0;' $gconf || {
echo "Failed to update console in $gconf"
umount $rootdev
return 1
}
;;
*)
;;
esac
fi
if [ -f /mnt/var/lib/random-seed -a -c /dev/urandom ]; then
echo " updating /var/lib/random-seed"
dd if=/dev/urandom of=/mnt/var/lib/random-seed bs=512 count=1 >/dev/null 2>&1
......@@ -956,13 +1032,30 @@ dolinux() {
# run any postconfig scripts:
if [ -x $BINDIR/osconfig ]; then
echo "Checking for dynamic client-side updates to slice...";
echo " checking for dynamic client-side updates to slice";
$BINDIR/osconfig -m /mnt -M '-t ext2fs' -f ext2fs \
-D $rootdev -s Linux postload
fi
umount $rootdev
#
# XXX woeful hack. On an SELinux-enabled filesystem, grub.conf
# might have an SELinux context and the BSD extfs implmentation
# doesn't know how to deal with extended attributes and leaves
# the FS in an inconsistent state. So if we changed grub.conf,
# we must fsck the filesystem to clean up.
#
if [ $needfsck -ne 0 ]; then
echo -n " ensuring FS is consistent..."
e2fsck -yf $rootdev >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "FIXED"
else
echo "OK"
fi
fi
if [ "x${linux}" != x ]; then
echo -n " "
# setup one time lilo command line, must be done after unmount
......
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