LoginSignup
1
1

More than 5 years have passed since last update.

NetBSDでBitVisorをビルドしてみる話

Posted at

BitVisorNetBSDでもビルドできる!という話を聞いたので、さっそくNetBSD-7.0-amd64環境でBitVisorのコンパイルとゲストOS起動までを試してみようと思い立ちました。

が、現状ではBitVisorのビルド(途中まで……)のところで留まっているので、ゲストOS起動はまた日を改めて紹介できればと思います。

NetBSDでBitVisorをビルドする

あらかじめ以下のパッケージをインストールします(他にもいくつか必要なものがあるかも)。ビルド環境とBitVisorインストール環境を分けておくと良いかもしれません。

$ sudo -i pkg_add -v mercurial wget pkg-config grub2

BitVisorのWebサイトから取得したソースコードを展開します。

$ tar zxvf bitvisor-1.4.tar.gz
$ cd bitvisor-1.4

NetBSDでもBitVisor のコンパイルの手順でコンパイルが行えますが、一部コンパイルエラーになってしまいます。

$ make
$ make -C boot/loader
$ make -C boot/uefi-loader

boot/loaderは警告がでるもののコンパイルは通っています。

$ make -C boot/loader
gcc -nostdlib -Wl,--oformat,binary -o bootloader bootloader.s
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400000
gcc -nostdlib -Wl,--oformat,binary -o bootloaderusb bootloaderusb.s
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400000
$ echo $?
0

以下のようにbootloaderが生成されています。

$ find . -name bootloader
./boot/loader/bootloader

$ file ./boot/loader/bootloader
./boot/loader/bootloader: DOS/MBR boot sector

uefi-loaderはビルドエラーが発生してしまいます。

$ make -C boot/uefi-loader
amd64-mingw32msvc-cc -shared -nostdlib -e efi_main@8  -mno-red-zone -mno-sse -nostdinc -s -O  -ffre\
estanding -fno-builtin -fno-stack-protector  -fno-strict-aliasing  -I../../edk/Foundation/Efi/Inclu\
de/  -I../../edk/Foundation/Framework/Include/  -I../../edk/Foundation/Include/  -I../../edk/Founda\
tion/Efi/ -o loadvmm.dll loadvmm.c
make: exec(amd64-mingw32msvc-cc) failed (No such file or directory)
*** Error code 1

Stop.
make: stopped in /home/fpig/work/bitvisor/bitvisor-1.4/boot/uefi-loader

real    0m0.006s
user    0m0.001s
sys     0m0.004s

とはいえ、bitvisor.elfが(最初のmake実行で)生成されており、これをgrubから実行することでBitVisorのバイナリで起動するとこまでは試せそうです。

$ find . -name *.elf
./bitvisor.elf
$ file ./bitvisor.elf 
./bitvisor.elf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped

ゲストOSの起動(……の前準備)

とりあえずbitvisor.elfが生成できたので、ゲストOS起動(の前準備)を進めてみます。

grub2のインストール

bitvisor.elfはgrub経由で起動させることができるようです。NetBSDではgrubをインストールするところから始めます(なのでBitVisorのコンパイル用VMとインストール用VMを分けておくと良さそう)。

# pkg_add -v grub2

grub-mkconfigを実行したのち、grub-installでgrubをインストールします。

# grub-mkconfig -o /grub/grub.cfg
Generating grub.cfg ...
Found NetBSD kernel: /netbsd
strings: not found
strings: not found
strings: not found
strings: not found
strings: not found
done

筆者の環境では「-f」オプションを付けてgrub-installを実行しないとgrubがブートローダとしてインストールされませんでした。

# df -h | grep wd
/dev/wd0a          8.7G       250M       8.0G   2% /
# disklabel wd0 | head -n1 | awk '{ print $2 }'
/dev/rwd0d:
# grub-install -f --no-floppy /dev/rwd0d
/usr/pkg/sbin/grub-bios-setup: warning: your core.img is unusually large.  It won't fit in the embe\
dding area.
/usr/pkg/sbin/grub-bios-setup: warning: Embedding is not possible.  GRUB can only be installed in t\
his setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
Installation finished. No error reported.

こんな感じでgrub2でNetBSDが起動するようになります。このNetBSD起動の部分にBitVisorが一段はさまる感じで動作するのかなと考えています。

スクリーンショット 2015-12-13 5.10.42.png

grub2.confでのBitVisorのmenuentty記述や必要なファイルの指定(このあたりまだ良く把握できていない)などがありますが、これはおいおい調べていこうと思います。

まとめ

ものすごい駆け足での記事になってしまいましたが、NetBSDでのBitVisorのコンパイルを試してみました。grub2側での設定方法についても後々まとめられればと思います。

参考URL

1
1
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
1
1