How to add password protection to GRUB2
These instructions are tested with Ubuntu desktop 12.04, but will probably be useful in other Linux distros with GRUB2 as well.
The goal is to block everything except booting the default system. In paricular, it should not be possible for anyone to boot into recovery mode, since that will bypass normal login and give root access directly.
- Run
grub-mkpasswd-pbkdf2from a terminal and enter the desired password, copy the output. - Edit
/etc/grub.d/40_customand add this to the end:
set superusers="root"
password_pbkdf2 root output from grub-mkpasswd-pbkdf2 goes here
password bogus bogus
- Make
/etc/grub.d/40_customnon-readable for users:
chmod o-r /etc/grub.d/40_custom - Edit
/etc/grub.d/10_linuxaccording to this diff:
90c90,94
< printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
---
> if ${recovery} || ${in_submenu}; then
> printf "menuentry '${title}' ${CLASS} --users '' {\n" "${os}" "${version}"
> else
> printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
> fi
258c262
< echo "submenu \"Previous Linux versions\" {"
---
> echo "submenu \"Previous Linux versions\" --users '' {"
- Edit
/etc/grub.d/20_memtest86+according to this diff:
27c27
< menuentry "Memory test (memtest86+)" {
---
> menuentry "Memory test (memtest86+)" --users "" {
33c33
< menuentry "Memory test (memtest86+, serial console 115200)" {
---
> menuentry "Memory test (memtest86+, serial console 115200)" --users "" {
46c46
< #menuentry "Memory test (memtest86+, experimental multiboot)" {
---
> #menuentry "Memory test (memtest86+, experimental multiboot)" --users "" {
52c52
< #menuentry "Memory test (memtest86+, serial console 115200, experimental multiboot)" {
---
> #menuentry "Memory test (memtest86+, serial console 115200, experimental multiboot)" --users "" {
- Run
update-grub
(I am not sure if it is possible to abuse memtest86+, but better safe than sorry.)