在BeagleBone Black上使用1-Wire传感器DS18B20-Part2:安装Debian7.8到SD卡上

BeagleBone Black的eMMC上有Debian操作系统,但我之前一直在SD卡上使用Ubuntu。由于需要3.8.13内核,我打算使用Debian 7.8。当我重新制作SD卡时,我遇到了一些困难。

将安装文件安装到SD卡上。

我会将MacBook Pro用作业机。我记得在Windows上写镜像花了很长时间,但在MacBook Pro上只需几分钟就能完成SD卡的写入。

下载

请下载于2015年7月6日刚发布的最新版本。

$ cd ~/Dowonloads
$ wget https://rcn-ee.com/rootfs/bb.org/release/2015-07-06/console/bone-debian-7.8-console-armhf-2015-07-06-2gb.img.xz

我将检查校验和。

$ openssl md5 bone-debian-7.8-console-armhf-2015-07-06-2gb.img.xz
MD5(bone-debian-7.8-console-armhf-2015-07-06-2gb.img.xz)= 6aeef824652637602dbdb1eae431203a

使用unar解压图像。

安装 Unarchiver 的命令行。

$ wget http://theunarchiver.googlecode.com/files/unar1.8.1.zip
$ unzip unar1.8.1.zip -d ~/bin
Archive:  unar1.8.1.zip
  inflating: /Users/mshimizu/bin/lsar
  inflating: /Users/mshimizu/bin/unar

使用unar命令解压缩xz格式的压缩文件。

$ unar bone-debian-7.8-console-armhf-2015-07-06-2gb.img.xz
bone-debian-7.8-console-armhf-2015-07-06-2gb.img.xz: XZ
  bone-debian-7.8-console-armhf-2015-07-06-2gb.img... OK.
Successfully extracted to "./bone-debian-7.8-console-armhf-2015-07-06-2gb.img".

使用dd命令进行写入

插入SD卡至MacBook Pro,并通过df命令确认设备名称。

$ df -h
Filesystem      Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk1     465Gi   86Gi  379Gi    19% 22550671 99288943   19%   /
devfs          186Ki  186Ki    0Bi   100%      645        0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%        0        0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%        0        0  100%   /home
/dev/disk2s1    15Gi  2.3Mi   15Gi     1%        0        0  100%   /Volumes/NO NAME

在进行任务之前,请使用diskutil将SD卡卸载。

$ sudo diskutil unmount /dev/disk2s1
Volume NO NAME on disk2s1 unmounted

使用dd命令将数据写入SD卡的原始磁盘。对于/dev/disk2s1,原始磁盘将变为/dev/rdisk2。

$ sudo dd bs=1m if=bone-debian-7.8-console-armhf-2015-07-06-2gb.img of=/dev/rdisk2
1700+0 records in
1700+0 records out
1782579200 bytes transferred in 147.239980 secs (12106625 bytes/sec)

写入需要几分钟时间。完成后,OSX将显示无法读取磁盘的对话框,但可以忽略它。可以使用diskutil命令弹出SD卡。

$ sudo diskutil eject /dev/rdisk2
Disk /dev/rdisk2 ejected

用串行连接进行确认。

我将通过OSX进行串行连接并确认启动。默认的用户名和密码是debian:temppwd。

BeagleBoard.org Debian Image 2015-07-06

Support/FAQ: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian

default username:password is [debian:temppwd]

beaglebone login:
Password:
Linux beaglebone 3.8.13-bone72 #1 SMP Tue Jun 16 21:36:04 UTC 2015 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
debian@beaglebone:~$

需要有线局域网

这个Debian 7.8的镜像在默认情况下没有安装连接无线局域网所需的工具,但是它非常精确。由于通过OSX的USB网络共享功能无法正常工作,因此我将通过有线局域网连接BeagleBone Black,并安装所需的包。

$ sudo apt-get update
$ sudo apt-get install usbutils wpasupplicant wireless-tools

重新启动网络。

$ sudo systemctl restart networking.service

请使用lsusb命令确认无线网卡适配器已被识别。

$ lsusb
Bus 001 Device 002: ID 2019:ab2a PLANEX GW-USNano2 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

无线局域网的配置 LAN de

使用wpa_passphrase命令,指定SSID和密码,创建wpa_supplicant.conf文件。

$ sudo sh -c 'wpa_passphrase SSID PASSWORD >> /etc/wpa_supplicant/wpa_supplicant.conf'
$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
network={
  ssid="SSID"
  #psk="PASSWORD"
  psk=PASSWORD
}

将wlan0的启动和wpa_supplicant.conf的设置读取配置写入/etc/network/interfaces文件中。

$ sudo vi /etc/network/interfaces
...
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
...

重新启动wlan0并从DHCP获取IP地址。

$ sudo ifdown wlan0
$ sudo ifup wlan0

最后,我们将使用ping命令来验证名称解析和与互联网的连接。

$ ping -c 1 www.yahoo.co.jp
PING www.g.yahoo.co.jp (183.79.71.173) 56(84) bytes of data.
64 bytes from f13.top.vip.kks.yahoo.co.jp (183.79.71.173): icmp_req=1 ttl=53 time=23.2 ms

--- www.g.yahoo.co.jp ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 23.215/23.215/23.215/0.000 ms

时区的变更

作为初始设定,将时区设置为 Asia/Tokyo。

$ sudo cp /etc/localtime{,.orig}
$ sudo ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

日期

安装 NTP。

$ sudo apt-get install ntp

设置NICT的NTP服务器。

#server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst
pool ntp.nict.jp iburst

我要重新启动 ntpd。

$ systemctl start ntp.service

Vim是一种文本编辑器。

安装Vim编辑器。

$ sudo apt-get install vim
$ mkdir ~/tmp

只进行不进行备份的设置。

set backupdir=~/tmp