[VirtualBox] 在 Kali 裡安裝 VirtualBox Guest Additions 使用共享目錄

[VirtualBox] 在 Kali 裡安裝 VirtualBox Guest Additions 使用共享目錄

通常我用 VirtualBox 裝好一個 VM 後,就會立刻安裝 VirtualBox Guest Additions,

好讓 shared folder (共享目錄)的功能可以正常使用~

不知怎麼搞的,這件事情遇到 Kali Linux 後就常常出問題…

 

在 在 Linux VM 裡安裝 Guest Additions 這篇文章裡,

提到用 Insert Guest Additions CD image 的方式,但執行時可能會出現錯誤,

這時只要將光碟檔案複製出來再執行就行了,但沒想到這招今天也破功~

於是我又想照著 在 Kali Linux 裡安裝 VirtualBox Guest Additions 這篇寫的,

直接用 apt-get 安裝 virtualbox-guest-x11 這個套件,

裝是可以裝,但問題是最新版的 VirtualBox 似乎認不得這個 repository 裡的 Guest Additions,

而論壇上似乎也嗅到了 Oracle 並不支援 APT repository 上的 Guest Additions 的訊息…

 

最後決定還是使用 VirtualBox 直接提供的 Insert Guest Additions CD image 的方式,

再將遇到的問題一步步的解決,順便記錄一下~

 

1. 執行 VBoxLinuxAdditions.run

先照著 在 Linux VM 裡安裝 Guest Additions 這篇文章的方式,插入光碟執行,

照慣例會失敗,接著將光碟檔案複製出來,執行 VBoxLinuxAdditions.run,

cd ~
cp -R /media/cdrom0 ./
cd cdrom0
./VBoxLinuxAdditions.run

 

如果也像我一樣失敗的話,看一下 /var/log/vboxadd-install.log 的內容:

Uninstalling modules from DKMS
Attempting to install using DKMS
Creating symlink /var/lib/dkms/vboxguest/5.0.20/source ->
/usr/src/vboxguest-5.0.20
DKMS: add completed.
Error! echo
Your kernel headers for kernel 4.3.0-kali1-686-pae cannot be found at
/lib/modules/4.3.0-kali1-686-pae/build or /lib/modules/4.3.0-kali1-686-pae/source.
Failed to install using DKMS, attempting to install without
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

 

看來是 kernel header 檔案找不到,導致 VirtualBox 無法編譯 kernel module…

接下來得先解決這個問題才行~

 

2. 將系統升級到最新狀態

因為 APT repository 上放的通常是最新的 kernel header (舊版的可能要找找看,不過我懶得找了),

因此需要先將 Kali Linux 升到最新版 (跟 APT repository 上的一樣),

這樣就可以從 APT repository 拿到最新且與系統版本相符合的 kernel header 了~

 

執行下面的指令,用 APT 將 Kali Linux 升級到最新狀態並重開機:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt autoremove
sudo reboot

 

重開機之後,用 uname 看一下現在的版本,

已經從 4.3.0-kali1-686-pae 變成 4.5.0-kali1-686-pae 了:

testuser@localhost:~/cdrom0$ uname -a
Linux localhost 4.5.0-kali1-686-pae #1 SMP Debian 4.5.3-2kali1 (2016-05-09) i686 GNU/Linux

 

3. 再次執行 VBoxLinuxAdditions.run

再執行一次 VBoxLinuxAdditions.run,這次會花比較久時間,

因為它有在編譯 kernel module (可以看 /var/log/vboxadd-install.log):

testuser@localhost:~/cdrom0$ sudo ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.20 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 5.0.20 of VirtualBox Guest Additions...
Removing existing VirtualBox non-DKMS kernel modules ...done.
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
Building the main Guest Additions module ...done.
Building the shared folder support module ...done.
Building the graphics driver module ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

 

這次沒有錯誤,可以重開機讓 VirtualBox Guest Additions 生效~

 

4. 設定 VirtualBox VM 的 share folder

到 Kali Linux VM 的 Machine > Settings > Shared Folders,

按下新增 + 鈕,來新增一個共享目錄:

Screen Shot 2016-06-05 at 10.35.54 PM

 

設定好的畫面:

Screen Shot 2016-06-05 at 10.38.14 PM  

 

這時再將 Kali Linux 重開機,應該可以看到桌面上跑出一個 sf_MacHome 的磁碟,

那就是 VirtualBox 的共享目錄囉,用 mount 也可以看的到:

testuser@localhost:~$ mount
MacHome on /media/sf_MacHome type vboxsf (rw,nodev,relatime)

 

要注意的是這個共享目錄只有 root 可以存取,

像我用一般使用者跑 Kali Linux 的話,就得用 sudo 才能看到這共享目錄裡的東西了~

 

參考資料:How to install Linux Kernel Headers on Kali Linux 2.0 (Kali Sana)

 

(本頁面已被瀏覽過 1,126 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料