# Persistent /var

**URL:** <https://forum.openwrt.org/t/persistent-var/119427>\
**Category:** Installing and Using OpenWrt\
**Created:** [February 6, 2022, 12:55am UTC](https://forum.openwrt.org/t/persistent-var/119427 "2022-02-06T00:55:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carbolymer](https://forum.openwrt.org/user_avatar/forum.openwrt.org/carbolymer/32/25250_2.png) [@carbolymer](https://forum.openwrt.org/u/carbolymer)\
**Post date:** [February 6, 2022, 12:55am UTC](https://forum.openwrt.org/t/persistent-var/119427/1 "2022-02-06T00:55:45Z")

</div>

I have configured usb external storage using extroot, and I'd like to have persistent `/var` directory. I've tried adding entry to /etc/config/fstab and replacing symlink with regular directory but this results in my router being softbricked.

How can I replace `/var` with regular directory or a mount?

---

<div class="post-metadata">

**Author:** ![slh](https://forum.openwrt.org/user_avatar/forum.openwrt.org/slh/32/113591_2.png) [@slh](https://forum.openwrt.org/u/slh)\
**Post date:** [February 6, 2022, 1:01am UTC](https://forum.openwrt.org/t/persistent-var/119427/2 "2022-02-06T01:01:29Z")

</div>

That is a build-time decision:

> <https://github.com/openwrt/openwrt/commit/57807f50ded6cf0996284a850084183af13d5894>
>
> In OpenWrt, /var is symlinked to /tmp by default. This is done to reduce
> the amo…unt 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\>

---

<div class="post-metadata">

**Author:** ![pmisch](https://forum.openwrt.org/user_avatar/forum.openwrt.org/pmisch/32/127705_2.png) [@pmisch](https://forum.openwrt.org/u/pmisch)\
**Post date:** [November 20, 2023, 9:02pm UTC](https://forum.openwrt.org/t/persistent-var/119427/3 "2023-11-20T21:02:52Z")

</div>

I build an x86 image with `TARGET_ROOTFS_PERSIST_VAR` set to `y` but still the /var partition is reset every reboot.  
I'm running an pc-engines apu4d4 with a USB flash drive.  
Could someone please point me into the right direction.

---

<div class="post-metadata">

**Author:** ![sn0wbl1nd](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sn0wbl1nd/32/87863_2.png) [@sn0wbl1nd](https://forum.openwrt.org/u/sn0wbl1nd)\
**Post date:** [August 31, 2024, 4:15am UTC](https://forum.openwrt.org/t/persistent-var/119427/4 "2024-08-31T04:15:57Z")

</div>

Are you building using the image builder? I may be having the same problem. When building the image directly /var is a directory, but with the image builder it is always a symbolic link.

---

<div class="post-metadata">

**Author:** ![pmisch](https://forum.openwrt.org/user_avatar/forum.openwrt.org/pmisch/32/127705_2.png) [@pmisch](https://forum.openwrt.org/u/pmisch)\
**Post date:** [September 16, 2024, 8:35pm UTC](https://forum.openwrt.org/t/persistent-var/119427/5 "2024-09-16T20:35:28Z")

</div>

I gave up on trying, it seemed to cumbersome to handle this.  
Someone somewhere once pointed out that this might be fixable by just defining where the runtime like podman or docker stores its data and putting this path onto a bigger + persistant + writeable storage.
