LoginSignup
7
6

More than 5 years have passed since last update.

CentOS 6 on xhyve

Last updated at Posted at 2015-07-16

Motive

  • Docker も良かったのだが OS X で使う上ではパフォーマンスに懸念がある
    • OS X では Boot2Docker を使う必要があり Linux 上で動かすのと比べると速度が遅いと予想
  • VirtualBox が遅い
    • 最新の 5.0 では準仮想化がサポートされたので速くなったとは思うが試してはいない
  • 純粋に xhyve に興味がある
    • より正確には Hypervisor.framework に興味がある

Prepare

Install xhyve

git clone git@github.com:mist64/xhyve.git
cd xhyve
make

Install

Create disk image

mkdir centos
dd if=/dev/zero of=centos/hdd.img bs=1g count=8

Copy base files

どこかの ftp から以下のファイルをダウンロードしてきて centos ディレクトリにコピーする。

  • CentOS-6.6-x86_64-minimal.iso
    • ftp 上の CentOS/6.6/isos/x86_64/ とかにあると思う
  • initrd.img
    • ftp 上の CentOS/6.6/os/x86_64/isolinux/ とかにあると思う
  • vmlinuz
    • ftp 上の CentOS/6.6/os/x86_64/isolinux/ とかにあると思う

Create install script

centos ディレクトリの一つ上(xhyve)に作成する。

xhyverun-centos-install.sh
#!/bin/sh

KERNEL="centos/vmlinuz"
INITRD="centos/initrd.img"
CMDLINE="earlyprintk=serial console=ttyS0 acpi=off sshd=1 vnc vncpassword=yourpasswd"

MEM="-m 1G"
#SMP="-c 2"
NET="-s 2:0,virtio-net"
IMG_CD="-s 3,ahci-cd,centos/CentOS-6.6-x86_64-minimal.iso"
IMG_HDD="-s 4,virtio-blk,centos/hdd.img"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
LPC_DEV="-l com1,stdio"

build/xhyve $MEM $SMP $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD -f kexec,$KERNEL,$INITRD,"$CMDLINE"

Execute install script

sudo sh ./xhyverun-centos-install.sh

Install

スクリプトを起動していくつかの質問に答えるとこんな画面になる。

Running anaconda 13.21.229, the CentOS system installer - please wait.
03:57:52 Starting VNC...
Disabling protocol version 1. Could not load host key
03:57:53 The VNC server is now running.
03:57:53

You chose to execute vnc with a password.


03:57:53 Please manually connect your vnc client to 192.168.64.4:1 to begin the install.
Press <enter> for a shell
03:57:53 Starting graphical installation.

VNC 接続(Finder で ⌘+kvnc://192.168.64.4:5901)してグラフィカルインストーラでインストールを続行する(アドレスは起動したコンソール画面に表示される)。
また、インストールの最後の再起動ボタンを押してはいけない

Copy kernel files

カーネル関連ファイルを ssh 経由でコピーしてくる。

scp root@192.168.64.4:/mnt/sysimage/boot/vmlinuz-2.6.32-504.el6.x86_64 ./centos/
scp root@192.168.64.4:/mnt/sysimage/boot/initramfs-2.6.32-504.el6.x86_64.img ./centos/
scp root@192.168.64.4:/mnt/sysimage/boot/grub/grub.conf ./centos/

この作業をした後にインストールの最後の再起動ボタンを押す。

Setup

Create boot script

centos ディレクトリの一つ上(xhyve)に作成する。

xhyverun-centos.sh
#!/bin/sh

KERNEL="centos/vmlinuz-2.6.32-504.el6.x86_64"
INITRD="centos/initramfs-2.6.32-504.el6.x86_64.img"
CMDLINE="ro root=/dev/mapper/vg_centos-lv_root rd_NO_LUKS rd_LVM_LV=vg_centos/lv_swap rd_NO_MD  KEYTABLE=us acpi=off console=ttyS0 crashkernel=auto rd_LVM_LV=vg_centos/lv_root LANG=ja_JP.UTF-8 rd_NO_DM"

MEM="-m 1G"
#SMP="-c 2"
NET="-s 2:0,virtio-net"
IMG_HDD="-s 4,virtio-blk,centos/hdd.img"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
LPC_DEV="-l com1,stdio"
UUID="-U 0C1F891D-7C67-4391-8C22-7A31F27EF8A3"

build/xhyve $MEM $SMP $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD $UUID -f kexec,$KERNEL,$INITRD,"$CMDLINE"

UUIDuuidgen で生成したものを使用する。
CMDLINE の内容はコピーしてきた grub.conf を参考にする。

Execute boot script

これでようやく インストールした CentsOS が起動するはず。

sudo sh ./xhyverun-centos.sh

Setup network

そのままだとネットワークに繋がらないので設定の微調整を行う。

# HWaddr を確認
/sbin/ifconfig -a

# スクリプトの名前変更
mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1

# DEVICE と HWADDR を編集
vi /etc/sysconfig/network-scripts/ifcfg-eth1

# ネットワークサービスを再起動
service network restart

Appendix

Add dsik image

数値はバス番号と予想される(ソースコードを確認した)。

IMG_HDD="-s 4,virtio-blk,centos/hdd.img -s 5,virtio-blk,centos/external-hdd.img"

References

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