|
#!/bin/sh |
|
############################################################################## |
|
# OpenMediaVault: USB Write Minimalisation Support (Post Install Command) |
|
############################################################################## |
|
|
|
############################################################################## |
|
# Functions |
|
|
|
omv_sed() { |
|
sed -i -r "$@" |
|
} |
|
|
|
omv_apt_get() { |
|
apt-get --allow-unauthenticated --assume-yes --no-install-recommends $* |
|
} |
|
|
|
omv_preseed() { |
|
seed=`mktemp --suffix=.seed /tmp/XXXXXXXX` |
|
echo "${*}" > "${seed}" |
|
debconf-set-selections "${seed}" |
|
rm -f "${seed}" |
|
} |
|
|
|
############################################################################## |
|
# Tweaks |
|
|
|
# Set some kernel parameters to reduce writes to the drive: |
|
cat >> /etc/sysctl.d/99-openmediavault.conf <<-'EOF' |
|
|
|
# Additional optimisations to reduce I/O on flash media: |
|
vm.dirty_writeback_centisecs = 12000 |
|
vm.dirty_expire_centisecs = 12000 |
|
vm.dirty_ratio = 10 |
|
vm.dirty_background_ratio = 1 |
|
vm.laptop_mode = 0 |
|
vm.swappiness = 0 |
|
vm.vfs_cache_pressure = 50 |
|
EOF |
|
|
|
# Use the 'noop' scheduler for flash drive: |
|
omv_sed '/exit 0/d' /etc/rc.local |
|
cat >> /etc/rc.local <<-'EOF' |
|
# Use a better scheduler for our root flash drive... |
|
device=`readlink -n /dev/root | sed 's|[0-9]||g'` |
|
echo noop > "/sys/block/${device}/queue/scheduler" |
|
|
|
exit 0 |
|
EOF |
|
|
|
# Force delayed write for all log files written by syslog daemon: |
|
omv_sed 's|\t(/var/log)|\t-\1|' /etc/rsyslog.conf |
|
|
|
# Fix for collectd 'value too old' rootfs issue spamming logs: |
|
output='/etc/collectd/collectd.conf' |
|
omv_sed '/^<Plugin df>/{n;d}' ${output} |
|
omv_sed '/^<Plugin df>/s/$/\n IgnoreSelected true/' ${output} |
|
omv_sed '/^<Plugin df>/s/$/\n FSType rootfs/' ${output} |
|
|
|
# Fix for broken mdadm --monitor --scan service on boot: |
|
cat >> /etc/mdadm/mdadm.conf <<-'EOF' |
|
|
|
# Configure a default mail address: |
|
MAILADDR root |
|
EOF |
|
|
|
# Disable the bash history: |
|
cat >> /root/.bashrc <<-'EOF' |
|
|
|
# Some options to reduce writes to flash drive: |
|
unset HISTFILE HISTFILESIZE HISTSIZE |
|
EOF |
|
|
|
# Fix issue starting the web administration interface with flashybrid: |
|
output='/etc/apache2/mods-enabled/fcgid.conf' |
|
omv_sed '/^<\/IfModule>/s/^/ FcgidIPCDir \/var\/run\/apache2\/fcgidsock\n/' ${output} |
|
omv_sed '/^<\/IfModule>/s/^/ FcgidProcessTableFile \/var\/run\/apache2\/fcgid_shm\n/' ${output} |
|
|
|
############################################################################## |
|
# Flashybrid |
|
|
|
# Install and enable flashybrid: |
|
omv_preseed 'flashybrid flashybrid/remove note' |
|
omv_apt_get install flashybrid |
|
|
|
# Enable the flashybrid service: |
|
echo 'ENABLED=yes' > /etc/default/flashybrid |
|
|
|
# Create directory for mounting temporary filesystems: |
|
mkdir /ram |
|
|
|
# Increase the amount of memory to use for temporary filesystems: |
|
omv_sed '/^FLASH_MAX/s/=.*/=512m/' /etc/flashybrid/config |
|
|
|
# Fix errors in flashybrid configuration files: |
|
omv_sed '/^\/tmp$/d' /etc/flashybrid/ramtmp |
|
omv_sed '/^\/var\/lib\/alsa$/d' /etc/flashybrid/ramtmp |
|
omv_sed '/^\/var\/lib\/apache$/s/$/2/' /etc/flashybrid/ramtmp |
|
|
|
# Fix some dependency issues in the flashybrid initscript: |
|
output='/etc/init.d/flashybrid' |
|
omv_sed '/^# Required-(Start|Stop):/s/\$[_a-z]+/$local_fs/' ${output} |
|
omv_sed '/^# Default-Start:/s/(:\s+).*/\1S/' ${output} |
|
omv_sed '/^# Default-Stop:/s/(:\s+).*/\10 6/' ${output} |
|
omv_sed '/^# Short-Description:/s/^/# X-Start-Before: $network $syslog resolvconf\n/' ${output} |
|
omv_sed '/^# Short-Description:/s/^/# X-Stop-After: $network $syslog resolvconf\n/' ${output} |
|
insserv --remove flashybrid |
|
insserv flashybrid |
|
|
|
# Add some additional flashybrid rules for OpenMediaVault: |
|
cat >> /etc/flashybrid/ramstore <<-'EOF' |
|
|
|
# Additional paths for OpenMediaVault: |
|
/var/backups |
|
/var/cache |
|
/var/lib/apt |
|
/var/lib/collectd |
|
/var/lib/cron-apt |
|
/var/lib/defoma |
|
/var/lib/dpkg |
|
/var/lib/initramfs-tools |
|
/var/lib/initscripts |
|
/var/lib/innserv |
|
/var/lib/libuuid |
|
/var/lib/logrotate |
|
/var/lib/mdadm |
|
/var/lib/misc |
|
/var/lib/monit |
|
/var/lib/nfs |
|
/var/lib/openmediavault |
|
/var/lib/pam |
|
/var/lib/postfix |
|
/var/lib/quota |
|
/var/lib/samba |
|
/var/lib/smartmontools |
|
/var/lib/snmp |
|
/var/lib/sudo |
|
/var/lib/ucf |
|
/var/lib/update-rc.d |
|
/var/lib/usbutils |
|
/var/www |
|
EOF |
|
|
|
# Add an hourly cron task to sync from /ram: |
|
cat > /etc/cron.hourly/flashybrid-sync <<-'EOF' |
|
#!/bin/sh |
|
|
|
# Force synchronisation of paths managed by flashybrid: |
|
/sbin/fh-sync > /dev/null 2>&1 |
|
|
|
# Force the changes to be written to disk: |
|
sync |
|
EOF |
|
|
|
############################################################################## |
|
# vim:et:ft=sh:nowrap:sts=4:sw=4:ts=4 |