Install VirtualBox Guest Additions for openEuler 20.03 SP1
Tags: linux, virtualbox, openeuler, beginners
Published: 2021-10-27 16:31:33

This article mainly discusses encountered issues and solutions when I installed VirtualBox Guest Additions for OpenEuler 20.03 SP1.

1. After installing openEuler 20.03 SP1, log in to openEuler (I login as root here, if you are a regular user, you may need to use `sudo` when executing commands below), and then click `Device` -> `Insert Guest Additions CD image...` to load the latest version of the Guest Additions CD into the system.

2. Mount the CD:
```bash
mkdir -p /run/media/openeuler/VBoxAdditions
mount /dev/sr0 /run/media/openeuler/VBoxAdditions
cd /run/media/openeuler/VBoxAdditions
```
![](https://img-blog.csdnimg.cn/20210714095112172.png)

3. If you choose to install directly as usual, it may prompt an error for extraction because the system lacks the `tar` extraction program in the case of minimal installation. So install it:
```bash
dnf update
dnf install tar
```
![](https://img-blog.csdnimg.cn/20210714100053588.png)

4. Run the installation:
```bash
./VBoxLinuxAdditions.run
```
![](https://img-blog.csdnimg.cn/20210714100606358.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)

You can see there exists an error. Let's take a look at the details of the error:

```bash
cat /var/log/vboxadd-setup.log
```
![](https://img-blog.csdnimg.cn/20210714100827446.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)

It can be seen that it is a compilation error. According to Linux kernel documentation, the `access_ok` function has been changed from passing three parameters to passing two parameters after the Linux kernel version 5. VBoxAdditions judges whether to use three or two parameters by the Linux version number. However, the kernel version number used by openEuler 20.03 SP1 is 4, but the patches later than the Linux kernel version 5 for this have been applied. As a result, the `access_ok` function only needs two parameters in this case, so we only need to change the VBoxAdditions source code to let it call `access_ok` with two parameters.

5. Modify the source code of VBoxAdditions (note that the corresponding path is changed according to the version number of VBoxAdditions):
```bash
cd /opt/VBoxGuestAdditions-6.1.22/src/vboxguest-6.1.22/vboxguest/r0drv/linux
vi memuserkernel-r0drv-linux.c
```

Use i to edit, and change the following two places `RTLNX_VER_MIN(5,0,0)` to `RTLNX_VER_MIN(4,0,0)`:
![](https://img-blog.csdnimg.cn/2021071410233935.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210714102414400.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)

Then press the `ESC` key, `:wq` save and exit.

There is also a same issue in another file, so continue to execute the command:
```bash
cd ../../../vboxsf
vi regops.c
```
![](https://img-blog.csdnimg.cn/20210714103207764.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)
Then press the `ESC` key, `:wq` save and exit.

6. Finally continue the installation:
```bash
/sbin/rcvboxadd setup
```
![](https://img-blog.csdnimg.cn/2021071410354843.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE4NTcyMDIz,size_16,color_FFFFFF,t_70)

Installation is complete!

Finally, the VirtualBox Guest Addition can be used after restarting the system!