Linux Mint – Setting Laptop Screen Brightness After Boot with Full Disk Encryption

bootencryptioninitramfslinux-mintluks

my girlfriend bought Lenovo Essential G500 i5-3230 and I installed Linux Mint 16 on it with full disk encryption. It is standard installation with encryption using dmcrypt and LUKS. But there is a problem with screen brightness, it is set to 0 before it even ask for password to encrypted partitions. I partly fixed it by adding:

echo 50 > /sys/class/backlight/acpi_video0/brightness

to /etc/rc.local but it fixes brightness after typing correct password to mount encrypted partitions. I want to fix brightness before that, so I can see the password input field. /etc/rc.local is loaded after mounting encrypted disk so I think I need to somehow force kernel to change brightness just after it loads itself and before mounting.

Is there a way to tell kernel to adjust brightness just after boot?

Graphic cards on laptop are: AMD® Radeon HD 8570M + Intel HD Graphics 4000

UPDATE

I've tried solution sugested by @derobert. I created initramfs script /etc/initramfs-tools/scripts/init-premount/local-backlight-brightness

#!/bin/sh
PREREQ=""
prereqs()
{
    echo "$PREREQ"
}

case $1 in
    prereqs)
        prereqs
        exit 0
    ;;
esac

. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line

echo 50 > /sys/class/backlight/acpi_video0/brightness

And after this:

$ sudo chmod a+rx /etc/initramfs-tools/scripts/init-premount/local-backlight-brightness
$ sudo update-initramfs -u
$ sudo reboot

But it don't work, screen is almost black when asking for password. I'm not even sure if this script was executed. How can I check if it was executed? Maybe I should add some requirements in PREREQ="" to make it work?

UPDATE 2 FINALLY WORKING

Ok, I decided to read manual for initramfs-tools again to check if everything was good and it looks like I used wrong boilerplate for my script. The correct one is:

#!/bin/sh
PREREQ=""
prereqs()
{
    echo "$PREREQ"
}

case $1 in
prereqs)
    prereqs
    exit 0
    ;;
esac

. /scripts/functions
# Begin real processing below this line

echo 50 > /sys/class/backlight/acpi_video0/brightness

The problem was with . /usr/share/initramfs-tools/hook-functions. This line was used for hook scripts that are not included in intramfs image. It should be . /scripts/functions. After changing it, brightness works like I wanted.

I'm marking @derobert answer as correct because it directed me to correct solution.

Best Answer

You need to add that script to your initramfs. On Debian (I suspect Mint is the same), it appears that the password prompt comes from /usr/share/initramfs-tools/scripts/local-top/cryptroot. That script arranges itself to be called last out of the local-top scripts. There is a parallel set of directories in /etc intended for local customization. So you just need to plop a file that looks something like:

#!/bin/sh
PREREQ=""
prereqs()
{
     echo "$PREREQ"
}

case $1 in
prereqs)
     prereqs
     exit 0
     ;;
esac

echo 50 > /sys/class/backlight/acpi_video0/brightness

into either /etc/initramfs-tools/scripts/local-top or /etc/initramfs-tools/scripts/init-premount. The file name doesn't matter, though I'd pick something like local-backlight-brightness to make sure it doesn't conflict with some package-provided script. (The prereqs boilerplate comes straight from the initramfs-tools manpage.)

Then, run update-initramfs -u.

Related Question