This describes how you could configure your Raspberry PI to work, hopefully, better with Codesys.
- Based on raspbian image
These instructions are based on...
- http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=61033
- https://extremeshok.com/1081/raspberry-pi-raspbian-tuning-optimising-optimizing-for-reduced-memory-usage/
- http://forum.codesys.com/viewtopic.php?f=21&t=5890
- http://blog.pi3g.com/2014/04/make-raspbian-system-read-only/
raspi-config
- Expand filesystem (can skip this step if extra partitions needed)
- I18N -> Locales, Timezone, keyboard.
- Advanced Options -> Memory Split -> give 16MB to GPU
- Overclock -> Modest, 800Mhz
Finish and reboot
#update to a fresh install
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get -y purge libx11-6 libgtk-3-common xkb-data lxde-icon-theme \
raspberrypi-artwork penguinspuzzle wolfram-engine
sudo apt-get -y autoremove
sudo rpi-update
sudo reboot
sudo dphys-swapfile swapoff && sudo dphys-swapfile uninstall && sudo update-rc.d dphys-swapfile remove
Change elevator from deadline to noop sudo nano /boot/cmdline.txt elevator=noop #sets the Network device not in turbo mode. turns off buffering network traffic smsc95xx.turbo_mode=N
(ctrl-x Save exit)
Since the filesystem will be read-only. DHCP will have issues updating resolv.conf Switch DNS resolve to Google Server (So packages will not update)
sudo apt-get install resolvconf
sudo nano /etc/resolvconf/resolv.conf.d/base
nameserver 8.8.8.8
nameserver 8.8.4.4
(ctrl-x Save exit)
Set the CPU scaling governor to performance
sudo echo -n performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
sudo nano /etc/default/rcS
# automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes
(ctrl-x Save exit)
Scan every 3 reboots
sudo tune2fs -c 3 /dev/mmcblk0p2
sudo su
apt-get -y remove --purge rsyslog
apt-get -y install inetutils-syslogd
echo -e "*.*;mail.none;cron.none\t -/var/log/messages\ncron.*\t -/var/log/cron\nmail.*\t -/var/log/mail" > /etc/syslog.conf
mkdir -p /etc/logrotate.d
echo -e "/var/log/cron\n/var/log/mail\n/var/log/messages {\n\trotate 4\n\tweekly\n\tmissingok\n\tnotifempty\n\tcompress\n\tsharedscripts\n\tpostrotate\n\t/etc/init.d/inetutils-syslogd reload >/dev/null\n\tendscript\n}" > /etc/logrotate.d/inetutils-syslogd
service inetutils-syslogd start
exit
echo "net.ipv6.conf.all.disable_ipv6=1" >> /etc/sysctl.d/disableipv6.conf
echo "install ipv6 /bin/true" >> /etc/modprobe.d/blacklist.conf
echo "install ipv6 /bin/true" >> /etc/modprobe.d/raspi-blacklist.conf
sudo sed -i '/::/s%^%#%g' /etc/hosts
sudo apt-get -y install dropbear openssh-client
sudo sed -i 's/NO_START=1/NO_START=0/g' /etc/default/dropbear
sudo /etc/init.d/ssh stop && sudo /etc/init.d/dropbear start
sudo apt-get purge openssh-server
Remove the extra tty / getty’s | Save: +3.5 MB RAM
sudo sed -i '/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g' /etc/inittab
sudo sed -i '/T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100/s%^%#%g' /etc/inittab
sudo dpkg-reconfigure dash
Assign network names based on location so image can boot on different PI
sudo nano /etc/udev/rules.d/70-persistent-net.rules
KERNEL=="eth*", KERNELS=="1-1.1", NAME="eth0"
KERNEL=="eth*", KERNELS=="1-1.[2-3]", NAME="eth1"
(ctrl-x Save exit)
(http://rpi.tnet.com/project/faqs/winaccessinterfacesfile)
sudo cd /etc/network
sudo cp interfaces /boot/interfaces
sudo mv interfaces interfaces.save
sudo ln -s /boot/interfaces interfaces
Setup enable second network interface to have DHCP
sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
(ctrl-x Save exit)
Optionally remove NTP from service so it does not interruppt Network Another way to disable NTP (http://windycitytech.blogspot.com/2013/03/disable-ntp-sending-out-requests-on.html)
sudo update-rc.d -f ntp remove
sudo nano /etc/sysctl.conf
fs.file-max = 150000
vm.min_free_kbytes = 16384
vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 1200
vm.overcommit_ratio = 2
vm.laptop_mode = 5
vm.swappiness = 10
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.core.rmem_default = 31457280
net.core.rmem_max = 12582912
net.core.wmem_default = 31457280
net.core.wmem_max = 12582912
net.core.somaxconn = 65536
net.core.netdev_max_backlog = 65536
net.core.optmem_max = 25165824
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144
net.ipv4.tcp_rmem = 8192 87380 16777216
net.ipv4.udp_rmem_min = 16384
net.ipv4.tcp_wmem = 8192 65536 16777216
net.ipv4.udp_wmem_min = 16384
(ctrl-x Save exit)
##Fix fstab
Add noatime to all, mount /var/run and other fast burning partitions to tmpfs (except /var/log). Mount /boot in ro mode sudo nano /etc/fstab
proc /proc proc defaults 0 0
none /var/run tmpfs size=1M,noatime 0 0
none /tmp tmpfs size=1M,noatime 0 0
none /var/tmp tmpfs size=1M,noatime 0 0
/dev/mmcblk0p1 /boot vfat noatime 0 2
/dev/mmcblk0p2 / ext4 ro,defaults,noatime 0 1
(ctrl-x Save exit)
sudo sed -i 's/defaults,noatime/defaults,noatime,nodiratime/g' /etc/fstab
Read more at http://abel-it.co.uk/pi/ramlog.html or http://www.xappsoftware.com/wordpress/2013/06/10/two-tricks-to-make-your-raspberry-pi-more-reliable/
It's basically a ram cashed /var/log that gets written to flash on intervals to save the SD card.
wget https://raw.github.com/swirepe/personalscripts/master/pi/ramlog_2.0.0_all.deb
sudo dpkg -i ramlog_2.0.0_all.deb
Edit /etc/init.d/ramlog and add the -After and -Before lines
### BEGIN INIT INFO
# Provides: ramlog
# Required-Start:
# X-Start-Before: inetutils-syslogd
# X-Stop-After: inetutils-syslogd
Set this up
sudo insserv
sudo cat /dev/null > ~/.bash_history && history -c
##Reboot to have all setting take effect sudo reboot
sudo mount -o remount,rw /
sudo dd bs=4M if=/dev/sdb | gzip > date +%Y-%m-%d
-raspbian-ro.img.gz