When doing ifup wlan0 on a system with / mounted as read-only (embedded computer), I get this error:

Failed to connect to non-global ctrl_ifname: wlan0  error: Read-only file system
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

can't create /var/lib/dhcp/dhclient.wlan0.leases: Read-only file system
Listening on LPF/wlan0/80:1f:02:d3:42:b8
Sending on   LPF/wlan0/80:1f:02:d3:42:b8
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13
...
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
No DHCPOFFERS received.
No working leases in persistent database - sleeping.

On the other hand, when doing ifup wlan0 with / mounted as read-write, no problem, an IP is succesfully attributed.

How to make DHCP work on a read-only root filesystem?


# /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "<myssid>"
wpa-psk "<mypasswd>"
share|improve this question
    
/var and /tmp must be writable. If you search for "read only root filesystem", there are several guides explaining this. You can either use a separate disk partition for /var, make/var a tmpfs partition, or use a unionfs overlay so the file system appears writable but changes are forgotten on reboot. – Mikel Jun 16 '15 at 13:45

Create a tmpfs partition in RAM, and then symlink /var/lib/dhcp to a directory in it.

Edit: I'll assume that you can edit your root filesystem before changing it to read-only. So:

  1. Set up a tmpfs mount point with mkdir /mnt/ramdisk && mkdir /mnt/ramdisk/var-lib-dhcp
  2. Add the tmpfs to your fstab with tmpfs /mnt/ramdisk/var-lib-dhcp tmpfs size=10M 0 0
  3. Add a symbolic link from /var/lib/dhcp to /mnt/ramdisk/var-lib-dhcp
  4. Test while file system is read/write
  5. Make file system read-only, test again
share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – cuonglm Jun 16 '15 at 1:12
2  
How so? It gives a clear technique that solves the problem. Perhaps it doesn't include every detail some people would like, but the OP clearly understands partition creation. (And, if it's details that you miss, you should say so.) – Daniel Griscom Jun 16 '15 at 1:25
    
Thanks @DanielGriscom! I understand the "global" thing, but can you help on how to do it? Should I add tmpfs /tmp/ tmpfs 0 0 in /etc/fstab, and then, where to set up the automatic symlink on boot? (I use systemd) ? Thanks a lot in advance. Last think: can't I simply add this to fstab: tmpfs /var/lib/dhcp tmpfs 0 0 in /etc/fstab ? – Basj Jun 16 '15 at 6:50
    
(I think I already tried this last thing in my previous comment, and that it didn't work) – Basj Jun 16 '15 at 7:01
    
Did my suggestion work for you? – Daniel Griscom Jun 18 '15 at 17:56

Assuming that you already have a tmpfs mount point, for instance /run, /var/run or /tmp, a very simple approach is executing,

sudo rm -rf /var/lib/dhcp/

and

sudo ln -s /run /var/lib/dhcp

The first one will remove your /var/lib/dhcp database directory, the second will create a link to /run. Or you can make the link to /tmp or /var/run.

You will need to remount your filesystem read-write in order to execute the above changes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.