You are here

Reinstalling Raspberry Pi

Submitted by egbert on Thu, 27/12/2018 - 11:47
Raspberry Pi file and ftp server

Today is the day to reinstall my raspberry pi which acts as:
ftp server
samba server
forked-daapd server for my flac collection
network bridge for my upstairs room

This particular pi has a "Segmentation Fault" when issuing certain commands like "sudo su" or "apt" commands. My guess is that the SD Card is corrupted, I know this from previous problems I had with this raspberry pi.

So I made backups of all important stuff like config files etc.. Let's see how it goes!

Reinstall the basic Pi

  1. Download the Raspbian image from Raspberry Pi website downloadpage.
  2. Burn the downloaded zip file to the SD Card. I use ApplePiBaker for this, good shit for baking your pi images :)
  3. Copy an empty file named "ssh" to the root of the SD card. This is done so we do not need an external monitor for configuring the pi.
  4. Use NMAP to find the new PI on your network:
    F.e. nmap 10.0.1.0/24
  5. Update the pi sudo apt-get update and sudo apt-get dist-upgrade
  6. Reboot

Restoring stuff

Step 1 - Restore Networking

- Restore ip configuration for wifi and local ether
- Restore the raspberry bridge function
- Restore the DHCP configuration

First step is to edit the hostfile /etc/hosts to set the pi's hostname, in this case "teladrop"
Step two - edit the /etc/dhcpcd.conf and add:
# 20180614 added for bridge function by Egbert - see https://pimylifeup.com/raspberry-pi-wifi-bridge/
interface eth0
static ip_address=192.168.220.1/24
static routers=192.168.220.0

Next I configured the wireless interface through sudo raspi-config.

I copied back settings from the backup of /etc/dnsmasq.conf into that file on the new pi:
interface=eth0 # Use interface eth0
listen-address=192.168.220.1 # Specify the address to listen on
bind-interfaces # Bind to the interface
server=10.0.1.7 # Use Google DNS
domain-needed # Don't forward short names
bogus-priv # Drop the non-routed address spaces.
dhcp-range=192.168.220.50,192.168.220.150,12h # IP range and lease time

I read up via Easy Raspberry Pi Bridge to get the bridge working again. I really wouldn't know that all by head..

Put the pi back into its place and connected the pendrives, the external harddrive, and the ethernetcable to my PowerMac. Booted up and networking is running fine!

Step 2 - restore Samba configuration

Step 1 - restore fstab settings:
I checked the external disks UID's with sudo blkid to make sure they are correct, they are..
I installed samba and needed disk stuff:
sudo apt-get install samba samba-common-bin
sudo apt-get install ntfs-3g
I copied over the settings from my backup of /etc/samba/smb.conf file to the new pi
Create the Pi samba user:
sudo smbpasswd -a pi
Created the share directories in /Volumes
Made the pi user owner of this directory
sudo chown -R pi:pi /Volumes

That worked out nicely. Now up to

Step 3 - Reinstall and configure Forked-daapd

First, install avahi-daemon:
sudo apt-get install avahi-daemon
Next add the source for forked-daapd to the /etc/apt/sources.list
deb http://www.gyfgafguf.dk/raspbian/forked-daapd/ stretch contrib
sudo apt-get update
sudo apt-install forked-daapd
I then copied back the /etc/forked-daapd.conf file from my backup and forked-daapd and rebooted the system.

Step 4 - Reinstall ProFTPD server

I use an FTP server for my On Song workflow. The reason for that is that I don't want to use Dropbox or another commercial file sharing solution. I like FTP a lot because it is so simple.

First install ProFTPD sudo apt-get install proftpd

Create the FTP User

So I made the FTP user with the /bin/false shell and stuff according to the instructions here: HOWTO: Create a FTP server with user access.

I copied over the /etc/proftpd/proftpd.conf file from my backup and restarted proftpd sudo service proftpd restart. It's running just fine!

Step 5 - Reinstall Backup my Pi script

I use this to backup my Pi's SD Card. First install gitL
sudo apt-get install git.
Next clone the repository:
cd ~
git clone https://github.com/lzkelley/bkup_rpimage.git
Now i can run an initial backup so next time I have to reinstall this pi I can simply restore the image created by this script:
sudo sh bkup_rpimage.sh start -c /Volumes/TELADROP-PENDRIVE/teladrop_backup/rpi_backup.img

I will use this image as the default rescue image for this Pi.

Things to do better next time

  1. Make a backup of the pi user crontab file
  2. Create a definitive backup of data files
  3. Backup webserver directories

Sources:
Create FTP server with user access (ProFTPD)
How to backup your Raspberry Pi SD Card