Pihole db on usb disk

Hi,

I’m trying to move the pihole database from standard location (/etc/pihole/pihole-FTL.db) to external usb disk (/data/pihole/pihole-FTL.db), where /data is the mount point accordig to my fstab

LABEL=data	/data	auto	defaults,noatime,nofail    0 0



ll /data/pihole/pihole-FTL.db
-rw-r--r-- 1 pihole pihole 28K apr  5 12:45 /data/pihole/pihole-FTL.db

During boot process I see in /var/log/pihole-FTL.log

[2018-04-05 12:36:11.108] Starting config file parsing (/etc/pihole/pihole-FTL.conf)
[2018-04-05 12:36:11.110]    SOCKET_LISTENING: only local
[2018-04-05 12:36:11.110]    QUERY_DISPLAY: Show queries
[2018-04-05 12:36:11.110]    AAAA_QUERY_ANALYSIS: Hide AAAA queries
[2018-04-05 12:36:11.110]    MAXDBDAYS: max age for stored queries is 365 days
[2018-04-05 12:36:11.110]    RESOLVE_IPV6: Don't resolve IPv6 addresses
[2018-04-05 12:36:11.110]    RESOLVE_IPV4: Resolve IPv4 addresses
[2018-04-05 12:36:11.110]    DBINTERVAL: saving to DB file every 300 seconds
[2018-04-05 12:36:11.110]    DBFILE: Using /data/pihole/pihole-FTL.db
[2018-04-05 12:36:11.110]    MAXLOGAGE: Importing up to 24.0 hours of log data
[2018-04-05 12:36:11.110] Finished config file parsing
[2018-04-05 12:36:11.113] Found no other running pihole-FTL process
[2018-04-05 12:36:11.114] PID of FTL process: 343
[2018-04-05 12:36:12.455] Gravity list entries: 561209
[2018-04-05 12:36:12.455] No blacklist present
[2018-04-05 12:36:12.455] No wildcard blocking list present
[2018-04-05 12:36:12.487] db_init() - Cannot open database (14): unable to open database file
[2018-04-05 12:36:12.487] Creating new (empty) database
[2018-04-05 12:36:12.487] db_create() - SQL error (14): unable to open database file
[2018-04-05 12:36:12.487] Database not available

As you can see the line “db_init() - Cannot open database (14): unable to open database file” is quite explicative.

If I restart the pihole-FTL service, then the db is correctly open:

[2018-04-05 12:37:16.467] Starting config file parsing (/etc/pihole/pihole-FTL.conf)
[2018-04-05 12:37:16.467]    SOCKET_LISTENING: only local
[2018-04-05 12:37:16.467]    QUERY_DISPLAY: Show queries
[2018-04-05 12:37:16.467]    AAAA_QUERY_ANALYSIS: Hide AAAA queries
[2018-04-05 12:37:16.467]    MAXDBDAYS: max age for stored queries is 365 days
[2018-04-05 12:37:16.467]    RESOLVE_IPV6: Don't resolve IPv6 addresses
[2018-04-05 12:37:16.467]    RESOLVE_IPV4: Resolve IPv4 addresses
[2018-04-05 12:37:16.467]    DBINTERVAL: saving to DB file every 300 seconds
[2018-04-05 12:37:16.467]    DBFILE: Using /data/pihole/pihole-FTL.db
[2018-04-05 12:37:16.467]    MAXLOGAGE: Importing up to 24.0 hours of log data
[2018-04-05 12:37:16.467] Finished config file parsing
[2018-04-05 12:37:16.470] Found no other running pihole-FTL process
[2018-04-05 12:37:16.471] PID of FTL process: 2321
[2018-04-05 12:37:17.480] Gravity list entries: 561209
[2018-04-05 12:37:17.480] No blacklist present
[2018-04-05 12:37:17.480] No wildcard blocking list present
[2018-04-05 12:37:17.520] Database initialized

It makes me think that at boot time, the service starts before the disk is mounted. Right? Is there a way to change the order of services?

I’m on a PI3 with version 6.6.

Thanks a lot.

I confirm that usb disk is not mounted when pihole starts.

In /etc/init.d/pihole-FTL I’ve add the following code:

su -s /bin/sh -c "/bin/df -h  2>&1 > /etc/pihole/debug.log" pihole

before

su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER"

And /data in not present:

/dev/root        15G  1,8G     13G  13% /
devtmpfs        484M     0    484M   0% /dev
tmpfs           489M     0    489M   0% /dev/shm
tmpfs           489M   13M    476M   3% /run
tmpfs           5,0M     0    5,0M   0% /run/lock
tmpfs           489M     0    489M   0% /sys/fs/cgroup
tmpfs          1023M     0   1023M   0% /tmp
tmpfs            10M  1,5M    8,6M  15% /DietPi
tmpfs            20M   60K     20M   1% /var/log
/dev/mmcblk0p1   42M   23M     19M  56% /boot

Partially solved with a dirty hack, added

sleep 30

before

su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER"

I am not at all satisfied with this solution for several reasons. In a next update there is a good chance that the file /etc/init.d/pihole-FTL will be overwritten. There are probably better ways to wait for the usb drive to be properly mounted, but my knowledge of systemd is still basic.

A little mod to speed up boot:

while [ ! -d /data/pihole ] ; do
        sleep 1
done

systemd-analyze critical-chain

graphical.target @7.887s
└─multi-user.target @7.887s
  └─pihole-FTL.service @1.460s +6.426s
    └─basic.target @1.457s
      └─sysinit.target @1.438s
        └─systemd-update-utmp.service @1.390s +46ms
          └─systemd-tmpfiles-setup.service @1.351s +36ms
            └─local-fs.target @1.349s
              └─boot.mount @1.288s +59ms
                └─dev-disk-by\x2dpartuuid-27504eef\x2d01.device @1.281s