Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Last active January 26, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save G33kDude/7bbfa2914c5ca2d815529e417d49b9f5 to your computer and use it in GitHub Desktop.
Save G33kDude/7bbfa2914c5ca2d815529e417d49b9f5 to your computer and use it in GitHub Desktop.

Making a read-only ev3dev system

Mounting ev3dev.img

Start by downloading the latest ev3dev release from http://www.ev3dev.org/download/.

Once downloaded, set it up as a loop device. Find out what the first unused loop device is by running losetup -f. This tells you which loop device will be used once set up. On my system, it printed /dev/loop0. Now we can run the command to actually set up the loop device:

sudo losetup -Pf /path/to/ev3dev.img

This will have created a few device endpoints in /dev: /dev/loop0, /dev/loop0p1, and /dev/loop0p2. These are the loop device and its two partitions. We're interested in the second partition, and will mount it with the default settings (both read and write) at /mnt.

sudo mount /dev/loop0p2 /mnt

Editing fstab to load ev3dev read-only

As root, open /mnt/etc/fstab in a text editor and edit it as shown below. Change the options for /boot/flash and / to include the read-only flag ro. At the end of the file, add a new virtual file system for /tmp so that temporary files can still be created. Because the EV3 is short on RAM, we're only using 20M of it for this purpose.

#<file system>  <mount point>   <type> <options>                              <dump> <pass>
/dev/mmcblk0p1  /boot/flash     vfat   defaults,errors=remount-ro,noatime,ro  0      2
/dev/mmcblk0p2  /               ext4   defaults,errors=remount-ro,noatime,ro  0      1
proc            /proc           proc   defaults                               0      0
tmpfs           /tmp            tmpfs  defaults,size=20M                      0      0

Setting up wpa_supplicant for persistent WiFi credentials

Start by disabling connman, as we will not be using it.

sudo ln -s /dev/null /mnt/etc/systemd/system/connman.service

As root, create /mnt/etc/network/interfaces with -rw-r--r- permissions and write to it as shown below.

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# Automatically configure WiFi
auto wlan0
# Allow the wifi device to be removed and reinserted
allow-hotplug wlan0
# Get a network address from DHCP
iface wlan0 inet dhcp
    # Load WiFi configuration from this file
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Create /mnt/etc/wpa_supplicant/wpa_supplicant.conf with -rw------ permissions and write to it as shown below.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=ev3dev
update_config=1

network={
   ssid="YourSSID"
   psk="YourPre-SharedKey"
}

Creating systemd services

You will not be able to run systemctl enable service normally because everything is read-only, so you'll have to create the required symlinks by hand. For a normal service that is WantedBy=multi-user.target, this entails creating a symlink to your service in /etc/systemd/system/multi-user.target.wants/. For example:

sudo ln -s /etc/systemd/system/mycustom.service /etc/systemd/system/multi-user.target.wants/mycustom.service

Unmounting ev3dev.img

Once you have made your changes to the ev3dev image, you should properly unmount it. Start by running umount on your mount point /mnt:

sudo umount /mnt

Once unmounted, detach the original loop device. Make sure to use the correct loop device so you don't detach the wrong thing by accident.

sudo losetup -d /dev/loop0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment