this post was submitted on 30 Oct 2023
6 points (100.0% liked)

Self-Hosted Main

502 readers
1 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

For Example

We welcome posts that include suggestions for good self-hosted alternatives to popular online services, how they are better, or how they give back control of your data. Also include hints and tips for less technical readers.

Useful Lists

founded 1 year ago
MODERATORS
 

Hey fellow self-hosters!

Not directly related to self-hosting, but since it looks like quite a few people here (like me) are using Raspberry PIs to self-host stuff, I thought some people might be interested.

I use my Raspberry Pi as a NAS, and I'm using Ansible to automate the whole setup. After trying some stuff and experimenting a bit, I like to start again with a clean install and run my Ansible playbook to have a clean setup.

But I'm not always home when I do stuff with my Pi and thought it would be useful to have a way to reflash it remotely, so I could continue to break stuff and just reflash it when it gets too messy.

So I made a script to remotely reflash the Raspberry Pi. The main idea is that after flashing the SD card with the Raspi Imager, I make a copy of the bootfs and rootfs partitions, and when I need to reset the Pi to the initial state, I restore both copies of the partitions.

I wrote a step-by-step guide explaining everything:

https://gist.github.com/lilianmallardeau/04368e95bc97eb9738fba13df3bbfe4a

Feel free to use it if you like!

top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 10 months ago (1 children)

YESSS.

Thank you! This is exactly what I need. I have a bunch of random boards I am always mucking around with.

[–] [email protected] 1 points 10 months ago (1 children)

For your case, you might want to switch to overlay rootfs and mount /boot as read-only, your sd card won't get changed at all.

[–] [email protected] 1 points 10 months ago (1 children)

Please elaborate how to overlay rootfs.

[–] [email protected] 1 points 10 months ago

Configure your raspberry pi os properly, then use raspi-config to switch to overlay root filesystem. You can switch back (using raspi-config) if you want to make changes to your os.

See https://learn.adafruit.com/read-only-raspberry-pi/overview

[–] [email protected] 1 points 10 months ago
[–] [email protected] 1 points 10 months ago

This is a great idea. Regarding not ending up in an unusable state if your internet connection goes down, you could consider running the flashing steps in a background subshell with nohup or similar. Or double-fork the shell.

[–] [email protected] 1 points 10 months ago

Great!

It would even be easier to get the DISK_ID directly in the script, at its beginning (but after the check about being root):

DISK_ID=$(sfdisk --disk-id /dev/mmcblk0)