RASPBIAN JESSIE LITEの初期設定
作業環境は、macOSですらないOSX。
wgetはバイナリを入れてある状態。ない人はcurlとか使ってね。
イメージファイルの入手
RASPBIAN JESSIE LITE落とす。
$ wget http://vx2-downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-04-10/2017-04-10-raspbian-jessie-lite.zip
重すぎ。
1時間かかると出る。
他から落としたほうがよさげ。
ミラーのリスト:https://www.raspbian.org/RaspbianMirrors
日本は3つしかないわ〜。
- http://ftp.jaist.ac.jp/raspbian
- http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian/
- http://ftp.yz.yamagata-u.ac.jp/pub/linux/raspbian/raspbian/
これは、debianのパッケージミラーで、イメージのミラーは見当たらない。
探すとイメージのミラーはあったけど、LITEがミラーされてない。
http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian/images/raspbian-2017-04-10/
たぶん日本ではRaspiなんか流行ってないんですね...
RSさんとか、スイッチサイエンスさんとか、ミラー運用しないんですかね...
ミラーみつけた。
別パスか...
http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian_lite/images/raspbian_lite-2017-04-10/
$ wget http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian_lite/images/raspbian_lite-2017-04-10/2017-04-10-raspbian-jessie-lite.zip $ ls -lh 2017-04-10-raspbian-jessie-lite.zip -rw-r--r-- 1 kinneko staff 294M 4 12 02:40 2017-04-10-raspbian-jessie-lite.zip
それでも30分くらいはかかった。つらい。
落としたイメージのチェック。
SHA-1:c24a4c7dd1a5957f303193fee712d0d2c0c6372d
$ shasum 2017-04-10-raspbian-jessie-lite.zip c24a4c7dd1a5957f303193fee712d0d2c0c6372d 2017-04-10-raspbian-jessie-lite.zip
間違いない。
イメージファイルをmicroSDに焼きこみ
展開して焼く。
7zipなのでツールがいる。
$ wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/theunarchiver/unar1.8.1.zip $ unzip unar1.8.1.zip Archive: unar1.8.1.zip inflating: lsar inflating: unar
展開。
$ ./unar 2017-04-10-raspbian-jessie-lite.zip 2017-04-10-raspbian-jessie-lite.zip: Zip 2017-04-10-raspbian-jessie-lite.img (1297862656 B)... OK. Successfully extracted to "./2017-04-10-raspbian-jessie-lite.img".
microSDに書き込む。
$ diskutil list /dev/disk0 /dev/disk1 /dev/disk3 #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *7.9 GB disk3 1: Windows_FAT_32 boot 66.1 MB disk3s1 2: Linux 7.9 GB disk3s2
disk3で認識されている。
前にPIXEL焼いていたのを入れたので、FAT領域が自動マウントされているのでアンマウントする。
$ diskutil umountDisk /dev/disk3 Unmount of all volumes on disk3 was successful
書き込む。
$ sudo dd bs=100m if=2017-04-10-raspbian-jessie-lite.img of=/dev/rdisk3 Password: 12+1 records in 12+1 records out 1297862656 bytes transferred in 94.807746 secs (13689416 bytes/sec)
起動時にsshを有効にする設定
この頃のraspbianでは、sshはデフォルトでオフになった模様。
http://downloads.raspberrypi.org/raspbian/release_notes.txt
2016-11-25:
* SSH disabled by default; can be enabled by creating a file with name "ssh" in boot partition
$ ssh pi@raspberrypi.local ssh: connect to host raspberrypi.local port 22: Connection refused
起動時にsshdをオンにするには、/boot/ssh/を作っておく。
こういう簡単にする目的で、隠蔽したやり方を取るってよくないと思うのだけどなぁ...
このまま、Mac上でsshディレクトリを作る。
$ diskutil list /dev/disk0 /dev/disk1 /dev/disk3 #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *7.9 GB disk3 1: Windows_FAT_32 boot 43.0 MB disk3s1 2: Linux 7.9 GB disk3s2
ターゲットは、disk3s1のようだ。
$ df | grep "disk3s1" /dev/disk3s1 82644 41534 41110 51% 0 0 100% /Volumes/boot
/Volumes/bootにマウントされているので、sshdディレクトリを作成する。
$ ls /Volumes/boot/ COPYING.linux bcm2710-rpi-cm3.dtb kernel.img LICENCE.broadcom bootcode.bin kernel7.img LICENSE.oracle cmdline.txt overlays bcm2708-rpi-0-w.dtb config.txt start.elf bcm2708-rpi-b-plus.dtb fixup.dat start_cd.elf bcm2708-rpi-b.dtb fixup_cd.dat start_db.elf bcm2708-rpi-cm.dtb fixup_db.dat start_x.elf bcm2709-rpi-2-b.dtb fixup_x.dat bcm2710-rpi-3-b.dtb issue.txt
$ mkdir /Volumes/boot/ssh $ ls -l /Volumes/boot/ | grep ssh drwxrwxrwx 1 kinneko staff 512 6 12 20:28 ssh
microSDを取り出す。
$ diskutil eject /dev/disk3 Disk /dev/disk3 ejected
ヘッドレスでssh接続する
Raspi3に挿入して起動する。
初回起動時に、microSDの未使用領域へのパーティションの伸長は自動で行われる。
Macに有線接続して、Mac側でEtherをWANに出ている無線と共有する。
デフォルトのホスト名はraspberrypi。
avahi-daemonは動いているということなので、mDNSで名前解決できるはず。
$ ping -c 1 raspberrypi.local PING raspberrypi.local (192.168.2.125): 56 data bytes 64 bytes from 192.168.2.125: icmp_seq=0 ttl=64 time=0.386 ms --- raspberrypi.local ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.386/0.386/0.386/0.000 ms
見える。
sshしてみる。
デフォルトのユーザ名はpi、パスワードはraspberry。
$ ssh pi@raspberrypi.local The authenticity of host 'raspberrypi.local (192.168.2.125)' can't be established. RSA key fingerprint is 97:91:3a:34:2a:bd:03:5e:25:41:2a:74:db:b3:44:82. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'raspberrypi.local' (RSA) to the list of known hosts. Warning: the RSA host key for 'raspberrypi.local' differs from the key for the IP address '192.168.2.125' Offending key for IP in /Users/kinneko/.ssh/known_hosts:111 Are you sure you want to continue connecting (yes/no)? yes pi@raspberrypi.local's password: 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. SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. pi@raspberrypi:~ $
入れた。
パッケージ更新
パッケージデータベースの更新。
pi@raspberrypi:~ $ sudo apt-get update Get:1 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB] Get:2 http://archive.raspberrypi.org jessie InRelease [22.9 kB] Get:3 http://mirrordirector.raspbian.org jessie/main armhf Packages [9,533 kB] Get:4 http://archive.raspberrypi.org jessie/main armhf Packages [163 kB] Get:5 http://archive.raspberrypi.org jessie/ui armhf Packages [57.9 kB] Ign http://archive.raspberrypi.org jessie/main Translation-en_GB Ign http://archive.raspberrypi.org jessie/main Translation-en Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB Ign http://archive.raspberrypi.org jessie/ui Translation-en Get:6 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [43.3 kB] Get:7 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [84.2 kB] Get:8 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B] Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB Ign http://mirrordirector.raspbian.org jessie/main Translation-en Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en Fetched 9,920 kB in 1min 50s (89.5 kB/s) Reading package lists... Done
翻訳系のパッケージリポジトリでIgnがいっぱい出ているな...
いろいろメンテされてないのかな...
アップグレードかける。
pi@raspberrypi:~ $ sudo apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: bind9-host binutils ca-certificates initramfs-tools libbind9-90 libc-bin libc-dev-bin libc6 libc6-dbg libc6-dev libdns-export100 libdns100 libgnutls-deb0-28 libgnutls-openssl27 libicu52 libirs-export91 libisc-export95 libisc95 libisccc90 libisccfg-export90 libisccfg90 libldap-2.4-2 liblwres90 libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0 librtmp1 libsystemd0 libtasn1-6 libtirpc1 libudev1 libwbclient0 locales login multiarch-support passwd perl perl-base perl-modules raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods raspi-config rpcbind samba-common sudo systemd systemd-sysv tzdata udev unzip vim-common vim-tiny wget 55 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 109 MB of archives. After this operation, 4,494 kB of additional disk space will be used. Do you want to continue? [Y/n] y (snip)
インストールパッケージ数。
pi@raspberrypi:~ $ dpkg -l | wc 432 4148 52678
ヘッドレス用ミニマム環境には程遠い感じ。
pi@raspberrypi:~ $ dpkg -l | awk 'NR>5 {print $2}' | tr '\n' ' '
acl adduser alsa-utils apt apt-listchanges apt-transport-https apt-utils aptitude aptitude-common avahi-daemon base-files base-passwd bash bash-completion bind9-host binutils bluez bluez-firmware bsdmainutils bsdutils build-essential bzip2 ca-certificates cifs-utils console-setup console-setup-linux coreutils cpio cpp cpp-4.9 crda cron curl dash dbus dc debconf debconf-i18n debconf-utils debianutils device-tree-compiler dhcpcd5 diffutils dmidecode dmsetup dosfstools dphys-swapfile dpkg dpkg-dev e2fslibs:armhf e2fsprogs ed fake-hwclock fakeroot fbset file findutils firmware-atheros firmware-brcm80211 firmware-libertas firmware-ralink firmware-realtek g++ g++-4.9 gcc gcc-4.6-base:armhf gcc-4.7-base:armhf gcc-4.8-base:armhf gcc-4.9 gcc-4.9-base:armhf gdb gdbserver geoip-database gettext-base gnupg gpgv grep groff-base gzip hardlink hostname ifupdown info init init-system-helpers initramfs-tools initscripts insserv install-info iproute2 iptables iputils-ping isc-dhcp-client isc-dhcp-common iso-codes iw kbd keyboard-configuration klibc-utils kmod less libacl1:armhf libalgorithm-c3-perl libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libapt-inst1.5:armhf libapt-pkg4.12:armhf libarchive-extract-perl libasan1:armhf libasound2:armhf libasound2-data libasprintf0c2:armhf libatomic1:armhf libattr1:armhf libaudit-common libaudit1:armhf libavahi-common-data:armhf libavahi-common3:armhf libavahi-core7:armhf libbind9-90 libblkid1:armhf libboost-iostreams1.49.0 libboost-iostreams1.50.0 libboost-iostreams1.53.0 libboost-iostreams1.54.0:armhf libboost-iostreams1.55.0:armhf libbsd0:armhf libbz2-1.0:armhf libc-bin libc-dev-bin libc6:armhf libc6-dbg:armhf libc6-dev:armhf libcap-ng0:armhf libcap2:armhf libcap2-bin libcgi-fast-perl libcgi-pm-perl libclass-c3-perl libclass-c3-xs-perl libcloog-isl4:armhf libcomerr2:armhf libcpan-meta-perl libcryptsetup4:armhf libcurl3:armhf libcurl3-gnutls:armhf libcwidget3:armhf libdaemon0:armhf libdata-optlist-perl libdata-section-perl libdb5.3:armhf libdbus-1-3:armhf libdebconfclient0:armhf libdevmapper1.02.1:armhf libdns-export100 libdns100 libdpkg-perl libdrm2:armhf libedit2:armhf libestr0 libevent-2.0-5:armhf libexpat1:armhf libfakeroot:armhf libfcgi-perl libffi6:armhf libfile-fcntllock-perl libfreetype6:armhf libfreetype6-dev libgcc-4.9-dev:armhf libgcc1:armhf libgcrypt20:armhf libgdbm3:armhf libgeoip1:armhf libglib2.0-0:armhf libglib2.0-data libgmp10:armhf libgnutls-deb0-28:armhf libgnutls-openssl27:armhf libgomp1:armhf libgpg-error0:armhf libgssapi-krb5-2:armhf libhogweed2:armhf libicu52:armhf libident libidn11:armhf libirs-export91 libisc-export95 libisc95 libisccc90 libisccfg-export90 libisccfg90 libisl10:armhf libiw30:armhf libjim0.75:armhf libjpeg62-turbo:armhf libjson-c2:armhf libk5crypto3:armhf libkeyutils1:armhf libklibc libkmod2:armhf libkrb5-3:armhf libkrb5support0:armhf libldap-2.4-2:armhf liblocale-gettext-perl liblog-message-perl liblog-message-simple-perl liblogging-stdlog0:armhf liblognorm1:armhf libluajit-5.1-common liblwres90 liblzma5:armhf libmagic1:armhf libmodule-build-perl libmodule-pluggable-perl libmodule-signature-perl libmount1:armhf libmpc3:armhf libmpfr4:armhf libmro-compat-perl libncurses5:armhf libncursesw5:armhf libnettle4:armhf libnewt0.52:armhf libnfnetlink0:armhf libnfsidmap2:armhf libnih-dbus1 libnih1 libnl-3-200:armhf libnl-genl-3-200:armhf libnss-mdns:armhf libopts25:armhf libp11-kit0:armhf libpackage-constants-perl libpam-chksshpwd:armhf libpam-modules:armhf libpam-modules-bin libpam-runtime libpam0g:armhf libparams-util-perl libparted2:armhf libpcre3:armhf libpcsclite1:armhf libpipeline1:armhf libplymouth4:armhf libpng12-0:armhf libpng12-dev:armhf libpod-latex-perl libpod-readme-perl libpopt0:armhf libprocps3:armhf libpsl0:armhf libpython-stdlib:armhf libpython2.7:armhf libpython2.7-minimal:armhf libpython2.7-stdlib:armhf libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0 libreadline6:armhf libregexp-common-perl librtmp1:armhf libsamplerate0:armhf libsasl2-2:armhf libsasl2-modules:armhf libsasl2-modules-db:armhf libselinux1:armhf libsemanage-common libsemanage1:armhf libsepol1:armhf libsigc++-1.2-5c2 libsigc++-2.0-0c2a:armhf libslang2:armhf libsmartcols1:armhf libsoftware-license-perl libsqlite3-0:armhf libss2:armhf libssh2-1:armhf libssl1.0.0:armhf libstdc++-4.9-dev:armhf libstdc++6:armhf libsub-exporter-perl libsub-install-perl libsysfs2:armhf libsystemd0:armhf libtalloc2:armhf libtasn1-6:armhf libterm-ui-perl libtext-charwidth-perl libtext-iconv-perl libtext-soundex-perl libtext-template-perl libtext-wrapi18n-perl libtimedate-perl libtinfo5:armhf libtirpc1:armhf libubsan0:armhf libudev0:armhf libudev1:armhf libusb-0.1-4:armhf libusb-1.0-0:armhf libustr-1.0-1:armhf libuuid1:armhf libv4l-0:armhf libv4l2rds0:armhf libv4lconvert0:armhf libwbclient0:armhf libwrap0:armhf libx11-6:armhf libx11-data libxapian22 libxau6:armhf libxcb1:armhf libxdmcp6:armhf libxext6:armhf libxml2:armhf libxmuu1:armhf libxtables10 linux-libc-dev:armhf locales login logrotate lsb-base lsb-release lua5.1 luajit make makedev man-db manpages manpages-dev mawk mime-support module-init-tools mount mountall multiarch-support nano ncdu ncurses-base ncurses-bin ncurses-term net-tools netbase netcat-openbsd netcat-traditional nfs-common ntp openresolv openssh-client openssh-server openssh-sftp-server openssl parted passwd patch perl perl-base perl-modules pi-bluetooth pkg-config plymouth procps psmisc python python-apt python-apt-common python-minimal python-rpi.gpio python-support python2.7 python2.7-minimal raspberrypi-bootloader raspberrypi-kernel raspberrypi-net-mods raspberrypi-sys-mods raspbian-archive-keyring raspi-config raspi-copies-and-fills readline-common rename rpcbind rsyslog samba-common sed sensible-utils sgml-base shared-mime-info ssh startpar strace sudo systemd systemd-sysv sysv-rc sysvinit-utils tar tasksel tasksel-data tcpd traceroute triggerhappy tzdata ucf udev unzip usb-modeswitch usb-modeswitch-data usbutils util-linux v4l-utils vim-common vim-tiny wget whiptail whois wireless-regdb wireless-tools wpasupplicant xauth xdg-user-dirs xkb-data xml-core xz-utils zlib1g:armhf zlib1g-dev:armhf
ざっと見ても、依存関係を追ってまで積極的に削除するパッケージはなさそう。
WiFiとかBTとか機能が多いので、こんなもんか。
都合でRaspi3がたくさんあるのでホスト名を設定。
こいつは9号機。
pi@raspberrypi:~ $ hostname raspberrypi pi@raspberrypi:~ $ sudo hostname raspi09 pi@raspberrypi:~ $ cat /etc/hostname raspi09 pi@raspberrypi:~ $ hostname raspi09
名前解決できるように/etc/hostsにループバックアドレスに設定したホスト名を書いておく。
pi@raspberrypi:~ $ sudo vi /etc/hosts 127.0.0.1 localhost raspi09
これ、ちょっと気になるけど放置する。
127.0.1.1 raspberrypi
確認。
pi@raspberrypi:~ $ ping -c 1 raspi09 PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.087 ms --- localhost ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.087/0.087/0.087/0.000 ms
mDNSのアナウンスも変更しておく。
pi@raspberrypi:~ $ sudo systemctl restart avahi-daemon.service
再ログインする。
pi@raspberrypi:~ $ exit logout $ ssh pi@raspi09.local The authenticity of host 'raspi09.local (192.168.2.125)' can't be established. RSA key fingerprint is 96:9c:f5:9f:0f:b9:d9:39:b1:ef:48:4b:84:7b:39:20. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'raspi09.local' (RSA) to the list of known hosts. pi@raspberrypi.local's password: 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. Last login: Tue Jun 13 04:37:38 2017 from 192.168.2.1 SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. pi@raspi09:~ $
sshログインメッセージを短く
うざいので短くする。
主なところは、motd(message of the day)がやっている。
debianではwheezy以降は、メッセージ内容は/etc/motdに固定されている。
pi@raspi09:~ $ cat /etc/motd 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.
motdは、どのパッケージにも含まれていないようなので削除してしまえばいい感じ。
pi@raspi09:~ $ sudo rm /etc/motd pi@raspi09:~ $ ls -l /etc/motd ls: cannot access /etc/motd: No such file or directory
ログインしてみる。
$ ssh pi@raspberrypi.local pi@raspberrypi.local's password: Last login: Tue Jun 13 05:31:36 2017 from 192.168.2.1 SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. pi@raspi09:~ $
まだ出るな。
/etc/profile.d/sshpwd.shにそれっぽいものがある。
/run/sshwarnをチェックして拾っている。
pi@raspi09:~ $ ls -l /run/sshwarn
-rw-r--r-- 1 root root 0 Jun 13 05:48 /run/sshwarn
piユーザーのパスワードを変更してないと表示するのかな?
あった。
https://www.raspberrypi.org/forums/viewtopic.php?t=172787&p=1105446
PAMを使ってパスワードの変更をチェックしているようだ。
書き換える。
pi@raspi09:~ $ sudo vi /etc/pam.d/common-session #session optional pam_chksshpwd.so
再起動して確認。
pi@raspi09:~ $ sudo reboot $ ssh pi@raspi09.local pi@raspi09.local's password: Last login: Tue Jun 13 06:05:01 2017 from 192.168.2.1 pi@raspi09:~ $ ls /run/sshwarn ls: cannot access /run/sshwarn: No such file or directory
よし減った。もちろんパスワードを変更しておくのが一番いい。
しかし、こんな余計な処理は入らないほうがいい。