Introduction
I sometimes have issues with a corrupted sd card (in raspberry PI). Occasionally after an update of domoticz the machine does not restart. I do create an image of the SD card on daily basis, so I'm always up-and running quite fast. But it takes an hour or so...
Yesterdat I started installing a Domoticz slave PI system and do not want the same issues... so googled on getting the pi running from a network share and found info in this location
For my own reference
HowTo setup NFS share on Synology nas
Open the DSM interface as administrator
- Open the control panel
- Open 'Shared folder'
- Click create button
- Fill share name and description, for this example I use 'PISlaveTest'
- In the next window you can give rights to nas users (for samba/windows network access)
- Click NFS permissions
- Click create
- Fill the hostname/IP with your raspberries IP or your network range, for example 192.168.1.* (to give all devices in your local network access)
- Ready, NFS share is available now (also as samba/windows network share)
Start with a running Domoticz system. MAKE A BACKUP(!), you can make your PI unbootable (use something like win32diskimager on a windows system)
Mount (connect to) the NFS share
- Enable RCPBind: "sudo update-rc.d rpcbind enable"
- Mount the NFS share: "sudo mount 192.168.1.2:/volume1/PISlaveTest /mnt" (where 192.168.1.2 is the IP of my NAS, 'volume1' is the disk volume in my nas and 'PISlaveTest' is the share name
- sudo cp -axv /. /mnt/.
- sudo cp -axv /dev/. /mnt/dev/.
- sudo nano /mnt/etc/fstab
- Delete the line which mounts /dev/mmcblk0p2 on / or comment it out (#).
- sudo nano /boot/cmdline.txt and copy the following:
- dwc_otg.lpm_enable=0 console=tty1 root=/dev/nfs rootfstype=nfs elevator=deadline rootwait nfsroot=192.168.1.2:/volume1/PISlaveTest,udp,vers=3 smsc95xx.turbo_mode=N ip=192.168.1.7:192.168.1.2:192.168.1.1:255.255.255.0:PISlaveTest:eth0:off
(where .7 is the IP of domoticz (using static IP, as already configured before on PI, this might totally replace that config), .2 is the NAS, .1 is the gateway)
Move your swap partition to NFS share
First clean the old swap
- sudo apt-get remove --purge dphys-swapfile
- sudo rm /var/swap
- sudo rm /etc/init.d/dphys-swapfile
- sudo update-rc.d dphys-swapfile remove
- the first step will create an 1gb file, will take some time...
- sudo dd if=/dev/zero of=/var/swap bs=1M count=1024
- sudo losetup /dev/loop0 /var/swap
- sudo mkswap /dev/loop0
- sudo swapon /dev/loop0
To make these changes permanent, edit the /etc/rc.local file and add the following before exit 0 .
echo "Setting up loopy/var/swap.."
sleep 2
losetup /dev/loop0 /var/swap
mkswap /dev/loop0
swapon /dev/loop0
There you have it, your network swap file will be active on boot now.
Here’s a couple of tweaks to system files to do some fine tuning. First, edit /etc/default/rcS and add 'ASYNCMOUNTNFS=no'.
Now edit /etc/sysctl.conf and add or change 'vm.min_free_kbytes = 16384' This will set aside 16MB of free RAM to prevent the risk of a kernel panic. You may set this value lower if you wish, but on a 512MB Pi it’s not a huge concern.
Good luck!
I will execute this setup in a few weeks when this system keeps running fine (it did for 24 hours now)