用意しておくもの
NetBSD/RPiのイメージを入手
イメージの編集
デバイス | 用途 | ホスト | ゲスト(NetBSD) | RPi(NetBSD) |
---|---|---|---|---|
SDカード | root | /dev/mmcblk0 | /dev/ld1 | /dev/ld0 |
USBメモリ | union | /dev/sdb | /dev/ld2 | /dev/sd0 |
miku@hachune% gzip -cd rpi.img.gz | sudo dd of=/dev/mmcblk0 bs=1M miku@hachune% sudo qemu-system-x86_64 -enable-kvm -m 512 \ > -drive file=/dev/mmcblk0,if=virtio \ > -drive file=/dev/sdc,if=virtio \ > -serial pty -nographicまずはRasberry Pi用イメージ上のルートファイルシステムとなるファイルシ ステムを/mnt以下にマウントする。その中にunionfsの上のレイヤーとなるUSB メモリのマウントポイント/unionを作成しマウントする。また、/union以下に 各ディレクトリとのunionディレクトリを作成する。
nbsd# mount /dev/ld1a /mnt nbsd# mkdir /mnt/union nbsd# mount /dev/ld2a /mnt/union nbsd# mkdir /mnt/union/usr /mnt/union/var \ > /mnt/union/etc /mnt/union/root /mnt/union/home/mnt/etc/rc.confを編集する。今回ネットワークはdhcpcd任せとするが、もち ろん静的設定を行っても良い。また、swap領域をSDカード上に作成しては書き 込み回数を抑える事ができないためsavecoreと合わせて無効にしておく。
更に、mountcritlocalの時点で/varが書き込み可能な状態でマウントされるよ う、critical_filesystems_localを設定しておく。(これを行なっていないと、 /varに書き込めずsyslog等を正しく実行できない)
if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf fi rc_configured=YES hostname=negi.k.hachune.org sshd=YES dhcpcd=YES wscons=YES no_swap=YES savecore=NO critical_filesystems_local="/union /etc /var"/etc/fstabを編集する。ここでは、swap領域のコメントアウトと/tmpのtmpfs の追加、unionfsの設定を行なう。
/dev/ld0a / ffs rw,log,noatime 1 1 # /dev/ld0b none swap sw 0 0 /dev/ld0e /boot msdos rw 1 1 kernfs /kern kernfs rw ptyfs /dev/pts ptyfs rw procfs /proc procfs rw tmpfs /tmp tmpfs rw,-m=1777,-s=67608576 /dev/sd0e /union ffs rw,log,noatime 1 1 /union/usr /usr union rw /union/var /var union rw /union/etc /etc union rw /union/root /root union rw /union/home /home union rw最後に、ssh経由でログインできるようホスト側のパスワードファイル等をコ ピーし、ホームディレクトリを作成しておく。
nbsd# cp /etc/group /etc/passwd /etc/master.passwd /mnt/etc nbsd# mkdir /mnt/home
カーネルのrebuild
通常のRPIカーネルと今回作成するNEGIPIカーネルの設定のdiffは以下の通り。
miku@hatsune% diff sys/arch/evbarm/conf/{RPI,NEGIPI} 43c43 < #file-system UNION # union file system --- > file-system UNION # union file system 252c252 < #pseudo-device carp # Common Address Redundancy Protocol --- > pseudo-device carp # Common Address Redundancy Protocol 256,257c256,257 < #pseudo-device ppp # Point-to-Point Protocol < #pseudo-device pppoe # PPP over Ethernet (RFC 2516) --- > pseudo-device ppp # Point-to-Point Protocol > pseudo-device pppoe # PPP over Ethernet (RFC 2516) 262,263c262,263 < #pseudo-device tap # virtual Ethernet < #pseudo-device tun # network tunneling over tty --- > pseudo-device tap # virtual Ethernet > pseudo-device tun # network tunneling over tty後はいつも通りbuild.sh。(クロスコンパイルがLinux上でも簡単にできるのは 非常にうれしい)
miku@hatsune% ./build.sh -O ../objarm -m evbarm -N0 -j9 -U tools kernel=NEGIPI ... ===> Kernels built from NEGIPI: /home/miku/netbsd/src/../objarm/sys/arch/evbarm/compile/NEGIPI/netbsd ===> build.sh ended: Sat Mar 23 04:28:47 JST 2013 ===> Summary of results: build.sh command: ./build.sh -O ../objarm -m evbarm -N0 -j5 -U kernel=NEGIPI build.sh started: Sat Mar 23 04:27:45 JST 2013 NetBSD version: 6.99.17 MACHINE: evbarm MACHINE_ARCH: arm Build platform: Linux 3.8.4-1-ARCH-amd64 x86_64 HOST_SH: /bin/sh MAKECONF file: /etc/mk.conf (File not found) TOOLDIR path: /home/miku/netbsd/src/../objarm/tooldir.Linux-3.8.4-1-ARCH-amd64-x86_64 DESTDIR path: /home/miku/netbsd/src/../objarm/destdir.evbarm RELEASEDIR path: /home/miku/netbsd/src/../objarm/releasedir Updated makewrapper: /home/miku/netbsd/src/../objarm/tooldir.Linux-3.8.4-1-ARCH-amd64-x86_64/bin/nbmake-evbarm Building kernel without building new tools Building kernel: NEGIPI Build directory: /home/miku/netbsd/src/../objarm/sys/arch/evbarm/compile/NEGIPI Kernels built from NEGIPI: /home/miku/netbsd/src/../objarm/sys/arch/evbarm/compile/NEGIPI/netbsd build.sh ended: Sat Mar 23 04:28:47 JST 2013 ===> . miku@hatsune% ls -l ../objarm/sys/arch/evbarm/compile/NEGIPI/netbsd.bin -rwxr-xr-x 1 miku miku 4637568 3月 23 04:28 ../objarm/sys/arch/evbarm/compile/NEGIPI/netbsd.bin完成したカーネル(netbsdではなくnetbsd.bin)をSDカードのFAT領域に kernel.imgとしてコピーしておく。
起動
ハマりどころ
- disklabelの扱いがamd64とevbarmで若干異なる
- postfixが起動できない(unionfsでfcntlがコケる?, 未解決)
postfix/master[1087]: fatal: open lock file /var/db/postfix/master.lock: cannot create file exclusively: Permission denied
negi# touch /var/db/postfix/master.lock negi# chown postfix:postfix /var/db/postfix/master.lock
postfix/postfix-script: warning: not owned by postfix: /var/db/postfix
negi# chown postfix:postfix /var/db/postfix
postfix/master[1678]: fatal: fcntl: set non-blocking flag on: Operation not supported
dmesg
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 6.99.17 (NEGIPI) #2: Sat Mar 23 04:28:45 JST 2013 miku@hatsune.k.hachune.org:/home/miku/netbsd/objarm/sys/arch/evbarm/compile/NEGIPI total memory = 192 MB avail memory = 183 MB timecounter: Timecounters tick every 10.000 msec cprng kernel: WARNING insufficient entropy at creation. mainbus0 (root) cpu0 at mainbus0 core 0: 700 MHz ARM1176JZ-S r0p7 (ARM11J V6ZK core) cpu0: DC enabled IC enabled WB enabled LABT cpu0: isar: [0]=0x140011 [1]=0x12002111 [2]=0x11231121 [3]=0x1102131, [4]=0x1141, [5]=0 cpu0: mmfr: [0]=0x1130003 [1]=0x10030302 [2]=0x1222100 [3]=0 cpu0: pfr: [0]=0x111 [1]=0x11 cpu0: 16KB/32B 4-way L1 Instruction cache cpu0: 16KB/32B 4-way write-back-locking-C L1 Data cache vfp0 at cpu0: VFP11 obio0 at mainbus0 bcmicu0 at obio0 bcmmbox0 at obio0: VC mailbox vcmbox0 at bcmmbox0 bcmtmr0 at obio0 intr 3: VC System Timer bcmpm0 at obio0: Power management, Reset and Watchdog controller bcmrng0 at obio0: RNG plcom0 at obio0 intr 57 plcom0: txfifo disabled plcom0: console genfb0 at obio0no data for est. mode 640x480x67 : switching to framebuffer console genfb0: framebuffer at 0xc006000, size 1920x1200, depth 32, stride 7680 wsdisplay0 at genfb0 kbdmux 1: console (default, vt100 emulation) wsmux1: connecting to wsdisplay0 wsdisplay0: screen 1-3 added (default, vt100 emulation) sdhc0 at obio0 intr 62: SDHC controller sdhc0: interrupting on intr 62 sdhc0: SD Host Specification 3.0, rev.153 sdmmc0 at sdhc0 slot 0 dotg0 at obio0 intr 9: USB controller bcmspi0 at obio0 intr 54: SPI spi0 at bcmspi0: SPI bus bsciic0 at obio0 intr 53: BSC0 iic0 at bsciic0: I2C bus bsciic1 at obio0 intr 53: BSC1 iic1 at bsciic1: I2C bus usb0 at dotg0: USB revision 2.0 timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0 timecounter: Timecounter "bcmtmr0" frequency 1000000 Hz quality 100 WARNING: module error: vfs load failed for `usbverbose', error 45 uhub0 at usb0WARNING: module error: vfs load failed for `usbverbose', error 45 : vendor 0x0000 DWC OTG root hub, class 9/0, rev 2.00/1.00, addr 1 uhub0: 1 port with 1 removable, self powered ld0 at sdmmc0: <0x02:0x544d:SD04G:0x38:0xb0f6cf37:0x088> ld0: 3780 MB, 1920 cyl, 64 head, 63 sec, 512 bytes/sect x 7741440 sectors ld0: 4-bit width, bus clock 50.000 MHz WARNING: module error: vfs load failed for `usbverbose', error 45 WARNING: module error: vfs load failed for `usbverbose', error 45 uhub1 at uhub0 port 1WARNING: module error: vfs load failed for `usbverbose', error 45 WARNING: module error: vfs load failed for `usbverbose', error 45 : vendor 0x0424 product 0x9512, class 9/0, rev 2.00/2.00, addr 2 uhub1: multiple transaction translators uhub1: 3 ports with 2 removable, self powered WARNING: module error: vfs load failed for `usbverbose', error 45 WARNING: module error: vfs load failed for `usbverbose', error 45 usmsc0 at uhub1 port 1 WARNING: module error: vfs load failed for `usbverbose', error 45 WARNING: module error: vfs load failed for `usbverbose', error 45 usmsc0: vendor 0x0424 product 0xec00, rev 2.00/2.00, addr 3 usmsc0: Ethernet address b8:27:eb:a1:40:7b ukphy0 at usmsc0 phy 1WARNING: module error: vfs load failed for `miiverbose', error 45 : OUI 0x00800f, model 0x000c, rev. 3 ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto WARNING: module error: vfs load failed for `usbverbose', error 45 uhidev0 at uhub1 port 2 configuration 1 interface 0 WARNING: module error: vfs load failed for `usbverbose', error 45 uhidev0: vendor 0x04d9 USB Keyboard, rev 1.10/3.90, addr 4, iclass 3/1 ukbd0 at uhidev0: 8 modifier keys, 6 key codes wskbd0 at ukbd0: console keyboard, using wsdisplay0 uhidev1 at uhub1 port 2 configuration 1 interface 1 WARNING: module error: vfs load failed for `usbverbose', error 45 uhidev1: vendor 0x04d9 USB Keyboard, rev 1.10/3.90, addr 4, iclass 3/1 uhidev1: 2 report ids uhid0 at uhidev1 reportid 1: input=6, output=0, feature=0 uhid1 at uhidev1 reportid 2: input=1, output=0, feature=0 umass0 at uhub1 port 3 configuration 1 interface 0 umass0: JetFlash Mass Storage Device, rev 2.00/1.00, addr 5 umass0: using SCSI over Bulk-Only scsibus0 at umass0: 2 targets, 1 lun per target sd0 at scsibus0 target 0 lun 0: <JetFlash, Transcend 4GB, 8.07> disk removable sd0: fabricating a geometry sd0: 3830 MB, 3830 cyl, 64 head, 32 sec, 512 bytes/sect x 7843840 sectors boot device: ld0 root on ld0a dumps on ld0b mountroot: trying nfs... mountroot: trying msdos... mountroot: trying ext2fs... mountroot: trying ffs... root file system type: ffs WARNING: no TOD clock present WARNING: using filesystem time WARNING: CHECK AND RESET THE DATE! warning: no /dev/console init: copying out path `/sbin/init' 11 sd0: fabricating a geometry WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `compat', error 78 WARNING: module error: vfs load failed for `com', error 78 WARNING: module error: vfs load failed for `com', error 78 nd6_dad_timer: called with non-tentative address 2001:c90:8405:1f9c:ba27:ebff:fea1:407b(usmsc0) wsdisplay0: screen 4 added (default, vt100 emulation)