# Create Ubuntu Server on macOS with QEMU
###### tags: `qemu` `kvm` `macOS` `Ubuntu` `shared_folder` `sshfs`
## 環境
* Mac OSX mojave 10.14.6
* Homebrew 2.2.11
```shell
$ sysctl hw.physicalcpu hw.logicalcpu
hw.physicalcpu: 2
hw.logicalcpu: 4
```
## 安裝 Ubuntu
按照[此篇](https://hackmd.io/@junwei/Syy7Sc4WU)進行安裝
> 建議使用 Ubuntu 18.04,,之前使用 Ubuntu Server 19.10 時,無法使用 Host 端的 CPU (選項 -cpu host),改採用 18.04 便可成功執行
## 使用 sshfs 進行檔案共享
* 依序下載並安裝以下套件
1. [FUSE for macOS](https://osxfuse.github.io/)
2. [sshfs](https://github.com/osxfuse/sshfs/releases/)
* 在 mac 上建立好新資料夾
```shell
$ mkdir ~/Desktop/qemu_mount
```
* 在 Terminal 輸入以下指令
```shell
$ sshfs username@localhost:/tmp mount -p2222
```
e.g.
```shell
$ sshfs ubuntu@localhost:/home/ubuntu/mount ~/Desktop/qemu_mount -p2222
```
* 接下來便可在 mac 存取 Ubuntu 的檔案
<!--
## 設定網路
* 使用 `ifconfig` 會發現沒有 `eth0` 介面卡,此時需要手動新增
```
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fec0::5054:ff:fe12:3456 prefixlen 64 scopeid 0x40<site>
inet6 fe80::5054:ff:fe12:3456 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:12:34:56 txqueuelen 1000 (Ethernet)
RX packets 306 bytes 49563 (49.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 230 bytes 38151 (38.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 110 bytes 8661 (8.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 110 bytes 8661 (8.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
* 打開
-->
## 參考資料
* [KGDB+ QEMU + SSH](http://jasonblog.github.io/note/qemu/kgdb_+_qemu_+_ssh.html)
* [通过SSHFS在Mac上远程开发Linux服务器程序](https://huataihuang.gitbooks.io/cloud-atlas/develop/mac/sshfs.html)