Two weeks ago, I ran into a problem with my Arch Linux installation: I had partitioned my main drive too frugally; I had run out of space on my root partition.
I had been thinking it was time for a bit of a clean-up anyway. I have a tendency to experiment with packages and forget to remove them so I generate clutter like nobody’s business.
I had been reading recently about Gentoo Linux, and liked what I heard. Not a normal distribution, but a “meta-distribution” which aims for absolute optimisation. My approach for optimisation, when the mood takes me, is approaching obsessive. I thought it might well be worth trying out this Gentoo business…
The Journey Begins
So I backed up all the important files that were on my computer (except my private GPG and SSH Keys… oops…) and wiped the drive. I set out on the journey, AMD64 Gentoo Handbook in one hand, Live CD in the other….
…and proceded to completely mess up the installation not once, not twice, but three times. But come build number four, I had a machine that booted, a kernel that could drive my hardware, and had my Xorg setup restored from my dotfiles repository.
On Bees and Switches
On my previous build, I had attempted to get Hybrid Graphics working via Bumblebee and bbswitch. It had never truly worked, no matter which installation guide I followed, and I had given it up for lost.
This time, I would persevere and make it work. I had, after all, installed Gentoo in the (often fruitless) pursuit of optimisation. Already I had a system that needed no initramfs, had a streamlined kernel, and could go from powered off to surfing the web in less than ten seconds. Surely a working GPU switch was the last piece in my puzzle.
The only problem was that there was no evidence of any bumblebee documentation on the Gentoo Wiki. Cue three days of trawling through forums for even a basic guide. All the while, trialing different configurations in an attempt to get the thing working. Nine times out of ten, I would run into catastrophic kernel errors which caused my system to hand without writing any sort of log file.
I found one, eventually, on the wayback machine, having followed a dead link half way down a thread on the Gentoo forums. It seemed reasonable enough, and I followed it.
In response to having had to dig so hard to find this guide, I decided to rehash it and post it to the Gentoo Wiki. Introducing the Gentoo Bumblebee Wiki Page!
Or so I thought.
I had got as far as having bumblebee capably switch the GPU on via bbswitch and load the nvidia drivers when I executed a primusrun command. However, it would not switch them off. Some more forum trawling brought Sven “Yamakuzure” Eden to my attention – he had not only had an extremely similar problem to me but had written a patch to fix it.
The only flaw in this was that the nvidia proprietary drivers had changed shape since the patch had been written, and now the patch was in need of minor updating to support the new ones.
I sent Sven an email, letting him know I was attempting to compile a diffinitive guide to bumblebee on Gentoo, and that his patch would be super useful if it supported both KMS and UVM.
He responded that he would write the fix over the next few days and update his repository. Wonderful news! I was content to wait for the patch and then test it.
Yet Another Bug
It was while I was waiting for Sven to write his patch that I began to experience a new bug all together: as it turned out, my kernel’s ACPI module was not at all happy with my gratuitous switching on and off of the GPU. This manifested itself as random kernel crashes with no logs generated. Cue a complete system rebuild and yet more forum trawling.
After a full day of searching the internet, I found a post about this exact issue on my exact model of computer on the Arch Linux forums. It suggested that the cause was the ACPI module, triggered by any PCI bus call while the GPU was off. The fix was a simple parameter setting in the kernel command line at boot. Finally it was all starting to work!
At this point, I was on the train heading north to visit my parents for the weekend. I had finally worked out all the bugs and was, for the time being, using a system built without KMS and UVM such that the official bumblebee ebuild would work.
Having got a system working and stable, it was time to start ricing and customising. It was two hours before my next rail connection and I was logged into the onboard wifi.
So I went about grabbing themes for GRUB, SDDM. Finding nice backgrounds for my wallpaper and lock screen. I had picked all the nicest fonts and fine-tuned my compositor settings to minimise screen tear (I have been having a war with screen tear on Linux ever since I first installed i3 on Arch).
I was just looking into installing the OCS-URL applet to handle automatically installing things from Gnome-Look when I mis-keyed a command and unpacked the archive right over my /usr/bin directory. It was like lobotomising the system – it could walk, it could talk, but it failed to execute any command that wasn’t an already running process.
Time for another system rebuild….
The Final Build
This time, however, I knew what I was doing. I recovered my configuration files via the live disk before wiping the drive once more. The installation went smoothly, and I built it with Sven’s newly patched Bumblebee from the get-go.
Poor Fearnley had been through hell to get there – compiling even a stage three Gentoo installation ten times in two weeks can’t have been easy – but we had pulled through. I can now switch my GPU on and off at will with no ill affects. It even works with CUDA for blender rendering acceleration.
To reward me for my endeavors, I now have a battery life of over ten hours (GPU off, light CPU usage, reasonable screen brightness)
A big thanks to Sven for his help with this. Please see his blog post about it here.