5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mac に Ubuntu Linux デスクトップ環境を構築する (xhyve編)

Last updated at Posted at 2018-09-27

普段は Mac で仕事をしているものの、Linux Desktop を使わないといけない案件があって、VirtualBox でもと思ってやり始めたものの、High Sierra の「拡張機能がブロックされました」のエラーで先にするめない。

そういや xhyve もあったなとググってたら結構使えるっぽいのでやってみたら、意外といいかんじ。

xhyve のインストール

Homebrew なら一行でOK。

$ brew install xhyve

Ubuntu をインストール

ほぼ https://gist.github.com/mowings/f7e348262d61eebf7b83754d3e028f6c の通り。
18.04 は kernel panic でインストーラが起動しなかったので、16.04 を入れた。

$ curl -O http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso
$ dd if=/dev/zero bs=2k count=1 of=tmp.iso
$ dd if=mini.iso bs=2k skip=1 >> tmp.iso
$ hdiutil attach tmp.iso
$ cp /Volumes/CDROM/linux .
$ cp /Volumes/CDROM/initrd.gz .
$ umount /Volumes/CDROM
$ rm tmp.iso  # kernel をコピーしたら用済み

$ dd if=/dev/zero of=hdd.img bs=1g count=40  # 40GB のディスクイメージ
$ sh ./install.sh  # 下記参照
install.sh
# !/bin/sh

KERNEL="linux"
INITRD="initrd.gz"
CMDLINE="earlyprintk=serial console=ttyS0"

# Guest Config
MEM="-m 1G"
IMG_CD="-s 1,ahci-cd,mini.iso"
IMG_HDD="-s 2,virtio-blk,hdd.img"
NET="-s 3:0,virtio-net,en0"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
LPC_DEV="-l com1,stdio"
ACPI="-A"

# and now run
sudo xhyve $ACPI $MEM $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_H -f kexec,$KERNEL,$INITRD,"$CMDLINE"

Ubuntu のインストーラが起動するので、ふつーにインストールする。ただし kernel ファイルをコピるため、インストーラを終了する前に Go Back を選択して Execute a shell を実行する。

# cd /target
# sbin/ifconfig
# tar c boot | nc -l -p 1234

このまま mac で別の端末を開き、以下を実行する

$ nc <Ubuntu の IP アドレス> 1234 | tar x

これでインストールは完了。

Ubuntu を起動

以下のスクリプトを実行する。

run.sh
# !/bin/sh
KERNEL="$(ls boot/vmlinuz-* | sort -u | tail -1)"
INITRD="$(ls boot/initrd.img-* | sort -u | tail -1)"
CMDLINE="earlyprintk=serial console=ttyS0 acpi=off root=/dev/vda1 ro"

# Guest Config
UUID="c643a961-c20b-11e8-9979-3200139e2000"  # python -c 'import uuid; print(uuid.uuid1())'  等で生成する。IPアドレスを固定できる。
CPU="-c 2"
MEM="-m 4G"
IMG_HDD="-s 2,virtio-blk,hdd.img"
NET="-s 3:0,virtio-net,en0"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
LPC_DEV="-l com1,stdio"
ACPI="-A"

# and now run
sudo xhyve $UUID $ACPI $CPU $MEM $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD -f kexec,$KERNEL,$INITRD,"$CMDLINE"

つらつらとログが流れた後、ログインプロンプトが表示される。めでたい。

Ubuntu 16.04.5 LTS rabbit ttyS0                
                                               
rabbit login:                                  

せっかくなので、18.04 にアップグレードしておく。

$ do-release-upgrade

xrdp のインストール

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install xrdp xfce4 xfce4-goodies
$ sudo apt-get install chromium-browser  # お好みで。

リモートデスクトップ接続

xrdp は特に設定がいらないようで、ubuntuのIPアドレスを指定して、マイクロソフトのリモートデスクトップクライアントから接続できる。

VNC よりも描画が速いし、いい感じ。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?