rob-mengert
January 8th, 2015, 10:48 PM
Hello everyone. I have a dual boot of Ubuntu desktop 14.04 and Ubuntu server 14.04 on a machine. I'm going to manage the machine through another host and was looking for a way in a deterministic fashion to boot either the desktop or server install without having to watch the machine boot and selecting from the grub menu. I wrote a script which rewrites GRUB_DEFAULT in /etc/default/grub based on what I would like to boot next.
Running the script while the desktop install is active causes the next boot to go into the server install as expected. Unfortunately running the same script on the server install does not force the next boot to go into the desktop install. The server install seems to be modifying a different /etc/default/grub file than what is actually being used to boot the machine. Running the script on the server to change the value of GRUB_DEFAULT from 4 (server install) to 0 (desktop install) does not work, when the machine boots next the 4th item is still highlighted in the grub menu and the server install boots again.
#!/bin/bash
bootPref=$1
# Perform argument validation
if [ $# -ne 1 ] ; then
echo -e "Too many parameters passed, acceptable parameters:\r
server \r
desktop"
exit 0
fi
# Confirm user is root
if [[ $EUID -ne 0 ]]; then
echo "$(date +%m-%d-%y_%H-%M-%S) - $0 - You must be root, currently you are: $(whoami)" 2>&1
exit 1
fi
case $bootPref in
server)
sed -i 's/GRUB_DEFAULT=./GRUB_DEFAULT=4/g' /etc/default/grub
update-grub
;;
desktop)
sed -i 's/GRUB_DEFAULT=./GRUB_DEFAULT=0/g' /etc/default/grub
update-grub
;;
*)
echo -e "Invalid parameter passed, acceptable parameters:\r
server \r
desktop"
exit 1
esac
cat /etc/default/grub
exit 0
The server partition was installed first and then the desktop partition. Is there some grub magic required to get this working?
Any help would be greatly appreciated, thanks in advance.
Running the script while the desktop install is active causes the next boot to go into the server install as expected. Unfortunately running the same script on the server install does not force the next boot to go into the desktop install. The server install seems to be modifying a different /etc/default/grub file than what is actually being used to boot the machine. Running the script on the server to change the value of GRUB_DEFAULT from 4 (server install) to 0 (desktop install) does not work, when the machine boots next the 4th item is still highlighted in the grub menu and the server install boots again.
#!/bin/bash
bootPref=$1
# Perform argument validation
if [ $# -ne 1 ] ; then
echo -e "Too many parameters passed, acceptable parameters:\r
server \r
desktop"
exit 0
fi
# Confirm user is root
if [[ $EUID -ne 0 ]]; then
echo "$(date +%m-%d-%y_%H-%M-%S) - $0 - You must be root, currently you are: $(whoami)" 2>&1
exit 1
fi
case $bootPref in
server)
sed -i 's/GRUB_DEFAULT=./GRUB_DEFAULT=4/g' /etc/default/grub
update-grub
;;
desktop)
sed -i 's/GRUB_DEFAULT=./GRUB_DEFAULT=0/g' /etc/default/grub
update-grub
;;
*)
echo -e "Invalid parameter passed, acceptable parameters:\r
server \r
desktop"
exit 1
esac
cat /etc/default/grub
exit 0
The server partition was installed first and then the desktop partition. Is there some grub magic required to get this working?
Any help would be greatly appreciated, thanks in advance.