Skip to content

Commit

Permalink
base-files: add option to make /var persistent
Browse files Browse the repository at this point in the history
In OpenWrt, /var is symlinked to /tmp by default. This is done to reduce
the amount of writes to the flash chip, which often have not the
greatest durability. As a result, things like DHCP or UPnP lease files,
are not persistent across reboots.

Since OpenWrt can run on devices with more durable storage, it makes
sense to have an option for a persistent /var. Add an option to make
/var persistent. When enabled, /var will no longer be symlinked to /tmp,
but /var/run will be symlink to /tmp/run, as it should contains only
files that should not be kept during reboot. The option is off by
default, to maintain the current behaviour.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
  • Loading branch information
stintel committed Aug 22, 2021
1 parent 31d984a commit 57807f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/Config-images.in
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,12 @@ menu "Target Images"
it will be mounted by PARTUUID which makes the kernel find the
appropriate disk automatically.

config TARGET_ROOTFS_PERSIST_VAR
bool "Make /var persistent"
default n
help
Do not symlink /var to /tmp, so that its content will persist
across reboots. When enabled, /var/run will still be linked
to /tmp/run.

endmenu
5 changes: 5 additions & 0 deletions package/base-files/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ define Package/base-files/install
mkdir -p $(1)/www
mkdir -p $(1)/root
$(LN) /proc/mounts $(1)/etc/mtab
ifeq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),n)
rm -f $(1)/var
$(LN) tmp $(1)/var
else
mkdir -p $(1)/var
$(LN) /tmp/run $(1)/var/run
endif
mkdir -p $(1)/etc
$(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/

Expand Down

0 comments on commit 57807f5

Please sign in to comment.