Find file
296e644 Jan 14, 2017
509 lines (405 sloc) 17.8 KB
# Setup a Debian installation, for DietPi.
# NOTICE: Images created by non-DietPi staff, will NOT be officially supported by DietPi, unless authorized by DietPi.
# NOTICE: There is no offical support for using these script/notes. However, exceptions may be made.
# Before starting, copy the following files and folders to /boot/
# - /boot/dietpi.txt (file)
# - /boot/config.txt (file)
# - /boot/dietpi (folder)
# Legend:
# - Items that are commented out should not be used.
# - Sections with '#???', are optional, depending on the device and its specs. (eg: does it need bluetooth?)
#This is not currently a executable script. Please manually run through the commands:
exit 0 #prevent continuation of this script.
#Jessie , unified apt sources.
# - C2
# cat << _EOF_ > /etc/apt/sources.list
# deb jessie main contrib non-free
# deb jessie-updates main contrib non-free
# deb jessie/updates main contrib non-free
# deb jessie-backports main contrib non-free
# deb jessie-proposed-updates contrib non-free main
# _EOF_
# C2 stretch
# cat << _EOF_ > /etc/apt/sources.list
# deb stretch main contrib non-free
# deb stretch-updates main contrib non-free
# deb stretch/updates main contrib non-free
# deb stretch-backports main contrib non-free
# deb stretch-proposed-updates contrib non-free main
# _EOF_
# apt-get update
# apt-get install busybox-static
# apt-get upgrade -y
# apt-get dist-upgrade -y
# apt-get autoremove --purge -y
# rpi stretch
# cat << _EOF_ > /etc/apt/sources.list
# deb stretch main contrib non-free rpi
# _EOF_
# apt-get update
# apt-get upgrade -y
# apt-get dist-upgrade -y
# apt-get autoremove --purge -y
# deb-src jessie main contrib non-free
# deb-src jessie-updates main contrib non-free
# deb-src jessie/updates main contrib non-free
# deb-src jessie-backports main contrib non-free
# deb-src jessie-proposed-updates contrib non-free main
#Apt mirror will get overwritten by: /DietPi/dietpi/func/dietpi-set_software apt-mirror default : during finalize.
# - Everything else (excluding RPi!)
cat << _EOF_ > /etc/apt/sources.list
deb jessie main contrib non-free
deb jessie-updates main contrib non-free
deb jessie/updates main contrib non-free
deb jessie-backports main contrib non-free
# RPI UK mirror director is slow, unstable and unreliable -------------------------
cat << _EOF_ > /etc/apt/sources.list
deb jessie main contrib non-free rpi
# cat << _EOF_ > /etc/apt/sources.list
# deb stretch main contrib non-free rpi
# _EOF_
# #echo -e "deb stretch main ui" > /etc/apt/sources.list.d/raspi.list #Does not currently support Stretch
# RPI UK mirror director is slow, unstable and unreliable -------------------------
#+Meveric images
rm /etc/apt/sources.list.d/deb-multimedia.list
#Remove following Jessie
apt-get clean
apt-get update
apt-get purge -y libboost-iostreams* sgml-base xml-core usb-modeswitch* libpng* cpp-* cpp ntpdate bluez bluetooth rsync dialog dhcpcd5 libsqlite* libxapian22 lua5.1 netcat-* make makedev ncdu plymouth openresolv shared-mime-in* tcpd strace tasksel* wireless-* xdg-user-dirs triggerhappy python* v4l-utils traceroute xz-utils ucf xauth zlib1g-dev xml-core aptitude* avahi-daemon rsyslog logrotate man-db manpages vim vim-common vim-runtime vim-tiny mc mc-data
#+Desktop images (Mostly desktop packages, but apply to non-desktop images also):
apt-get purge -y libpod-* libpeas-* isc-dhcp-server gnome-* fonts-dejavu* eject dnsmasq* dns-root-data colord-data libturbojpeg1 libjasper* libjson* libwbclient* libwayland* golang-* libavahi* libtext* libweb* libpcsclite1 libxau6* libvpx1 libxc* dictionaries-* libgtk* miscfiles minicom lrzsz lxmenu-* x11-* zenity* yelp-*
apt-get purge -y toilet toilet-fonts w-scan vlan weather-util* sysbench stress apt-transport-* cmake cmake-data device-tree-co* fping hddtemp haveged hostapd i2c-tools iperf ir-keytable libasound2* libmtp* libusb-dev lirc lsof ncurses-term pkg-config unicode-data rfkill pv mtp-tools m4 screen alsa-utils autotools-dev bind9-host btrfs-tools bridge-utils cpufrequtils dvb-apps dtv-scan-table* evtest f3 figlet gcc gcc-4.8-* git git-man iozone3 ifenslave
#apt-get purge -y linux-jessie-root-*
#+ dev packages
apt-get purge -y '\-dev$' linux-headers*
#+ Misc
#rm /etc/apt/sources.list.d/armbian.list
rm /etc/init.d/resize2fs
systemctl daemon-reload
rm /etc/update-motd.d/*
#??? RPI
apt-get purge -y libraspberrypi-doc
#??? RPI (remove older version packages marked as manual):
apt-get purge gcc-4.6-base gcc-4.7-base gcc-4.8-base libsigc++-1.2-5c2
apt-get autoremove --purge -y
apt-get dist-upgrade -y
#install packages
echo -e "CONF_SWAPSIZE=0" > /etc/dphys-swapfile
apt-get install -y apt-transport-https ethtool p7zip-full hfsplus iw debconf-utils xz-utils fbset wpasupplicant resolvconf bc dbus bzip2 psmisc bash-completion cron whiptail sudo ntp ntfs-3g dosfstools parted hdparm pciutils usbutils zip htop wput wget fake-hwclock dphys-swapfile curl unzip ca-certificates console-setup console-data console-common keyboard-configuration wireless-tools wireless-regdb crda --no-install-recommends
#??? NanoPi Neo Air 3.x kernel only (and possibily other ap62xx chipsets), required for ap6212 bt firmware service:
apt-get install rfkill
#??? bluetooth if onboard device / RPI
apt-get install -y bluetooth
#??? RPi - bluetooth/firmware for RPi 3 (ALL)
apt-get install -y pi-bluetooth
#??? RPi - common rpi specific binaries (eg: raspistill)
apt-get install -y libraspberrypi-bin
#??? Non-ARMbian images only: firmware
apt-get install -y firmware-realtek firmware-ralink firmware-brcm80211 firmware-atheros -y --no-install-recommends
chmod +x -R /boot
#Delete any non-root user (eg: pi)
userdel -f pi
userdel -f test #armbian
#Remove folders (now in finalise script)
#Remove files
rm /etc/init.d/cpu_governor # Meveric
rm /etc/systemd/system/cpu_governor.service # Meveric
#Create DietPi common folders
mkdir /DietPi
mkdir -p /mnt/dietpi_userdata
mkdir -p /mnt/usb_1
mkdir -p /mnt/samba
mkdir -p /mnt/ftp_client
mkdir -p /mnt/nfs_client
echo -e "Samba client can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/samba/readme.txt
echo -e "FTP client mount can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/ftp_client/readme.txt
echo -e "NFS client can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/nfs_client/readme.txt
/boot/dietpi/dietpi-logclear 2
cp /boot/dietpi/conf/fstab /etc/fstab
systemctl daemon-reload
mount -a
#Setup DietPi services
# DietPi-Ramdisk
cat << _EOF_ > /etc/systemd/system/dietpi-ramdisk.service
ExecStart=/bin/bash -c '/boot/dietpi/dietpi-ramdisk 0'
ExecStop=/bin/bash -c '/DietPi/dietpi/dietpi-ramdisk 1'
systemctl enable dietpi-ramdisk.service
systemctl daemon-reload
systemctl start dietpi-ramdisk.service
# DietPi-Ramlog
cat << _EOF_ > /etc/systemd/system/dietpi-ramlog.service
Before=rsyslog.service syslog.service
ExecStart=/bin/bash -c '/boot/dietpi/dietpi-ramlog 0'
ExecStop=/bin/bash -c '/DietPi/dietpi/dietpi-ramlog 1'
systemctl enable dietpi-ramlog.service
systemctl daemon-reload
systemctl start dietpi-ramlog.service
# Boot
cat << _EOF_ > /etc/systemd/system/dietpi-boot.service
Description=DietPi-Boot networking.service dietpi-ramdisk.service dietpi-ramlog.service
ExecStart=/bin/bash -c '/DietPi/dietpi/boot'
systemctl enable dietpi-boot.service
systemctl daemon-reload
# Remove rc.local from /etc/init.d
update-rc.d -f rc.local remove
rm /etc/init.d/rc.local
rm /lib/systemd/system/rc-local.service
cat << _EOF_ > /etc/systemd/system/rc-local.service
Description=/etc/rc.local Compatibility
After=dietpi-boot.service dietpi-ramdisk.service dietpi-ramlog.service
Requires=dietpi-boot.service dietpi-ramdisk.service
systemctl enable rc-local.service
systemctl daemon-reload
cat << _EOF_ > /etc/rc.local
#Precaution: Wait for DietPi Ramdisk to finish
while [ ! -f /DietPi/.ramdisk ]
/DietPi/dietpi/func/dietpi-notify 2 "Waiting for DietPi-RAMDISK to finish mounting DietPi to RAM..."
sleep 1
echo -e "\$(cat /proc/uptime | awk '{print \$1}') Seconds" > /var/log/boottime
if (( \$(cat /DietPi/dietpi/.install_stage) == 1 )); then
/DietPi/dietpi/dietpi-services start
/DietPi/dietpi/dietpi-banner 0
echo -e " Default Login:\n Username = root\n Password = dietpi\n"
exit 0
chmod +x /etc/rc.local
systemctl daemon-reload
# Shutdown SSH/Dropbear before reboot
cat << _EOF_ > /etc/systemd/system/kill-ssh-user-sessions-before-network.service
Description=Shutdown all ssh sessions before network
ExecStart=/usr/bin/killall sshd && /usr/bin/killall dropbear
systemctl enable kill-ssh-user-sessions-before-network
systemctl daemon-reload
#Cron jobs
cp /DietPi/dietpi/conf/cron.daily_dietpi /etc/cron.daily/dietpi
chmod +x /etc/cron.daily/dietpi
cp /DietPi/dietpi/conf/cron.hourly_dietpi /etc/cron.hourly/dietpi
chmod +x /etc/cron.hourly/dietpi
cat << _EOF_ > /etc/crontab
#Please use dietpi-cron to change cron start times
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 1 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 1 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 1 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
rm /etc/cron.daily/ntp &> /dev/null
rm /etc/init.d/ntp &> /dev/null
# - Force use existing installed configs if available, else install new. Also disables end user prompt from dpkg
cat << _EOF_ > /etc/apt/apt.conf.d/local
Dpkg::Options {
#Stretch, disable automatic updates and management of apt cache. Prevents unexpected lock on Apt cache and therefore failed apt installations.
systemctl mask apt-daily.service
#/etc/sysctl.conf | Check for a previous entry before adding this
echo -e "vm.swappiness=1" >> /etc/sysctl.conf
echo -e "\n/DietPi/dietpi/login" >> /root/.bashrc
rm -R /etc/network/interfaces # armbian symlink for bulky network-manager
cp /boot/dietpi/conf/network_interfaces /etc/network/interfaces
# - enable allow-hotplug eth0 after copying.
sed -i "/allow-hotplug eth/c\allow-hotplug eth$(sed -n 1p /DietPi/dietpi/.network)" /etc/network/interfaces
#Reduce DHCP request retry count and timeouts:
sed -i '/^#timeout /d' /etc/dhcp/dhclient.conf
sed -i '/^#retry /d' /etc/dhcp/dhclient.conf
sed -i '/^timeout /d' /etc/dhcp/dhclient.conf
sed -i '/^retry /d' /etc/dhcp/dhclient.conf
cat << _EOF_ >> /etc/dhcp/dhclient.conf
timeout 10;
retry 4;
#Add ipv6 flags DietPi uses to disable IPV6 if set.
cat << _EOF_ >> /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
cat << _EOF_ > /etc/hosts localhost DietPi
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
cat << _EOF_ > /etc/hostname
#htop cfg
mkdir -p /root/.config/htop
cp /boot/dietpi/conf/htoprc /root/.config/htop/htoprc
cat << _EOF_ >> /etc/hdparm.conf
#DietPi external USB drive. Power management settings.
/dev/sda {
#10 mins
spindown_time = 120
apm = 254
cat << _EOF_ >> /etc/bash.bashrc
export \$(cat /etc/default/locale | grep LANG=)
#DietPi Additions
alias sudo='sudo ' #
alias dietpi-process_tool='/DietPi/dietpi/dietpi-process_tool'
alias dietpi-letsencrypt='/DietPi/dietpi/dietpi-letsencrypt'
alias dietpi-autostart='/DietPi/dietpi/dietpi-autostart'
alias dietpi-cron='/DietPi/dietpi/dietpi-cron'
alias dietpi-launcher='/DietPi/dietpi/dietpi-launcher'
alias dietpi-cleaner='/DietPi/dietpi/dietpi-cleaner'
alias dietpi-morsecode='/DietPi/dietpi/dietpi-morsecode'
alias dietpi-sync='/DietPi/dietpi/dietpi-sync'
alias dietpi-backup='/DietPi/dietpi/dietpi-backup'
alias dietpi-bugreport='/DietPi/dietpi/dietpi-bugreport'
alias dietpi-services='/DietPi/dietpi/dietpi-services'
alias dietpi-config='/DietPi/dietpi/dietpi-config'
alias dietpi-software='/DietPi/dietpi/dietpi-software'
alias dietpi-update='/DietPi/dietpi/dietpi-update'
alias dietpi-drive_manager='/DietPi/dietpi/dietpi-drive_manager'
alias emulationstation='/opt/retropie/supplementary/emulationstation/emulationstation'
alias opentyrian='/usr/local/games/opentyrian/run'
alias cpu='/DietPi/dietpi/dietpi-cpuinfo'
alias dietpi-logclear='/DietPi/dietpi/dietpi-logclear'
du -k --max-depth=1 | sort -nr | awk '
split("KB,MB,GB,TB", Units, ",");
u = 1;
while (\$1 >= 1024)
\$1 = \$1 / 1024;
u += 1;
\$1 = sprintf("%.1f %s", \$1, Units[u]);
print \$0;
#fakehwclock - allow times in the past
sed -i "/FORCE=/c\FORCE=force" /etc/default/fake-hwclock
#wifi dongles | move to dietpi-set_hardware wifi
# echo -e "options 8192cu rtw_power_mgnt=0" > /etc/modprobe.d/8192cu.conf
# echo -e "options 8188eu rtw_power_mgnt=0" > /etc/modprobe.d/8188eu.conf
# echo -e "options 8189es rtw_power_mgnt=0" > /etc/modprobe.d/8189es.conf
#Set swapfile size
echo -e "CONF_SWAPSIZE=0" > /etc/dphys-swapfile
#nano /etc/systemd/logind.conf
#nano /etc/default/console-setup
#Reduce gettys ACTIVE_CONSOLES="/dev/tty[1-2]"
systemctl disable getty@tty[2-6].service
#systemctl disable serial-getty@ttyS0.service
#NTPd - remove systemd's version
systemctl disable systemd-timesync
dpkg-reconfigure tzdata #Europe > London
dpkg-reconfigure keyboard-configuration #Keyboard must be plugged in for this to work!
dpkg-reconfigure locales # en_GB.UTF8 as default and only installed locale
#??? Sparky SBC ONLY: Blacklist GPU and touch screen modules:
cat << _EOF_ > /etc/modprobe.d/disable_sparkysbc_touchscreen.conf
blacklist ctp_gsl3680
cat << _EOF_ > /etc/modprobe.d/disable_sparkysbc_gpu.conf
blacklist pvrsrvkm
blacklist drm
blacklist videobuf2_vmalloc
blacklist bc_example
#??? RPI ONLY: Scroll lock fix for RPi by Midwan:
cat << _EOF_ > /etc/udev/rules.d/50-leds.rules
ACTION=="add", SUBSYSTEM=="leds", ENV{DEVPATH}=="*/input*::scrolllock", ATTR{trigger}="kbd-scrollock"
#A Unique HW_MODEL index will need to be assigned and coded into the DietPi sourcecode.
# If you are not creating a pull request for this, then:
# Email:
# Address=''
# Subject title='Unique HW_MODEL Index Request [DEVICENAME]' | Where DEVICENAME could be 'Odroid C3'
#Once you have the updated sourcecode, update the file '/DietPi/dietpi/dietpi-obtain_hw_model'
#??? Does this device have a unique HW ID index and file? check /DietPi/dietpi/dietpi-obtain_hw_model
echo ID > /etc/.dietpi_hw_model_identifier
#Finalise system
#Power off system
#Read image
#Resize 2nd parition to mininum size +50MB