I've been using Alpine Linux for some weeks now in most of my Docker containers with great success. I recently bought a Raspberry Pi2 to hook up to AWS IoT and thought Alpine Linux would make a great fit given the small foot print and emphasis on security.
Download Raspberry Pi Alpline Linux image
Download an Alpine Linux archive for use with Raspberry Pi from https://alpinelinux.org/downloads/.
Prepare SD card
First, you'll need to reformat the MicroSD card to have a (bootable) FAT32 filesystem. To do this from OSX, follow these instructions. If you are in Linux, use gparted or fdisk to format the SD card to a FAT32 partition type and mark it as bootable. I'm not sure what to use for Windows.
One you've got a mountable FAT32 partition, copy over the Alpine Linux archive files. Again, I'm on OSX so I've used Disk Utility to mount the filesystem to a volume with the pattaren of
/Volumes/$PARTITION_NAME/. If you were in Linux, you'd
sudo mount /dev/$your_msdos_parititon /mnt/rasppi2 or some-such.
# Decompress the downloaded archive and extract to the mounted SD card. sudo tar xvf /path/to/alpine/archive.tar.gz -C /path/to/msdos/mount/point # OSX example. tar xvf ~/Downloads/alpine-rpi-3.3.3-armhf.rpi.tar.gz -C /Volumes/RASPINE/
Unmount the MS-DOS partition before you remove the SD card from your machine! Strange things can happen.
Your Raspberry Pi should now boot up when you install the SD card in the Raspberry Pi.
Log in with root (no password!). Run alpine-setup and answer the questions to expedite the setup process.
If you want wireless connectivity, be sure to configure the wlan0 interface when it prompts you. If you choose dhcp, that's fine but it might fail if you need WPA authentication info for the wireless connection. This can easily be solved later, so just keep moving.
If you picked
chrony as your NTP daemon (timeserver), you'll need to make it start at boot.
rc-update add chronyd boot
Setup Wireless Connection (WPA)
# Install dependency packages. apk add wireless-tools wpa_supplicant # Scan for available wireless networks. iwlist wlan0 scanning | grep SSID # Generate WPA passphrase secret wpa_passphrase "YOUR SSID" > /etc/wpa.conf <type passphase and hit enter> # OPTIONAL, remove plain text password. # edit /etc/wpa.conf and remove commented out plain text password.
Now that you have everything setup for wireless, enable it for the wireless interface on boot.
/etc/network/interfaces to contain the following (you could have some of this there already).
auto wlan0 iface wlan0 inet dhcp hostname YOUR_HOSTNAME wireless-essid YOUR SSID pre-up wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa.conf
Bring up the interface and you should be all good.
See if you can contact the internet world by doing a
ping 18.104.22.168 or some-such.
If you are now online, it would be a great time to grab grab the time from a NTP server and install some updates!
# if you picked chronyd in setup-alpine service chronyd restart apk update apk upgrade
Remember, only /etc changes are persisted accross reboots and only if you have committed the changes...so commit all of the hard work.
Add a non-root user
This is technically optional, but highly advised. Also, you'll want to add a non-root user if you want to SSH to your Raspberry Pi.
apk add sudo adduser lyle -G wheel # Running the following will put you into the vi editor. visudo # Uncomment the line for %wheel # If you are new to vi... # 1. press "/" to search # 2. enter "%wheel" and hit [enter] # 3. hit "x" twice at the beginning of the line to delete the first 2 characters # (this makes the line active and not commented anymore) # 4. hit Escape (to go back into command mode) # 5. enter in ":wq" and hit [enter] to write and quit # persist /etc lbu commit
I'd like some files to be able to change and persist between reboot. To do this, you'll need to create a filesystem to store files on.
I only care about
/home, but adjust to what you need to persist, keeping in mind the media of your persisted filesystem.
# Create a small writable filesystem (1GB). mount /media/mmcblk0p1 -o rw,remount sed -i 's/vfat\ ro,/vfat\ rw,/' /etc/fstab dd if=/dev/zero of=/media/mmcblk0p1/persist.img bs=1024 count=0 seek=1048576 apk add e2fsprogs mkfs.ext4 /media/mmcblk0p1/persist.img # Mount storage. echo "/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors=remount-ro 0 0" >> /etc/fstab mkdir /media/persist mount -a # Create overlay directories. mkdir /media/persist/usr mkdir /media/persist/home mkdir /media/persist/.work echo "overlay /usr overlay lowerdir=/usr,upperdir=/media/persist/usr,workdir=/media/persist/.work 0 0" >> /etc/fstab echo "overlay /home overlay lowerdir=/home,upperdir=/media/persist/home,workdir=/media/persist/.work 0 0" >> /etc/fstab mount -a # Persist /etc lbu commit
So, hopefully you have a Raspberry Pi up and running Alpine Linux. Happy hacking! I've posted some helpful links below: