Install pihole on an external usb stick

Please follow the below template, it will help us to help you!

Expected Behaviour:

I want to run raspberry pi in read only mode so that I can extend the life of the sdcard.
is there a way to install pihole onto an external usb stick so that when it does it's updates on the ads filtering on the stick and not on the card?

Actual Behaviour:

Debug Token:

This is easy to achieve, but I honestly would not recommend it.

Prior to installing Pi-hole, you could re-partition a USB drive to two partitions (Given that these files run at elevated privilege, these partitions should be formatted in a file-system that fully supports setting file mode, ie not fat32, but ext4 suits the job). Then after add entries to /etc/fstab to mount these two partitions at /etc/pihole and /etc/.pihole reboot and install Pi-hole as normal.

This does not cover all of the files that Pi-hole installs (it does not cover the scripts or binaries installed in /usr/bin for example), but it does include those more likey to be updated and over-written, such the blocklists and so forth.

If done this way, your USB drive must be present at boot from then on in, and if it were to fail, the results would not be pretty (ranging from loss of internet connectivity, to complete failure to boot).

If you are using a reputable brand and a decent size card, the life of the SD card will be much greater than you should ever need. If you use an off-brand card, they typically are lower quality and don't have good wear-leveling built into the controller. Additionally, if you use a small card, you end up reading and writing the same parts of the card frequently.

I use the SanDisk Ultra 32 GB cards on my Pi's, less than $11 at Amazon. At that price, buy two and use one to clone your primary card periodically. If the primary card fails, toss in the backup. Or, once every few years, clone your card and replace with a new one as a pre-emptive measure. Even swapping out the card every year (this is way conservative) costs you less than $1/month.

That's a cheaper and easier solution than adding on a stick (which typically doesn't have either the performance or wear leveling of a good microSD card.

https://www.amazon.com/gp/product/B073JWXGNT/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

1 Like

I basically want to put the hole directory structure that pihole on an ext4 formatted USB stick, and putting the microSD card into read only mode.
I intend to push the $/month as low as possible. And when the USB fails I don't need to setup a new is or anything. I just need to swap out the USB stick.

I see what you want to do, I just don't think your fear of an impending SD failure from wear is warranted. You can make this work on a USB stick, but it will be a pain in the rear and may or may not be reliable. I think you have a solution looking for a problem.

Plus, if your SD card is in read-only mode, how will you install system and PiHole updates? You'll want to keep them up to date.

What size and brand SD card are you running?

1 Like

No, actually it is a problem looking for a solution. I started off at looking at the sourcecode of pihole and judging from interpretation pihole does periodic updates / downloads, especially when starting up.
I immediately ran into problems when booting raspbian as read-only.
So if I could outsource at least all the paths that pihole writes to, I'd have a better chance at booting raspbian without pihole giving me problems.
I'm using an 8GB intenso SDcard

If this is the path you wish to pursue, then I think following Robgill's advice is your best course.

As a user on one of the threads linked below noted, if you disable query logging on your PiHole you eliminate the vast majority of write cycles, since it's not updating the log constantly. That might be an option to consider.

Typically SD card corruption on a Pi comes from sudden power loss, not from card failure. These threads have some additional information.

https://www.reddit.com/r/pihole/comments/64yewc/pi_hole_sd_card_wear/

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.