Fix installation of vbox guest additions.

Credits for this idea go to @myhro who suggested emulating uname.

I cleaned his changes up somewhat and moved the script into a
separate file to make things easier to look at.

I did a test build of wheezy with my changes and the modules were
installed correctly.

root@localhost:/home/vagrant# dkms status
vboxguest, 4.3.20, 3.2.0-4-amd64, x86_64: installed

root@localhost:/home/vagrant# lsmod | egrep ^vbox
vboxsf                 33359  0
vboxvideo              12437  0
vboxguest             162115  1 vboxsf
This commit is contained in:
Jonas Bergler 2014-11-26 17:06:53 +00:00 committed by Tiago Ilieve
parent c95259c9c4
commit 8f03987593
2 changed files with 46 additions and 5 deletions

View file

@ -0,0 +1,16 @@
#!/bin/bash
function uname {
if [[ $1 == '-r' ]]; then
echo "KERNEL_VERSION"
return 0
elif [[ $1 == '-m' ]]; then
echo "KERNEL_ARCH"
return 0
else
$(which uname) $@
fi
}
export -f uname
INSTALL_SCRIPT --nox11

View file

@ -2,6 +2,9 @@ from bootstrapvz.base import Task
from bootstrapvz.common import phases from bootstrapvz.common import phases
from bootstrapvz.common.tasks.packages import InstallPackages from bootstrapvz.common.tasks.packages import InstallPackages
from bootstrapvz.common.exceptions import TaskError from bootstrapvz.common.exceptions import TaskError
import os
assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))
class CheckGuestAdditionsPath(Task): class CheckGuestAdditionsPath(Task):
@ -10,7 +13,6 @@ class CheckGuestAdditionsPath(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
import os.path
guest_additions_path = info.manifest.provider['guest_additions'] guest_additions_path = info.manifest.provider['guest_additions']
if not os.path.exists(guest_additions_path): if not os.path.exists(guest_additions_path):
msg = 'The file {file} does not exist.'.format(file=guest_additions_path) msg = 'The file {file} does not exist.'.format(file=guest_additions_path)
@ -27,12 +29,19 @@ class AddGuestAdditionsPackages(Task):
info.packages.add('bzip2') info.packages.add('bzip2')
info.packages.add('build-essential') info.packages.add('build-essential')
info.packages.add('dkms') info.packages.add('dkms')
kernel_headers_pkg = 'linux-headers-' kernel_headers_pkg = 'linux-headers-'
if info.manifest.system['architecture'] == 'i386': if info.manifest.system['architecture'] == 'i386':
arch = 'i686'
kernel_headers_pkg += '686-pae' kernel_headers_pkg += '686-pae'
else: else:
arch = 'x86_64'
kernel_headers_pkg += 'amd64' kernel_headers_pkg += 'amd64'
info.packages.add(kernel_headers_pkg) info.packages.add(kernel_headers_pkg)
info.kernel = {
'arch': arch,
'headers_pkg': kernel_headers_pkg,
}
class InstallGuestAdditions(Task): class InstallGuestAdditions(Task):
@ -42,19 +51,35 @@ class InstallGuestAdditions(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
import os from bootstrapvz.common.tools import log_call, log_check_call
for line in log_check_call(['chroot', info.root, 'apt-cache', 'show', info.kernel['headers_pkg']]):
key, value = line.split(':')
if key.strip() == 'Depends':
kernel_version = value.strip().split('linux-headers-')[-1]
break
guest_additions_path = info.manifest.provider['guest_additions'] guest_additions_path = info.manifest.provider['guest_additions']
mount_dir = 'mnt/guest_additions' mount_dir = 'mnt/guest_additions'
mount_path = os.path.join(info.root, mount_dir) mount_path = os.path.join(info.root, mount_dir)
os.mkdir(mount_path) os.mkdir(mount_path)
root = info.volume.partition_map.root root = info.volume.partition_map.root
root.add_mount(guest_additions_path, mount_path, ['-o', 'loop']) root.add_mount(guest_additions_path, mount_path, ['-o', 'loop'])
install_script = os.path.join('/', mount_dir, 'VBoxLinuxAdditions.run') install_script = os.path.join('/', mount_dir, 'VBoxLinuxAdditions.run')
install_wrapper_name = 'install_guest_additions.sh'
install_wrapper = open(os.path.join(assets, install_wrapper_name)) \
.read() \
.replace("KERNEL_VERSION", kernel_version) \
.replace("KERNEL_ARCH", info.kernel['arch']) \
.replace("INSTALL_SCRIPT", install_script)
install_wrapper_path = os.path.join(info.root, install_wrapper_name)
with open(install_wrapper_path, 'w') as f:
f.write(install_wrapper + '\n')
# Don't check the return code of the scripts here, because 1 not necessarily means they have failed # Don't check the return code of the scripts here, because 1 not necessarily means they have failed
from bootstrapvz.common.tools import log_call log_call(['chroot', info.root, 'bash', '/' + install_wrapper_name])
log_call(['chroot', info.root, install_script, '--nox11'])
# VBoxService process could be running, as it is not affected by DisableDaemonAutostart # VBoxService process could be running, as it is not affected by DisableDaemonAutostart
log_call(['chroot', info.root, 'service', 'vboxadd-service', 'stop']) log_call(['chroot', info.root, 'service', 'vboxadd-service', 'stop'])
root.remove_mount(mount_path) root.remove_mount(mount_path)
os.rmdir(mount_path) os.rmdir(mount_path)
os.remove(install_wrapper_path)