ubuntu2404 AMD64 编译和安装virtualbox7.0.18并加载模块
0、官方参考文档:
https://www.virtualbox.org/wiki/Linux%20build%20instructions
1、下载源码:
$ wget https://download.virtualbox.org/virtualbox/7.0.18/VirtualBox-7.0.18.tar.bz2
2、安装库:
$ sudo apt install acpica-tools chrpath doxygen g++-multilib libasound2-dev libcap-dev libcurl4-openssl-dev libdevmapper-dev libidl-dev libopus-dev libpam0g-dev libpulse-dev libqt5opengl5-dev libqt5x11extras5-dev qttools5-dev
$ sudo apt install libsdl1.2-dev libsdl-ttf2.0-dev libssl-dev libvpx-dev libxcursor-dev libxinerama-dev libxml2-dev libxml2-utils libxmu-dev libxrandr-dev make nasm python3-dev python-dev-is-python3 qttools5-dev-tools
$ sudo apt install texlive texlive-fonts-extra texlive-latex-extra unzip xsltproc default-jdk libstdc++5 libxslt1-dev linux-kernel-headers makeself mesa-common-dev subversion yasm zlib1g-dev lib32z1 libc6-dev-i386 lib32gcc-s1 lib32stdc++6 pylint python3-psycopg2 python3-willow
# sudo apt install python-psycopg2 python-pil
$ sudo apt install libpng-dev
$ sudo apt install glslang-tools
$ sudo apt install docbook-xsl
3、创建软连接
先找到系统自带的64位库文件目录,我的在/usr/lib/x86_64-linux-gnu
$ sudo find /usr -iname "libX11.so.6"
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libX11.so.6 /usr/lib32/libX11.so
# sudo ln -s /usr/lib/x86_64-linux-gnu/libXTrap.so.6 /usr/lib32/libXTrap.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXt.so.6 /usr/lib32/libXt.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXtst.so.6 /usr/lib32/libXtst.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXmu.so.6 /usr/lib32/libXmu.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXext.so.6 /usr/lib32/libXext.so
libXTrap.so.6
ubuntu2404里没有找到这个libXTrap.so.6文件,要去下载并安装
http://mirror.nju.edu.cn/debian-archive/debian/pool/main/libx/libxtrap/
libxtrap6_1.0.0-5_amd64.deb
$ wget http://mirror.nju.edu.cn/debian-archive/debian/pool/main/libx/libxtrap/libxtrap6_1.0.0-5_amd64.deb
$ sudo ln -s /usr/lib/libXTrap.so.6 /usr/lib/x86_64-linux-gnu/libXTrap.so.6
$ sudo ln -s /usr/lib/libXTrap.so.6 /usr/lib32/libXTrap.so
4、配置和编译:
$ ./configure --disable-hardening
$ source ./env.sh
# kmk all会报错没去深究,直接放弃release版本,编译debug版本如下
$ kmk BUILD_TYPE=debug
要先kmk编译报错后再kmk BUILD_TYPE=debug
5、安装模块:
$ cd out/linux.amd64/debug/bin/src
$ make
$ sudo make install
$ cd ..
6、运行:
$ ./VirtualBox
这时候虚拟机可能打不开的,因为我之前装了别的版本加载了别的模块
虚拟机启动系统时会提示sudo /sbin/vboxconfig其实是这个脚本postinst-common.sh
$ sudo ./out/linux.amd64/debug/bin/postinst-common.sh
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
提示加载成功,
但是依然启动系统失败,提示vboxdrv驱动没有权限
$ sudo chmod ugo+rw /dev/vboxdrv
再启动
$ ./VirtualBox
7、GG:
最后附上精美图片
8、参考资料:
Linux build instructions – Oracle VM VirtualBox
Ubuntu下源码编译VirtualBox三 —— 源码编译(2)_visualbox源码分析-CSDN博客
PS: 原创不易,点个赞呗!