GRUB 2 has outsourced many functions into modules. This makes it possible to load only the required functions and thus smaller core images are possible. You can also use these modules to extend GRUB, e.g. to implement scheduling in GRUB. This makes it possible to start an particular operating system at a certain time.

You get a list of all available modules with

Configuring Scheduling in GRUB

For the scheduling in GRUB you need the module datehook. This allows access to the following variables in GRUB:

  • DAY
  • HOUR
  • MINUTE
  • SECOND
  • MONTH
  • WEEKDAY
  • YEAR

All these values are based on the time and date set in the BIOS (usually the mainboard hardware clock). You have to keep that in mind when setting up the scheduling in GRUB.

With the following command you get a list with all menu items of the GRUB menu:

The first entry has the number 0, the second the number 1 and so on.

Next open the file /boot/grub/grub.cfg and add the following lines relative to the beginning of the file:

At the beginning, an extra zero is inserted for minutes smaller than 10, so that the number of minutes is always two digits. Then we construct a new variable TIME, which has the current time in the format HHMM. These can now be used to implement scheduling in GRUB.

Ubuntu should be started by default, but in the evening Windows 10 takes precedence. It may be necessary to adjust the times, since the time zone UTC is often set up in the BIOS.

Conclusion

The changes above are only valid until the next time update-grub is executed. To keep the changes in GRUB permanently, you should create a template with this code in /etc/grub.d/.

We use this option to better manage our computers at school. Ubuntu is started by default during the day, but during the night we let Linbo boot so that the computers can be updated or provided with a new image, for example.

Categories: HowTo

Stephan

Stephan

I'm a teacher and IT system administrator in an international school. I love open source software and I used it over a decade in my private and work life. My passion is to solve problems with open source software!