Logo address

9front on QEMU

用語 (Terminologie)

QEMU host
QEMU が動いているホストコンピュータ
QEMU guest
QEMU によって動いている仮想コンピュータ

Environmment

Hardware

MB: GA-H61M-USB3H (2 cores, vt-x support)
CPU: Intel Pentium G860
The spec is

Software

Ubuntu on Linux 5.4.0-89-generic
QEMU version: 4.2.1

9front: 9front-8593.acc504....amd64.iso (2021 release) 520MB

Network

以下で maia は QEMU host 名である。この OS は上に述べた Ubuntu である。また 「maia$」は maia による command prompt である。

maia は家庭内のネットワーク環境で動いている。その IP address は 192.168.0.3 である。

Installation

Preparation

maia$ qemu-img create -f qcow2 9front.img 20G
maia$ ls -l 9front.img
-rw-r--r-- 1 arisawa arisawa     196928 12月 27 11:56 9front.img
maia$
これで最大 20GB の仮想 HD が実現できる。(it will be enough for 9front)
after installation of 9front:
maia$ ls -l 9front.img
-rw-r--r-- 1 arisawa arisawa 1027145728 12月 27 14:54 9front.img
maia$

Installation

let
qemu=qemu-system-x86_64
then exec
$qemu -cdrom 9front.iso 9front.img
to install 9front.iso to 9front.img.

The installation process is different from OS to OS.
In case 9front, installation starts from a commend:

insta/start
質問には、基本的には「はいはい」と答えていけばよい。
disk partition に関する質問があるが、質問と共に示されるヒントのとおり書き込み "w" を打ち込み、終了 "q" で終わればよい。 以下の質問には、自分で答えを選択しなくてはならない。例えば次のようにする:
これで 9front の標準ファイルシステムである cwfs が構成された。(正確には cwfs64x)

実行

いろいろな実行方法があるが、ここで紹介するのは user モードでの実行である。QEMU を簡単に使えるのは、このモードである。ここでは user モードの特性を徹底的に調べる。
user モードの中でも多くのオプションがある。まずはオプションなしで実行してみる:
$qemu 9front.img	#1
コメントの "#1" は後で引用するために載せている。

実行すると次の message が表示される:

bootargs is (tcp, il, local!device) [local!/dev/sdC0/fscache]
まずは localdevice を試してみる。

ユーザー名を問われるが、最初は glenda しか許されない。他の名前にしたければ cwfs にユーザー登録しなければいけない。(方法は後で述べる)

localdevice で起動した場合、安全に終了するためには

fshalt
または(リブートする場合)
fshalt -r
を実行する必要がある。

guest OS の 9front は terminal としても cpu server としても起動できる。どちらで起動されているかは

term% echo $service
terminal
term%
で判る。

QEMU guest は何らかのネットワーク環境にあることが想定されている。
user モードで実行された場合には、default では gust network 環境は

GW: 10.0.2.2		(gate way)
DNS: 10.0.2.3		(DNS server)
guest: 10.0.2.15	(QEMU guest)
となっている。このことは 9front の /net/ndb 見れば判る。
guest は GW によって保護されている。この様子は home network の中で動くコンピュータと home GW の関係に似ている。すなわち home GW の外側は Internet の世界であり、外から中へのアクセスは(原則として)禁止されている。中から外へのアクセスは自由に行えるが、その際にはアクセスされた側が受け取る IP packet の source address は home GW の外側に付された IP address となる。その際、中側と外側の1対1通信が可能になるように、内側の port 番号も適切な変換を受ける。(この様子については後にまた触れる)

NIC

QEMU は多様なデバイスをエミュレートできる。デバイスの一覧は

$qemu -device help
で見ることができる。NIC に関しては
name "e1000", bus PCI, alias "e1000-82540em", desc "Intel Gigabit Ethernet"
name "e1000-82544gc", bus PCI, desc "Intel Gigabit Ethernet"
name "e1000-82545em", bus PCI, desc "Intel Gigabit Ethernet"
name "e1000e", bus PCI, desc "Intel 82574L GbE Controller"
name "i82550", bus PCI, desc "Intel i82550 Ethernet"
name "i82551", bus PCI, desc "Intel i82551 Ethernet"
name "i82557a", bus PCI, desc "Intel i82557A Ethernet"
name "i82557b", bus PCI, desc "Intel i82557B Ethernet"
name "i82557c", bus PCI, desc "Intel i82557C Ethernet"
name "i82558a", bus PCI, desc "Intel i82558A Ethernet"
name "i82558b", bus PCI, desc "Intel i82558B Ethernet"
name "i82559a", bus PCI, desc "Intel i82559A Ethernet"
name "i82559b", bus PCI, desc "Intel i82559B Ethernet"
name "i82559c", bus PCI, desc "Intel i82559C Ethernet"
name "i82559er", bus PCI, desc "Intel i82559ER Ethernet"
name "i82562", bus PCI, desc "Intel i82562 Ethernet"
name "i82801", bus PCI, desc "Intel i82801 Ethernet"
name "ne2k_isa", bus ISA
name "ne2k_pci", bus PCI
name "pcnet", bus PCI
name "pvrdma", bus PCI, desc "RDMA Device"
name "rocker", bus PCI, desc "Rocker Switch"
name "rtl8139", bus PCI
name "tulip", bus PCI
name "usb-bt-dongle", bus usb-bus
name "usb-net", bus usb-bus
name "virtio-net-device", bus virtio-bus
name "virtio-net-pci", bus PCI, alias "virtio-net"
name "virtio-net-pci-non-transitional", bus PCI
name "virtio-net-pci-transitional", bus PCI
name "vmxnet3", bus PCI, desc "VMWare Paravirtualized Ethernet v3"
が表示される。

9front に与えられた NIC は /dev/kmesg を見ると i82543 となっている。つまり "e1000" が default なのだろう。

QEMU guest が virtio をサポートしていれば、virtio の方が効率が良いと言われる。9front は virtio をサポートしている。

$qemu 9front.img -nic model=virtio	#2

KVM

QEMU host が VT-x をサポートしていれば、QEMU は KVM モードで実行できる。
maia は該当するので

$qemu 9front.img -enable-kvm	#3
で実行すればよい。俄然速くなる。

シームレスなマウス

実行形式 #1 のままでは、マウスカーソルが QEMU guest に張り付いて使い勝手が悪い。この問題を解決するためには
$qemu 9front.img -usb -device usb-tablet	#4
を実行すればよい。使い勝手が俄然改善される。

結論

実行形式 #2,3,4 を合わせて

$qemu 9front.img -nic model=virtio -enable-kvm -usb -device usb-tablet	#5
を得る。

9front の調整

VESA

9front の default の vga size は遠慮気味に設定されている。QEMU の VESA は
640x400x8      	m8        	packed
640x480x8      	m8        	packed
800x600x8      	m8        	packed
1024x768x8     	m8        	packed
1280x1024x8    	m8        	packed
320x200x15     	r5g5b5    	direct
320x200x16     	r5g6b5    	direct
320x200x24     	r8g8b8    	direct
640x480x15     	r5g5b5    	direct
640x480x16     	r5g6b5    	direct
640x480x24     	r8g8b8    	direct
800x600x15     	r5g5b5    	direct
800x600x16     	r5g6b5    	direct
800x600x24     	r8g8b8    	direct
1024x768x15    	r5g5b5    	direct
1024x768x16    	r5g6b5    	direct
1024x768x24    	r8g8b8    	direct
1280x1024x15   	r5g5b5    	direct
1280x1024x16   	r5g6b5    	direct
1280x1024x24   	r8g8b8    	direct
1600x1200x8    	m8        	packed
1600x1200x15   	r5g5b5    	direct
1600x1200x16   	r5g6b5    	direct
1600x1200x24   	r8g8b8    	direct
320x200x32     	x8r8g8b8  	direct
640x400x32     	x8r8g8b8  	direct
640x480x32     	x8r8g8b8  	direct
800x600x32     	x8r8g8b8  	direct
1024x768x32    	x8r8g8b8  	direct
1280x1024x32   	x8r8g8b8  	direct
320x200x8      	m8        	packed
1600x1200x32   	x8r8g8b8  	direct
1152x864x8     	m8        	packed
1152x864x15    	r5g5b5    	direct
1152x864x16    	r5g6b5    	direct
1152x864x24    	r8g8b8    	direct
1152x864x32    	x8r8g8b8  	direct
1280x768x16    	r5g6b5    	direct
1280x768x24    	r8g8b8    	direct
1280x768x32    	x8r8g8b8  	direct
1280x800x16    	r5g6b5    	direct
1280x800x24    	r8g8b8    	direct
1280x800x32    	x8r8g8b8  	direct
1280x960x16    	r5g6b5    	direct
1280x960x24    	r8g8b8    	direct
1280x960x32    	x8r8g8b8  	direct
1440x900x16    	r5g6b5    	direct
1440x900x24    	r8g8b8    	direct
1440x900x32    	x8r8g8b8  	direct
1400x1050x16   	r5g6b5    	direct
1400x1050x24   	r8g8b8    	direct
1400x1050x32   	x8r8g8b8  	direct
1680x1050x16   	r5g6b5    	direct
1680x1050x24   	r8g8b8    	direct
1680x1050x32   	x8r8g8b8  	direct
1920x1200x16   	r5g6b5    	direct
1920x1200x24   	r8g8b8    	direct
1920x1200x32   	x8r8g8b8  	direct
2560x1600x16   	r5g6b5    	direct
2560x1600x24   	r8g8b8    	direct
2560x1600x32   	x8r8g8b8  	direct
1280x720x16    	r5g6b5    	direct
1280x720x24    	r8g8b8    	direct
1280x720x32    	x8r8g8b8  	direct
1920x1080x16   	r5g6b5    	direct
1920x1080x24   	r8g8b8    	direct
1920x1080x32   	x8r8g8b8  	direct
1600x900x16    	r5g6b5    	direct
1600x900x24    	r8g8b8    	direct
1600x900x32    	x8r8g8b8  	direct
2560x1440x16   	r5g6b5    	direct
2560x1440x24   	r8g8b8    	direct
2560x1440x32   	x8r8g8b8  	direct
320x200x8      	m8        	packed
をサポートしている。確認には
sysinfo >[2] /dev/null |grep '^vesa mode'
を実行すればよい。

term% 9fs 9fat
term% ls /n/9fat
/n/9fat/9bootfat
/n/9fat/9pc64
/n/9fat/efi
/n/9fat/pbs.bak
/n/9fat/plan9.ini
term% cat /n/9fat/plan9.ini
bootfile=9pc64
bootargs=local!/dev/sdC0/fscache
mouseport=ps2
monitor=vesa
vgasize=1024x768x16

tiltscreen=none
term%
となっているので、この vgasize を好みの値に変更すればよい。

plan9.ini を弄る前に確認したい場合には、次の rc script を glendabin/rc に置いて

#!/bin/rc
rfork e
fn usage{
	echo 'usage: vgasetup'
	echo 'usage: gvasetup [-t] vgasize'
	exit
}

switch($1){
case -t
	shift
	if(~ $#* 0)
		usage
	vgasetup $1; sleep 5; vgasetup $vgasize
	exit
case -*
	usage
}

if(~ $#* 0 || ~ $#vgasize 0){
	@{rfork n; aux/realemu; aux/vga -p}|grep '^vesa mode'|awk '{printf("vgasetup %-15s\t%-10s\t%s\n",$4,$5,$6)}'
	echo 'your vgasize:' $vgasize
	echo 'your monitor:' $monitor
	if(! ~ $monitor ?*)
		echo '### set monitor value'
	echo '/dev/vgactl:'
	cat /dev/vgactl
	exit
}


@{rfork n; aux/realemu; aux/vga -p}|grep -s '^vesa mode .+ '^$1
if(~ $status ?*){
	echo select from
	vgasetup
	exit
}

@{rfork n; aux/realemu; aux/vga -m $monitor -l $1}
vgasetup を実行し、リストアップされたサイズから好みのサイズを選んでもよい。(このプログラムは QEMU でなくても役に立つ)

download vgasetup

外部へのネットアクセス

Confirmation

ネットワークを使う前に、

cat /net/ipselftab
cat /net/iproute
で QEMU guest が見るネットワークを調べておく。
正しく動作しておれば、ここに 10.0.2.010.0.2.15 などのネットワーク情報が表示されているはずである。

このような言い方をするのは、いろいろ弄っている間に、表示されなくなることがあるからである。その場合には外部へのネットアクセスはできない。(原因不明)
その場合

ip/ipconfig -d
を実行してみたらよい。もう一度 QEMU の DHCP サーバーから情報を取り寄せ表示されるようになる。

ipv6 の設定がなくても困ることはないが、どうしても欲しいなら

ip/ipconfig -6 ether /net/ether0
を実行すればよい。

Access to QEMU host

最初に QEMU から最も近い「外部」である QEMU host である maia へのアクセスを調べる。以下では maia は ssh サービスを行っていると仮定する。QEMU の内部ネットワーク 10.0.2.0 に見える 10.0.2.2 は gateway であると共に QEMU host のアドレスでもある。従って(ユーザー名が arisawa の場合には)

ssh arisawa@10.0.2.2
で maia に login できる。

Plan9 から ssh を使う場合には、通常は vt100 エミュレータの下で行う。直接実行した場合には不便な面もあるが便利な面もある。プロンプトが出ないので、最初は戸惑うが

bash -i
を実行してやればよい。

QEMU host の maia のファイルシステムを mount したければ

sshfs arisawa@10.0.2.2:/ /n/maia
/n/maia に mount される。

Access to external host

/etc/qemu-ifdown
/etc/qemu-ifup
/etc/default/qemu-kvm
/etc/systemd/system/multi-user.target.wants/qemu-kvm.service