You are not logged in.

#1 2011-04-27 15:28:57

Marcel-
Member
From: Utrecht, NL
Registered: 2006-12-03
Posts: 266

Automatic recompilation of VirtualBox modules

After getting trapped by not recompiling my VirtualBox modules after a kernel (or VirtualBox) upgrade, I decided to add this to /etc/rc.local:

vboxdrvrunning() {
    lsmod | grep -q "vboxdrv[^_-]"
}

vboxdrvrunning || {
    /etc/rc.d/vboxdrv setup
    modprobe vboxdrv
}

This code checks if vboxdrv was succesfully found and loaded on startup and if not, it recompiles the VirtualBox modules and manually loads vboxdrv. So far, it seems to work correctly (in both cases).

I'd like to know if there are any drawbacks? If not, should I propose a feature request to the VirtualBox package? Or is there an improvement possible?

Offline

#2 2011-04-27 16:02:45

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: Automatic recompilation of VirtualBox modules

This actually makes more sense as a pacman hook. You can of course add this to the Virtualbox wiki, but packages aren't supposed to mess with rc.local anyway so I highly doubt this is going into the Virtualbox package.

Drawbacks:-
1. Sometimes when starting up a computer (esp. laptop) you want it used immediately, compiling vbox modules in the background delays this considerably.
2. Only compiles for the running kernel. I have my own simple script which builds for all installed kernels (based on the same loop as my nvidia-beta-all package).

In general, this being Arch, this module recompiling should be done manually by the user. Automating it just makes the system more opaque.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#3 2011-04-27 16:12:25

Marcel-
Member
From: Utrecht, NL
Registered: 2006-12-03
Posts: 266

Re: Automatic recompilation of VirtualBox modules

Thanks for your feedback. I now see I was not totally clear about the feature request: I meant a request to add a message that one can add these lines of code to /etc/rc.local, not doing this without influence of or knowledge to the user.

1. Agreed, that came to my mind, too.
2. Which script? From the AUR comments I extracted this one:

#!/bin/sh
NEWZEN=`pacman -Ql kernel26-zen | grep /modules.alias.bin | sed 's/kernel26.*\/lib\/modules\/\(.*\)\/modules.alias.bin/\1/g'`
KERN_DIR="/usr/src/linux-${NEWZEN}"
MODULE_DIR="/lib/modules/${NEWZEN}/misc"
sudo -E /etc/rc.d/vboxdrv setup
sudo depmod -a $NEWZEN

but it doesn't work flawlessly anymore, I still get errors about modules not being found (IIRC).

Offline

#4 2011-04-27 16:21:59

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: Automatic recompilation of VirtualBox modules

#! /bin/bash

#VBOX_SRC_PATH=/opt/VirtualBox/src/vboxhost
VBOX_SRC_PATH=/usr/lib/virtualbox/src/

for KERNEL in `file /boot/* | grep 'Linux kernel.*boot executable' | sed 's/.*version \([^ ]\+\).*/\1/'`;
do
  echo "Building vboxdrv for $KERNEL"
  cd $VBOX_SRC_PATH
        sed -i 's/$(shell uname -r)/'$KERNEL'/' ./*/Makefile
  make clean && make && make install
  sed -i 's/'$KERNEL'/$(shell uname -r)/' ./*/Makefile
done

Doesn't do error checking or anything, but works for me. Not sure why you're starting with -Ql kernel26-zen, you're listing every file in one installed kernel. You don't even need that section.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#5 2011-04-27 16:30:16

Bregol
Member
Registered: 2008-08-15
Posts: 175

Re: Automatic recompilation of VirtualBox modules

Marcel- wrote:

2. Which script? From the AUR comments I extracted this one:

Marcel-, that piece of code is actually the start of an addition to ngoonee's pkgbuild.  I keep my zen kernel with the git suffix on it, which caused problems with ngoonee's original loop.  That piece of code you found there looks like what I wrote and passed along to ngoonee, who fixed it up and incorporated as an alternative way for the script to detect what kernels are installed.   For the actual loop itself as implemented in the nvidia-beta-all package, probably better off looking in the pkgbuild.

Ngoonee, thanks for sharing that script.  I hadn't really thought to use that same loop for building virtualbox too.  I will be making use of this.


Nai haryuvalyë melwa rë

Offline

#6 2011-04-27 17:59:30

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Automatic recompilation of VirtualBox modules

You're also making the assumption that vbox users always load vboxdrv at boot time. I only load it when I need it.

Also, "getting trapped"... isn't that a bit over-dramatic? smile

Last edited by tomk (2011-04-27 17:59:58)

Offline

#7 2011-04-28 00:56:20

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: Automatic recompilation of VirtualBox modules

tomk wrote:

Also, "getting trapped"... isn't that a bit over-dramatic? smile

Just imagine, you're all stuck in your Arch system, with NO WAY OF IMMEDIATELY BOOTING VIRTUALBOX!!! How can you get your Microsoft Office fix now?

Oh wait.... just /etc/rc.d/vboxdrv setup and modprobe and you're good to go smile.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#8 2011-04-28 01:00:52

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,676

Re: Automatic recompilation of VirtualBox modules

You don't even need the modprobe

Offline

#9 2011-04-28 03:00:42

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: Automatic recompilation of VirtualBox modules

skunktrader wrote:

You don't even need the modprobe

Ah. Yes you're right of course. Thing is I use my own script (see above) and it doesn't modprobe =p. That's cos I normally run it after updating and before rebooting....


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#10 2011-04-28 05:02:52

sl1pkn07
Member
From: Spanishtán
Registered: 2010-03-30
Posts: 371

Re: Automatic recompilation of VirtualBox modules

install dkms and dkms-virtualbox_bin 4.0.6-1

add "dkms_autoinstaller" on rc.conf Daemons

enjoy

greetings

Offline

#11 2011-04-28 11:42:35

Marcel-
Member
From: Utrecht, NL
Registered: 2006-12-03
Posts: 266

Re: Automatic recompilation of VirtualBox modules

Bregol wrote:

That piece of code you found there looks like what I wrote

Indeed, it's from the comments of zen-kernel package in AUR and I also use the git suffix in my kernel name. The script used to work, but it doesn't anymore, so that's why I was looking for an alternative solution.

tomk wrote:

You're also making the assumption that vbox users always load vboxdrv at boot time.

No, I'm not making that assumption: I thought it might be useful to other users if such code is included in post_install(), so anyone can choose whether they want to incorporate the code or not. It's just the same as the current suggestion made there:

===> To load it automatically, add vboxdrv module
===> to the MODULES array in /etc/rc.conf.
tomk wrote:

Also, "getting trapped"... isn't that a bit over-dramatic? smile

[sarcastic]The only thing I use this computer for is running my favourite web browser, Internet Explorer. Why isn't it available in the AUR, yet?[/sarcastic]
"I got stuck" was perhaps a better description.

skunktrader wrote:

You don't even need the modprobe

It is, as `vboxdrv setup` only reloads modules that are loaded at the moment it starts. vboxdrv isn't loaded at the moment the modules have to be recompiled.

Anyway, ngoonee, thanks for your script, I will try that one.

Offline

Board footer

Powered by FluxBB