LoginSignup
12
18

More than 5 years have passed since last update.

Raspberry PI でNetwork Bootに挑戦

Posted at

はじめに

RaspberryPiが20台くらい手に入ったのですが、SDカードが足りない!
そんなときってよくありますよね。
RaspberyPi3からネットワークブートが可能になったようなので挑戦しました

公式の参考情報を見ながら進めていきます

英語を読める方は本家の手順を参考にしてください。

NETWORK BOOTING
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net.md
NETWORK BOOT YOUR RASPBERRY PI
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net_tutorial.md

やってみた

Server側の設定

  • RaspberyPI3を用意しましょう
  • SDカードにいつものRaspbianを用意する
    • いつものNOOBSをいつもの手順で準備しましょう
  • OSのアップデートを掛けます
# If on raspbian lite you need to install rpi-update before you can use it:
$ sudo apt-get update; sudo apt-get install rpi-update
$ sudo BRANCH=next rpi-update
  • SDカードの容量いっぱいまでfilesystemを使えるようにしましう。 終わったら再起動です
$ sudo raspi-config
$ sudo reboot

-ethoのIPアドレスをスタティックに振り直します。

$ sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet static 
        address 10.42.0.2
        netmask 255.255.255.0
        gateway 10.42.0.1
  • NFSサーバを建てます
$ sudo mkdir -p /nfs/client1
$ sudo apt-get install rsync
$ sudo rsync -xa --progress --exclude /nfs / /nfs/client1
$ cd /nfs/client1
$ sudo mount --bind /dev dev
$ sudo mount --bind /sys sys
$ sudo mount --bind /proc proc
$ sudo chroot .
$ rm /etc/ssh/ssh_host_*
$ dpkg-reconfigure openssh-server
$ exit
$ sudo umount dev
$ sudo umount sys
$ sudo umount proc
  • dnsmasqの設定をします
sudo apt-get update
sudo apt-get install dnsmasq tcpdump
sudo rm /etc/resolvconf/update.d/dnsmasq
sudo reboot
sudo echo | sudo tee /etc/dnsmasq.conf
sudo nano /etc/dnsmasq.conf
  • dnsmasq.confの作成
port=0
dhcp-range=10.42.0.255,proxy
log-dhcp
enable-tftp
tftp-root=/tftpboot
pxe-service=0,"Raspberry Pi Boot"
  • /tftpboot を作ります
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot
sudo systemctl enable dnsmasq.service
sudo systemctl restart dnsmasq.service
cp -r /boot/* /tftpboot
sudo systemctl restart dnsmasq
  • NFS Rootのセットアップ
sudo apt-get install nfs-kernel-server
echo "/nfs/client1 *(rw,sync,no_subtree_check,no_root_squash)" | sudo tee -a /etc/exports
sudo systemctl enable rpcbind
sudo systemctl restart rpcbind
sudo systemctl enable nfs-kernel-server
sudo systemctl restart nfs-kernel-server

  • /tftpboot/cmdline.txtの作成
root=/dev/nfs nfsroot=10.42.0.2:/nfs/client1 rw ip=dhcp rootwait elevator=deadline
  • Server側の設定は以上です。

Client側の設定

  • RaspberyPI3を用意しましょう
  • SDカードにいつものRaspbianを用意する
    • いつものNOOBSをいつもの手順で準備しましょう
  • OSのアップデートを掛けます
# If on raspbian lite you need to install rpi-update before you can use it:
$ sudo apt-get update; sudo apt-get install rpi-update
$ sudo BRANCH=next rpi-update
  • USB bootモードを有効にします
echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
  • USBブートモードをONにします。 ネットワークブートですが、USBブートモードをONにします。
$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
  • vcgencmdの結果が以下の通りならOK
$ vcgencmd otp_dump | grep 17:
17:3020000a
  • 電源を停止させます。
$ sudo poweroff
  • 電源がちゃんと止まってから電源とSDカードを抜きます。
  • 再び電源を挿すとNetwork bootが始まります。

Network Bootで起動したはいいが…

SSH Serverがどうしても起動せず。
さて困った・・・。

12
18
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
12
18