Windows下安裝VirtualBox+Ubuntu

Windows下安裝VirtualBox+Ubuntu

本篇記錄筆者照著網上的教程在Windows下安裝VirtualBox時所碰到的各種問題。

VirutalBox下載連結

最新版本的VirtualBox下載連結為:Download VirtualBox。
但因為最新的版本(6.1.4版)會有剪貼簿無法共用的問題,所以筆者使用的是5.2版,下載連結為:Download VirtualBox (Old Builds): VirtualBox 5.2。

VirtualBox安裝Ubuntu

在VirtualBox中安裝Ubuntu16.04,筆者主要是按照VirtualBox 5.2安裝Ubuntu 16.04這個教程操作的。途中碰到的各種問題將在下面一一給中解決方式。

安裝Ubuntu系統重啟後卡住

筆者曾經碰過VirtualBox內Ubuntu重啟後卡住的問題,解決方法如安装Ubuntu14.10重启后卡住所說,把插著電腦的USB線拔掉就好了。

插入Guest Additions CD映像

Ubuntu系統安裝完成後首先要做的是插入Guest Additions CD映像,它提供了待會會介紹到的共用資料夾共用剪貼簿等功能。具體操作方式可以參考VirtualBox 5.2安裝Ubuntu 16.04與Windows 10共用資料夾的前七個步驟。

如果上述方法失敗,可以嘗試手動插入,參考Unable to mount the CD/DVD image on the machine Sandbox。

其中第一步是下載VBoxGuestAdditions.iso。而5.2.38版的VBoxGuestAdditions_5.2.38.iso的下載地址為http://download.virtualbox.org/virtualbox/5.2.38/VBoxGuestAdditions_5.2.38.iso。

如果途中碰到Unable to install guest additions: unknown filesystem type 'iso9660'的錯誤,參考Unable to install guest additions: unknown filesystem type ‘iso9660’,使用如下指令:

sudo apt-get install --reinstall linux-image-$(uname -r)

調整VirtualBox內視窗大小

在VirtualBox中,Ubuntu系統裝好之後,可能只佔畫面大小的一半,如果想要讓它能覆蓋整個螢幕,根據請問 如何放大在 Virtualbox 中的 OS 視窗?,這個問題的解決方式就是前一節的插入Guest Additions CD映像

共用資料夾

如果是docker,我們可以選擇用mount的方式來讓docker容器與主機共用資料夾。而在VirtualBox下,則需要參照VirtualBox 5.2安裝Ubuntu 16.04與Windows 10共用資料夾這篇教學來設定,其中的前七個步驟是我們已經做過的插入Guest Additions CD映像

其中要注意的是,在設定共用資料夾時,要選擇自動掛載。假設主機上共用資料夾的名稱為implementation,重啟Ubuntu後我們會在/media下看到sf_implementation這個資料夾,這時我們已經可以在該資料夾中看到主機上的東西了。

但我們通常會想在家目錄,而不是/media下進行操作,所以接下來是在家目錄中新建一個資料夾,用來做為/media/sf_implementation的對應,如下:

mkdir /home/ubt/Documents/implementation

接下來是將我們剛創建的資料夾與/media中的資料夾實際對應起來:

cd /media
sudo mount –t vboxsf implementation /home/ubt/Documents/implementation

在上面這個指令中要注意的是:雖然/media底下的資料夾名稱是sf_implementation,但是在指令中我們應該要用implementation,否則會出現:

/sbin/mount.vboxsf: mounting failed with the error: Protocol error

的錯誤。

如果在輸入上述指令時,出現了關於mount使用方式的訊息,那可能是指令打錯了(少了-t),或是/home/ubt/Documents/implementation這個資料夾根本不存在。

還有一種可能是使用root身份使用如下指令:

mount –t vboxsf implementation /home/ubt/Documents/implementation

這時也會報一樣的錯,筆者試著退出root身份,再下sudo mount –t vboxsf implementation /home/ubt/Documents/implementation的指令後就成功了。

重啟Virtual machine可能會導致mounting設定還原(即/home/ubt/Documents/implementation下沒有東西)。筆者試過Virtualbox shared folder mount from fstab fails; works once bootup is complete、Make the mount folder persistent、How to mount a VirtualBox shared folder at startup?、Error mounting VirtualBox shared folders in an Ubuntu guest等連結裡描述的方法,修改/etc/fstab/etc/modules/etc/rc.local等三個檔案,來嘗試讓這項設定成為永久的,但是沒有一個成功的。

後來筆者的權宜之計是在~/.bashrc中加入上述指令,如此一來,每次系統重啟時都會重新執行mount指令。

共用剪貼簿(從/到主機的複製貼上)

根據Copy paste not working on Virtual box 6.1 running Ubuntu 18.04 on Windows 10 Machine所說,6.1.4版的VirtualBox無此功能,因此筆者改用較舊的5.2.38版。

參考Copy And Paste Between VirtualBox Host And Guest Machines,要做的事很簡單,就是在VirtualBox操作界面中選擇[設定值]-[進階],將[共用剪貼簿]及[拖放]設為雙向即可。

註:VirtualBox裡的複製貼上是Shift+Ctrl+CShift+Ctrl+V

調整硬碟大小

參考增加 VirtualBox 虛擬硬碟大小(使用 GParted 調整分割區),在Windows cmd裡使用如下指令可以將虛擬硬碟大小調整為SIZE_IN_MB

C:\Program Files\Oracle\VirtualBox\VboxManage.exe modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

其中YOUR_HARD_DISK.vdi的位置可以到[設定]-[存放裝置],然後查看右邊[資訊]下的[位置]來找出。

下一步則要先從GNOME Partition Editor下載gparted-live-1.1.0-1-amd64.iso。

開機順序則要照著How To Increase Virtualbox Disk Size For Dynamically Allocated Disks中說的,把光碟(Optical)調到最上面去。

接下來要先決定欲加大的磁碟分區,有/dev/sda1/dev/sda2可選。筆者想要加大的是Ubuntu中/的硬碟大小,我們可以透過df -h查看,發現/是屬於/dev/sda1這個檔案系統。接著從連結中的Step 7開始,把圖中的/dev/sda2改成/dev/sda1即可。

解除安裝

VirtualBox的安裝路徑xxx\Oracle\VirtualBox下並沒有類似Uninstall.exe的檔案,如果想要在Windows下完全將VirtualBox解安裝,可以使用IObit Uninstaller這個軟體,其下載連結為:IObit Uninstaller 9 Free。

參考連結

Download VirtualBox

Download VirtualBox (Old Builds): VirtualBox 5.2

VirtualBox 5.2安裝Ubuntu 16.04

安装Ubuntu14.10重启后卡住

VirtualBox 5.2安裝Ubuntu 16.04與Windows 10共用資料夾

Unable to mount the CD/DVD image on the machine Sandbox

Unable to install guest additions: unknown filesystem type ‘iso9660’

請問 如何放大在 Virtualbox 中的 OS 視窗?

VirtualBox 5.2安裝Ubuntu 16.04與Windows 10共用資料夾

Virtualbox shared folder mount from fstab fails; works once bootup is complete

Make the mount folder persistent

How to mount a VirtualBox shared folder at startup?

Error mounting VirtualBox shared folders in an Ubuntu guest

Copy paste not working on Virtual box 6.1 running Ubuntu 18.04 on Windows 10 Machine

Copy And Paste Between VirtualBox Host And Guest Machines

增加 VirtualBox 虛擬硬碟大小(使用 GParted 調整分割區)

IObit Uninstaller 9 Free

你可能感兴趣的:(Windows)