Let op: Tweakers stopt per 2023 met Tweakblogs. In
dit artikel
leggen we uit waarom we hiervoor hebben gekozen.
Raspberry Pi Headless setup
Best thing of 2015? The Raspberry Pi Zero! Slower, less memory, too few interfaces for practical use and overal so much of a hassle to install I'd rather watch reruns of four month old golf matches. It's amazing and it's also only 5 euro.
But that installation. No ethernet and a mini HDMI. That's a real pain. I did the first few by setting up a fresh image on a RPI B (using Ethernet), then cloning that, but that was not a pretty method. There are some excellent blogs out there that explained to me how to open the image on the SD card, but they required a Linux machine with a card reader. The best solution was to configure the image file itself, so any new Raspberry Pi I load with said image can join my network without having to attach a monitor or an ethernet cable.
To enjoy such a pain-free installation on the RPI Zero or any other Raspberry Pi, you'll need the following:
• Any flavour Raspberry Pi. And the common stuff like power and a MicroSD card.
• The most recent Raspbian image. I use 2015-11-21-raspbian-jessie-lite.img
• The Raspberry Pi should have an USB stick based on the RTL8188CUS chipset. For example, the PiHUT 802.11n WIFI dongle, the EDUP N8508 or N8508GS WiFi stick or any of those other tiny, tiny WIFI USB stubs costing about 5 euro's. This should also work with anything based on the 8192CU, but I did not test those.
• Any Linux machine for editing the image file and running NMAP. Another RPI already running or a VM will work just fine.
Okay. So every sector contains 512 bytes. The second disk starts at sector offset 131072 (second column on the last line). This means mount will have to open our image file from byte 512 * 131072 = 67108864 and up.
Cake for everybody! That's half the job already done. Assuming you have a RTL8188CUS card, edit /etc/wpa_supplicant/wpa_supplicant.conf and replace it's content with the following:
You could also configure a static IP address, but for me that contradicts the purpose of being able to load the image onto multiple RPI's.
Since the RTL8188CUS has some erratic behaviour with power saving mode, we'll disable that in two seperate ways:
There. Now leave the /mnt directory and "umount /mnt". "Burn" the image file to the SD card with whatever tool you favor - I usually copy it back to my Windows machine and use win32disk imager.
There! A fresh Raspberry Pi Zero, on a clean image.
Additionally, since we are headless, you should consider the following:
- Lower the amount of memory allocated to graphics: using raspi-config, set the memory split value to 16 mb.
- Disable the HDMI port and save power: add "/usr/bin/tvservice -o" to /etc/rc.local
But that installation. No ethernet and a mini HDMI. That's a real pain. I did the first few by setting up a fresh image on a RPI B (using Ethernet), then cloning that, but that was not a pretty method. There are some excellent blogs out there that explained to me how to open the image on the SD card, but they required a Linux machine with a card reader. The best solution was to configure the image file itself, so any new Raspberry Pi I load with said image can join my network without having to attach a monitor or an ethernet cable.
To enjoy such a pain-free installation on the RPI Zero or any other Raspberry Pi, you'll need the following:
• Any flavour Raspberry Pi. And the common stuff like power and a MicroSD card.
• The most recent Raspbian image. I use 2015-11-21-raspbian-jessie-lite.img
• The Raspberry Pi should have an USB stick based on the RTL8188CUS chipset. For example, the PiHUT 802.11n WIFI dongle, the EDUP N8508 or N8508GS WiFi stick or any of those other tiny, tiny WIFI USB stubs costing about 5 euro's. This should also work with anything based on the 8192CU, but I did not test those.
• Any Linux machine for editing the image file and running NMAP. Another RPI already running or a VM will work just fine.
Editting the image
Unzip the downloaded Raspbian image so you have the basis 1,5 gb .img file. Copy that to your Linux machine. We are going to mount the file like a filesystem, but before we can do that there is a small hurdle, this file actually contains two images: a small system for booting, and the actual Raspbian installation that we would want to modify. If we don't tell the mount command where our disk starts in the image file, it will fail with the "mount: wrong fs type, bad option, bad superblock" error. So first, we will determine at which byte offset mount will open the file. We use fdisk to show us the partition information found in the image file:code:
1
2
3
4
5
6
7
8
9
10
11
12
| root@linux:~# fdisk -l 2015-11-21-raspbian-jessie-lite.img Disk 2015-11-21-raspbian-jessie-lite.img: 1.4 GiB, 1458569216 bytes, 2848768 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 Disklabel type: dos Disk identifier: 0xb3c5e39a Device Boot Start End Sectors Size Id Type 2015-11-21-raspbian-jessie-lite.img1 8192 131071 122880 60M c W95 FAT32 (LBA) 2015-11-21-raspbian-jessie-lite.img2 131072 2848767 2717696 1.3G 83 Linux |
Okay. So every sector contains 512 bytes. The second disk starts at sector offset 131072 (second column on the last line). This means mount will have to open our image file from byte 512 * 131072 = 67108864 and up.
code:
1
2
3
4
| root@linux:~# mount -o loop,offset=67108864 2015-11-21-raspbian-jessie-lite.img /mnt/ root@linux:~# ls /mnt bin dev home lost+found mnt proc run srv tmp var boot etc lib media opt root sbin sys usr |
Cake for everybody! That's half the job already done. Assuming you have a RTL8188CUS card, edit /etc/wpa_supplicant/wpa_supplicant.conf and replace it's content with the following:
code:
1
2
3
4
5
6
7
8
9
| ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOUR_SSID"
psk="YOUR_WIFI_PASSWORD"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
} |
You could also configure a static IP address, but for me that contradicts the purpose of being able to load the image onto multiple RPI's.
Since the RTL8188CUS has some erratic behaviour with power saving mode, we'll disable that in two seperate ways:
code:
1
2
| echo "wireless-power off" >> /mnt/etc/network/interfaces; echo "options 8192cu rtw_power_mgnt=0 rtw_enusbss=0" >> /mnt/etc/modprobe.d/8192cu.conf |
There. Now leave the /mnt directory and "umount /mnt". "Burn" the image file to the SD card with whatever tool you favor - I usually copy it back to my Windows machine and use win32disk imager.
Booting..
Power it up. Check that the light on the WiFi sticks blinks like a disco. Now from the Linux machine, run an NMAP scan for new devices on port 22 on your subnet:code:
1
2
3
4
5
6
7
8
9
| root@linux:~# nmap -p 22 --open 192.168.1.0/24 ... Nmap scan report for 192.168.1.235 Host is up (0.0090s latency). PORT STATE SERVICE 22/tcp open ssh MAC Address: E8:7E:06:32:33:95 (Edup International (hk) CO.) |
There! A fresh Raspberry Pi Zero, on a clean image.
Additionally, since we are headless, you should consider the following:
- Lower the amount of memory allocated to graphics: using raspi-config, set the memory split value to 16 mb.
- Disable the HDMI port and save power: add "/usr/bin/tvservice -o" to /etc/rc.local
12-'15 Connect a Bluetooth lightbulb to Philips HUE
Reacties
You could also use a distro like DietPi.
It has the ability to automate installations and it's very small (100MB download, <1GB image).
Take a look at dietpi.net
It has the ability to automate installations and it's very small (100MB download, <1GB image).
Take a look at dietpi.net
Mooi! Met een nóg slimmere methode om wifi tevoren te configureren. Dat had mij een avond aanrommelen bespaard!Take a look at dietpi.net
Bij de Model A zit ik ook iedere keer te klooien om de wifi aan de gang te krijgen. Zonder wifi immers geen ssh en met wifi geen toetsenbordBene schreef op zaterdag 02 januari 2016 @ 23:42:
[...]
Mooi! Met een nóg slimmere methode om wifi tevoren te configureren. Dat had mij een avond aanrommelen bespaard!
Reageren is niet meer mogelijk