2014-06-19 08:22:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#Used only by sysclone
|
|
|
|
|
2014-06-23 09:00:26 +00:00
|
|
|
# SI post-install script to configure the efi boot mgr or grub after SI has installed the OS
|
|
|
|
# SI post-install scripts run in a chroot environment of the final OS image
|
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
arch=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/`
|
|
|
|
if [ "$arch" = "x86_64" ]; then
|
|
|
|
if [ -d /sys/firmware/efi ]; then
|
|
|
|
echo "Setting Boot Manager for the next boot."
|
|
|
|
echo "delete all sysclone boot list"
|
|
|
|
str_bootnums=`efibootmgr | grep 'syscloneLinux' | awk '{print $1}' | sed 's/boot//i' | sed 's/*//'`
|
|
|
|
for str_num in $str_bootnums
|
|
|
|
do
|
|
|
|
efibootmgr -b $str_num -B -q
|
|
|
|
done
|
2013-08-27 03:16:47 +00:00
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
if [ -f "/boot/efi/EFI/redhat/grub.efi" ];then
|
|
|
|
efibootmgr -c -l \\EFI\\redhat\\grub.efi -L syscloneLinux
|
2014-11-05 02:40:49 +00:00
|
|
|
#support for redhat 7.0
|
|
|
|
elif [ -f "/boot/efi/EFI/redhat/grubx64.efi" ];then
|
|
|
|
efibootmgr -c -l \\EFI\\redhat\\grubx64.efi -L syscloneLinux
|
|
|
|
|
|
|
|
boot_root=`mount | grep -E ' on\s+/ type ' | awk '{print $1}'`
|
2014-11-19 08:32:12 +00:00
|
|
|
sed -i 's| root=\S*| root='$boot_root' net.ifnames=0|' /boot/efi/EFI/redhat/grub.cfg
|
2014-11-05 02:40:49 +00:00
|
|
|
|
|
|
|
blkid -c /dev/null |grep UUID|while read str_line
|
|
|
|
do
|
|
|
|
partition=`echo "$str_line"|grep UUID|awk '{print $1}'|sed -e 's|/dev/\(.*\):|\1|g'`
|
|
|
|
#echo "partition=$partition"
|
|
|
|
|
|
|
|
if echo "$partition"|grep /; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
newuuid=`blkid -c /dev/null|grep "$partition"|sed -e 's|.*UUID="\(.*\)" T.*|\1|g'`
|
|
|
|
#echo "newuuid=$newuuid"
|
|
|
|
sed -i '/'$partition'/s|UUID=\S*|UUID='$newuuid'|' /etc/fstab
|
|
|
|
done
|
2014-08-25 07:23:47 +00:00
|
|
|
elif [ -f "/boot/efi/efi/SuSE/elilo.efi" ];then
|
|
|
|
efibootmgr -c -l \\efi\\SuSE\\elilo.efi -L syscloneLinux
|
|
|
|
else
|
|
|
|
echo "Can not find the boot loader."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "run grub-install to configure the MBR."
|
|
|
|
if [ -e /etc/mtab ];then
|
|
|
|
mv /etc/mtab /etc/mtab.bak
|
|
|
|
fi
|
|
|
|
grep -v rootfs /proc/mounts > /etc/mtab
|
|
|
|
boot_device=''
|
|
|
|
if [ -f "/etc/systemconfig/systemconfig.conf" ];then
|
2014-10-22 09:23:43 +00:00
|
|
|
#boot_root=`cat /etc/systemconfig/systemconfig.conf | grep ROOTDEV | awk '{print $3}'`
|
|
|
|
boot_root=`mount | grep -E ' on\s+/ type ' | awk '{print $1}'`
|
2014-08-25 07:23:47 +00:00
|
|
|
boot_device=`cat /etc/systemconfig/systemconfig.conf | grep BOOTDEV | awk '{print $3}'`
|
|
|
|
else
|
|
|
|
boot_root=`mount | grep -E ' on\s+/ type ' | awk '{print $1}'`
|
|
|
|
boot_device=`echo $boot_root | sed -e 's/[0-9]*$//'`
|
2014-06-23 09:00:26 +00:00
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
#str_temp=`mount | awk '{print $1","$3}'`
|
|
|
|
#for line in $str_temp
|
|
|
|
#do
|
|
|
|
# mp=`echo $line | awk -F, '{print $2}'`
|
|
|
|
# if [ "$mp" = "/" ];then
|
|
|
|
# boot_device=`echo $line | awk -F, '{print $1}' | sed -e 's/[0-9]*$//'`
|
|
|
|
# break
|
|
|
|
# fi
|
|
|
|
#done
|
|
|
|
fi
|
2013-08-23 05:58:53 +00:00
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
if [ -n "$boot_device" ];then
|
|
|
|
echo "The boot device is $boot_device"
|
|
|
|
echo "The boot root device is $boot_root"
|
|
|
|
else
|
|
|
|
echo "Can not find the boot device, return error"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set grub to use this boot device
|
|
|
|
if grep -qe '^VERSION\s*=\s*11' /etc/SuSE-release; then
|
|
|
|
#sles11, run grub-install.unsupported directly
|
|
|
|
echo "grub-install.unsupported --no-floppy --recheck $boot_device"
|
|
|
|
grub-install.unsupported --no-floppy --recheck $boot_device
|
|
|
|
# note: the error about grub-set-default not existing is harmless, because we want the default to be 0 anyway
|
|
|
|
else
|
|
|
|
#for sles10, should run grub-install with parameters
|
|
|
|
echo "grub-install --no-floppy --recheck $boot_device"
|
|
|
|
grub-install --no-floppy --recheck $boot_device
|
|
|
|
fi
|
2014-06-23 09:00:26 +00:00
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
# change the entries in the grub conf file to use the correct boot root device
|
|
|
|
# (not the one leftover from the golden image)
|
|
|
|
if [ -f "/boot/grub/grub.conf" ];then
|
|
|
|
conffile="/boot/grub/grub.conf"
|
|
|
|
else
|
|
|
|
conffile="/boot/grub/menu.lst"
|
|
|
|
fi
|
|
|
|
sed -i 's| root=\S*| root='$boot_root'|' $conffile
|
|
|
|
sed -i 's| resume=\S*| noresume|' $conffile
|
2014-06-23 09:00:26 +00:00
|
|
|
|
2014-08-25 07:23:47 +00:00
|
|
|
if [ -e /etc/mtab.bak ];then
|
|
|
|
mv -f /etc/mtab.bak /etc/mtab
|
|
|
|
else
|
|
|
|
rm -f /etc/mtab
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "$arch" = "ppc64" ]; then
|
2014-11-05 06:50:45 +00:00
|
|
|
echo "Choose suitale boot loader to configure the MBR."
|
2014-08-25 07:23:47 +00:00
|
|
|
if [ -f "/usr/lib/yaboot/yaboot" ]; then
|
|
|
|
# set bootloader
|
2014-11-05 06:50:45 +00:00
|
|
|
echo "Using /usr/lib/yaboot/yaboot"
|
2014-08-25 07:23:47 +00:00
|
|
|
echo "dd if=/usr/lib/yaboot/yaboot of=/dev/sda1 bs=4096"
|
|
|
|
dd if=/usr/lib/yaboot/yaboot of=/dev/sda1 bs=4096
|
|
|
|
|
|
|
|
# Set 0x41 as the partition type of the first partition
|
2014-09-01 08:03:49 +00:00
|
|
|
# echo A | dd of=/dev/sda bs=1 count=1 seek=450
|
2014-08-25 07:23:47 +00:00
|
|
|
elif [ -f "/lib/lilo/pmac/yaboot" ]; then
|
|
|
|
# set bootloader
|
2014-11-05 06:50:45 +00:00
|
|
|
echo "using /lib/lilo/pmac/yaboot"
|
2014-08-25 07:23:47 +00:00
|
|
|
echo "dd if=/lib/lilo/pmac/yaboot of=/dev/sda1 bs=4096"
|
|
|
|
dd if=/lib/lilo/pmac/yaboot of=/dev/sda1 bs=4096
|
|
|
|
|
|
|
|
# Set 0x41 as the partition type of the first partition
|
2014-09-01 08:03:49 +00:00
|
|
|
# echo A | dd of=/dev/sda bs=1 count=1 seek=450
|
2014-11-05 02:40:49 +00:00
|
|
|
elif [ -f "/boot/grub2/grub" ];then
|
2014-11-05 06:50:45 +00:00
|
|
|
echo "using /boot/grub2/grub"
|
2014-11-05 02:40:49 +00:00
|
|
|
echo "dd if=/boot/grub2/grub of=/dev/sda1 bs=4096"
|
|
|
|
dd if=/boot/grub2/grub of=/dev/sda1 bs=4096
|
|
|
|
|
|
|
|
boot_root=`mount | grep -E ' on\s+/ type ' | awk '{print $1}'`
|
2014-11-19 08:32:12 +00:00
|
|
|
sed -i 's| root=UUID=\S*| root='$boot_root' net.ifnames=0|' /boot/grub2/grub.cfg
|
2014-11-05 02:40:49 +00:00
|
|
|
|
|
|
|
blkid -c /dev/null |grep UUID|while read str_line
|
|
|
|
do
|
|
|
|
partition=`echo "$str_line"|grep UUID|awk '{print $1}'|sed -e 's|/dev/\(.*\):|\1|g'`
|
|
|
|
#echo "partition=$partition"
|
|
|
|
|
|
|
|
if echo "$partition"|grep /; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
newuuid=`blkid -c /dev/null|grep "$partition"|sed -e 's|.*UUID="\(.*\)" T.*|\1|g'`
|
|
|
|
#echo "newuuid=$newuuid"
|
|
|
|
sed -i '/'$partition'/s|UUID=\S*|UUID='$newuuid'|' /etc/fstab
|
|
|
|
done
|
2013-08-23 05:58:53 +00:00
|
|
|
else
|
2014-11-05 02:40:49 +00:00
|
|
|
echo "Can not find boot loader"
|
2014-08-25 07:23:47 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "[ERROR]: unsupport arch....."
|
|
|
|
fi
|
|
|
|
|