BeagleBone BlackにUbuntu12.04をインストールする
作業の備忘録として記録しています。Raspberry Piを触っていれば、ほぼ同じような手順ですが・・・ (本当はIntel Galileoで遊ぶつもりが発売が年明けに延びたので、こっちをやっつけることに...)
追記 この方法では、SDカードからのブート時に「ボタン」を押す必要がありますが、きんねこさんが押さなくても起動するように、解決してくれました。 armhf.comで配布しているUbuntuイメージはボタン押さないと起動できない件 解決方法は最後に追記しました
BeagleBone Blackの購入
たまたま寄った秋月電子に最新版のRev A6が売ってたので購入¥4,980
UbuntuをSDカードに書き込む
ホストマシンはMacintoshです。まずはBeagleBone Black用のUbuntuイメージをダウンロードします。今回はLTS版のPrecidse 12.04を使います
ダウンロードしたら解凍します。
$ xz -d ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img.xz
解凍して出来たイメージをSDカードに書き込みます。使用するmicroSDは2GB以上のclass10が良いでしょう。ddコマンドで書きこめばいいのですが、Raspberry Piで使用した「RPi-sd card builder」などを使うと楽になります。
Ubuntuから起動
LANケーブルを接続しておき、SDカードを本体に差し込み起動しますが、そのままでは起動しないので、Bootボタンを押しながら電源を入れます。LEDが点滅し始めたら離しても大丈夫のようです(離すまでの時間が曖昧・・・)無事起動していればsshでログインできるはずです。
$ ssh ubuntu@192.168.0.6 <— BeagleBone Blackのアドレス ubuntu@192.168.0.6's password: Welcome to Ubuntu 12.04.3 LTS (GNU/Linux 3.8.13-bone30 armv7l) * Documentation: https://help.ubuntu.com/ The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. ubuntu@ubuntu-armhf:~$
パーティションの拡張
今回は4GBのSDカードを使ったのですが、そのままではブートイメージのサイズ上2GBしか使用できないので、パーティションの拡張を行います。電子工作マスターへの歩みを参考にfdiskで拡張します
ubuntu@ubuntu-armhf:~$ df -h Filesystem Size Used Avail Use% Mounted on rootfs 1.8G 244M 1.5G 15% / /dev/root 1.8G 244M 1.5G 15% / devtmpfs 248M 4.0K 248M 1% /dev none 50M 224K 50M 1% /run none 5.0M 0 5.0M 0% /run/lock none 248M 0 248M 0% /run/shm /dev/mmcblk0p1 1004K 480K 524K 48% /boot/uboot
今はまだサイズが1.8GBになってますので、fdiskで拡張します
ubuntu@ubuntu-armhf:~$ sudo fdisk /dev/mmcblk0 ommand (m for help): p Disk /dev/mmcblk0: 4023 MB, 4023386112 bytes 4 heads, 16 sectors/track, 122784 cylinders, total 7858176 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x80008000 Device Boot Start End Blocks Id System /dev/mmcblk0p1 * 2048 4095 1024 1 FAT12 /dev/mmcblk0p2 4096 3751935 1873920 83 Linux Command (m for help): d Partition number (1-4): 2 Command (m for help): p Disk /dev/mmcblk0: 4023 MB, 4023386112 bytes 4 heads, 16 sectors/track, 122784 cylinders, total 7858176 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x80008000 Device Boot Start End Blocks Id System /dev/mmcblk0p1 * 2048 4095 1024 1 FAT12 Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (1-4, default 2): Using default value 2 First sector (4096-7858175, default 4096): Using default value 4096 Last sector, +sectors or +size{K,M,G} (4096-7858175, default 7858175): Using default value 7858175 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
ここまで来たら、先のBootボタンを押しながらリブートします
ubuntu@ubuntu-armhf:~$ sudo reboot
起動したら再びsshで接続してログイン後、resizeコマンドを叩きます
ubuntu@ubuntu-armhf:~$ sudo fdisk /dev/mmcblk0 Command (m for help): p Disk /dev/mmcblk0: 4023 MB, 4023386112 bytes 4 heads, 16 sectors/track, 122784 cylinders, total 7858176 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x80008000 Device Boot Start End Blocks Id System /dev/mmcblk0p1 * 2048 4095 1024 1 FAT12 /dev/mmcblk0p2 4096 7858175 3927040 83 Linux Command (m for help): q ubuntu@ubuntu-armhf:~$ sudo resize2fs /dev/mmcblk0p2 resize2fs 1.42 (29-Nov-2011) Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/mmcblk0p2 is now 981760 blocks long. ubuntu@ubuntu-armhf:~$ df -h Filesystem Size Used Avail Use% Mounted on rootfs 3.7G 246M 3.3G 7% / /dev/root 3.7G 246M 3.3G 7% / devtmpfs 248M 4.0K 248M 1% /dev none 50M 224K 50M 1% /run none 5.0M 0 5.0M 0% /run/lock none 248M 0 248M 0% /run/shm /dev/mmcblk0p1 1004K 480K 524K 48% /boot/uboot ubuntu@ubuntu-armhf:~$
これで領域が3.7GBに拡張されました
ボタンを押さなくてもSDカードブートするように修正
前述のように、きんねこさんがSDカードブートするように解決してくれました。 調査内容はエントリ上部のリンクを参照してください。ここでは修正部分だけ追記します。
nEnv.txtに2行追加します
# cd /boot/uboot # vim nEnv.txt mmcpart=2 bootfile=zImage <---- 追加 optargs=fixrtc uenvcmd=i2c mw 0x24 1 0x3e; kd=0; if test $mmcdev -eq 1; then mmc dev 0; if mmc rescan; then kd=1; fi; mmc dev 1; fi; setenv mmcroot /dev/mmcblk${kd}p${mmcpart} ro loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} ${bootdir}/dtbs/${fdtfile} loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${bootdir}/${bootfile} mmcboot=echo Booting from mmc ...; run mmcargs; bootz ${kloadaddr} - ${fdtaddr} <---- 追加
これで保存して、一度シャットダウンして再度電源を入れればSDから自動起動するようになります\(^o^)/