# Installing Ubuntu 18.04 on VirtualBox > 紀錄在 VirtualBox 安裝 Ubuntu 18.04 的過程,以及設定共享資料夾及開啟複製貼上功能 ## Installing VirtualBox 至 VirtualBox 官網下載安裝檔~ https://www.virtualbox.org/wiki/Downloads 我的桌機是 Ubuntu 24.04,就到 VirtualBox 官網下載相對應的 VirtualBox 安裝檔: https://www.virtualbox.org/wiki/Linux_Downloads ![image](https://hackmd.io/_uploads/HkqoBfViC.png) 下載後點擊它就會自動安裝了 ## Installing Ubuntu 18.04 1. 下載 Ubuntu 18.04 image: 至以下頁面下載 Ubuntu 18.04 的 iso 檔: https://ubuntu.com/download/alternative-downloads#past-releases-and-other-flavours 2. 開啟 VirtualBox,點選 `New` ![image](https://hackmd.io/_uploads/Bk0DLfNjA.png) 3. 設定此虛擬機的名稱,以及放在哪個資料夾 :::danger 此時先不要點選 `ISO Image`! ::: ![image](https://hackmd.io/_uploads/rkPzwMNoR.png) 4. 設定 Base memory 和 Processors Base memory 基本給個 4096 MB,Processors 就看自己電腦有多少 CPU 就選多少 ![image](https://hackmd.io/_uploads/ryTvPf4iA.png) 5. 設定 virtual hard disk 至少給個 50 GB ![image](https://hackmd.io/_uploads/S1nawfEoA.png) 6. 點 `Finish` ![image](https://hackmd.io/_uploads/B1l1dzEiA.png) 7. 點選剛剛設定的虛擬機 `Ubuntu 18.04`,然後點選 `Settings` ![image](https://hackmd.io/_uploads/HyZ-_MNiR.png) 8. 點左側的 `Storage`,然後點 `Empty`,然後再點 `Optical Driver` 旁邊那個光碟的圖案 ![image](https://hackmd.io/_uploads/H1sQuzEsC.png) 9. 點 `Choose/Create a Virtual Optical Disk` ![image](https://hackmd.io/_uploads/ry-tuz4oA.png) 10. 點 `Add` ![image](https://hackmd.io/_uploads/Hk3iuzNo0.png) 11. 選擇剛剛下載的 Ubuntu 18.04 的 `.iso` 檔 ![image](https://hackmd.io/_uploads/H1cxFMViC.png) 12. 點 `Choose` ![image](https://hackmd.io/_uploads/HJ4bYGNjC.png) 13. `OK` ![image](https://hackmd.io/_uploads/S1OzYfNjR.png) 14. 點 `Start` 啟動 Ubuntu 18.04 虛擬機 ![image](https://hackmd.io/_uploads/HkOVFfEoA.png) 15. 點選語言,然後 `Install Ubuntu` ![image](https://hackmd.io/_uploads/HkCOKzEjC.png) 16. 點選鍵盤的 layout,然後 `Continue` ![image](https://hackmd.io/_uploads/rJq5FzEjR.png) 17. `Normal Installation` 和 `Download updates while installing Ubuntu`,然後 `Continue` ![image](https://hackmd.io/_uploads/B1YnYM4iR.png) 18. 因為等下想將 root directory `/` 和 home directory `~/` 放在不同的 partition,所以這裡點 `Something else`,然後 `Continue` ![image](https://hackmd.io/_uploads/Sy8JczNi0.png) 19. 點 `/dev/sda`,然後點 `New Partition Table...` ![image](https://hackmd.io/_uploads/HJEfcGEjC.png) 20. 點 `free space`,然後點那個 `+` 的按鈕 ![image](https://hackmd.io/_uploads/BJhr5M4jR.png) 21. 給 root directory `/` 20480 MB ![image](https://hackmd.io/_uploads/SJbKqMVsA.png) 22. 再點選 `free space`,然後再按那個 `+` 的按鈕 ![image](https://hackmd.io/_uploads/rJHbjMNsC.png) 23. 剩下的 33207 MB 都給 home directory `/home` ![image](https://hackmd.io/_uploads/ByMIofEj0.png) 24. `Install Now` ![image](https://hackmd.io/_uploads/H1-YiG4iA.png) 25. `Continue` ![image](https://hackmd.io/_uploads/H16ssGViC.png) 26. `Continue` ![image](https://hackmd.io/_uploads/S1hTozEoA.png) 27. 設定 username 和密碼,然後 `Continue` ![image](https://hackmd.io/_uploads/HyBm3zVjR.png) 28. 開始安裝~ ![image](https://hackmd.io/_uploads/BkJHhf4oC.png) 28. 安裝完,`Restart Now` ![image](https://hackmd.io/_uploads/S1Kf-QEsR.png) 29. 可以開始用啦~ ![image](https://hackmd.io/_uploads/H18_XXVsC.png) ## Enabling Shared Clipboard 這裡要做的設定是讓 host 跟 VirtualBox 虛擬機共用剪貼簿,這樣在 host 複製的文字,就可以在虛擬機裡面貼上,虛擬機裡面複製的文字,也可以在 host 貼上~ 1. 點選虛擬機的 `Settings`,然後點 `General`,再點 `Advanced`,然後 `Shared Clipboard` 和 `Drag'n'Drop` 欄位都選 `Bidirectional` ![image](https://hackmd.io/_uploads/rJs5imEsA.png) 2. 點 `Storage`,再點 `Controller: SATA`,然後勾選 `Use Host I/O Cache` ![image](https://hackmd.io/_uploads/BkWe37Ei0.png) 3. 點 `Ubuntu 18.04.vdi`,然後勾選 `Solid-state Drive`,然後 `OK` ![image](https://hackmd.io/_uploads/rJNfnmEoA.png) 4. 開啟 Ubuntu 18.04 虛擬機 ![image](https://hackmd.io/_uploads/HkOVFfEoA.png) 5. 開啟 terminal,執行以下指令: ```shell sudo apt update && sudo apt -y install build-essential dkms ``` 6. 點選 VirtualBox 視窗上方的 `Devices` 欄位,再點選 `Insert Guest Additions CD image...` ![image](https://hackmd.io/_uploads/r17naQVoR.png) 7. 點 `Run` ![image](https://hackmd.io/_uploads/rJcgAXEjR.png) 8. 安裝成功會出現以下畫面 ![image](https://hackmd.io/_uploads/SyBHCQNiC.png) 9. 重開機後即可複製貼上啦~ ## Setting Shared Folder between Host and Virtual Machine 設定讓 host 跟虛擬機有共享的資料夾,這樣 host 跟虛擬機只要把東西放在共享資料夾,就能透過共享資料夾傳遞東西至 host 或虛擬機~ 1. 點選 Ubuntu 18.04 virtual machine -> `Settings` -> `Shared Folders` 2. 點選右側的 `Adds new shared folder`(如下圖箭頭所指的按鈕) ![image](https://hackmd.io/_uploads/HJ0xYSpoC.png) 3. 指定在 host 上要用來當作 shared folder 的資料夾的路徑,並記得勾選 `Auto-mount`(ex. 我想設定 host 的 `/home/cpt1020/vbox_shared` 這個資料夾當作共享資料夾,選完 `Folder Path` 之後 `Folder Name` 就會自動顯示該資料夾的名稱,以我這個例子來說就會是`vbox_shared`) ![image](https://hackmd.io/_uploads/B1BrYHai0.png) ![image](https://hackmd.io/_uploads/Hyk5YHTjA.png) 4. 開啟 Ubuntu 18.04 virtual machine 5. 在 virtual machine 中建立一個新的資料夾,等下要讓 host 端共享的資料夾掛載到這個資料夾(ex. 我設定虛擬機的 `/home/cpt1020/shared_folder` 這個資料夾來當作共享資料夾) 6. 開啟 terminal 並輸入以下指令即可共用資料夾: ```shell $ sudo mount -t vboxsf <folder_name> /path/to/vm/shared/folder ``` 以我的例子就是: ```shell $ sudo mount -t vboxsf vbox_shared /home/cpt1020/shared_folder ``` :::info 每次開啟 virtual machine 都需要輸入前述指令將 shared folder 掛載 :::