1

Using the excellent answers from this thread I've been able to schedule booting into different OSes at different times of day.

However, I would like to get the community's advice on how to boot into Ubuntu on weekdays and Windows on weekends, without trial-and-erroring myself into a bricked laptop.

My existing /boot/grub/custom.cfg looks like this:

insmod datehook

if [ $MINUTE -lt 10 ]; then PADDING="0"; else PADDING=""; fi
TIME=$HOUR$PADDING$MINUTE

if [ $TIME -ge 0 -a $TIME -lt 559 ]; then
  set default="Windows Boot Manager (on /dev/nvme0n1p2)"
fi

if [ $TIME -ge 1000 -a $TIME -lt 1659 ]; then
  set default="Ubuntu"
fi

if [ $TIME -ge 1700 -a $TIME -lt 2359 ]; then
  set default="Windows Boot Manager (on /dev/nvme0n1p2)"
fi

Even if someone knows about a sandbox mode which will allow me to trial-and-error my way to an answer that'd be great, but I'd also appreciate some best-practice input from the community.

Thank you!

1

If you want to experiment with grub, you can use the grub command line (hit c when you are in grub menu). You should see the grub prompt :

grub>

If you want to be safe for experimenting, I would suggest using a virtual machine (with VirtualBox for example).

Once in grub command line interface, you can enter the commands like you would in your /boot/grub/custom.cfg.

grub> insmod datehook
grub> date

I haven't found the datehook module documentation ; however, the source code of datehook shows that a $WEEKDAY variable is available.

grub> echo $WEEKDAY

So, you can do

grub> if [ $WEEKDAY = "saturday" -o $WEEKDAY = "sunday"  ]; then
 echo "Setting Windows as default"
 set default="Windows Boot Manager (on /dev/nvme0n1p2)"
else
 echo "Setting Ubuntu as default"
 set default="Ubuntu"
fi

Be aware that $WEEKDAY might be localized, so test before using this code.

If you are not using a QWERTY keyboard, follow these instructions to set your keymap in grub : How to change grub command-line (grub shell) keyboard layout?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.