Skip to content

Commit

Permalink
v8.3
Browse files Browse the repository at this point in the history
- DietPi-Build | Reduce image size and assure that "iproute2" is installed on containers
- DietPi-Software | Do not install CPU microcode packages and skip time sync setup on containers
- DietPi-Set_hardware | Pre-create /etc/modprobe.d, if required but missing; Remove legacy kernel and unsupported SBC kernel module handling
- DietPi-PREP | Assure "iproute2" is installed on container images but do not enable serial consoles and do not touch Bluetooth on them
- DietPi-FirstBoot | Reorder steps so that keyboard, SSH and network setup can be skipped on container images
- General | Check for container "hardware" ID whenever asking systems whether it is a container in conditionals, and replace systemd-detect-virt with the lighter /proc/1/environ parsing for "container" variable
- DietPi-TimeSync | Skip time sync on container systems and if any image is run as container
  • Loading branch information
MichaIng committed Mar 25, 2022
1 parent f2cb574 commit 78ba121
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 90 deletions.
6 changes: 3 additions & 3 deletions .build/images/dietpi-build
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ case $HW_MODEL in
16) iname='OdroidC4' HW_ARCH=3 partition_start=4 root_size=764;;
20) iname='VM' WIFI_REQUIRED=0 HW_ARCH=${HW_ARCH:-10} VMTYPE=${VMTYPE:-raw};;
21) iname='NativePC-BIOS' HW_ARCH=10 root_size=1215;;
75) iname='Container' root_size=511;;
75) iname='Container' root_size=383;;
*) G_DIETPI-NOTIFY 1 "Invalid hardware model \"$HW_MODEL\" passed, aborting..."; exit 1;;
esac

Expand Down Expand Up @@ -262,8 +262,8 @@ fi
##########################################
# debootstrap
##########################################
packages='apt,bash-completion,bzip2,ca-certificates,cron,curl,fdisk,gnupg,htop,iputils-ping,locales,nano,p7zip,parted,procps,psmisc,sudo,systemd-sysv,tzdata,udev,unzip,wget,whiptail'
(( $HW_MODEL == 75 )) || packages+=',console-setup,ethtool,fake-hwclock,ifupdown,isc-dhcp-client,kmod,rfkill,systemd-timesyncd,usbutils'
packages='apt,bash-completion,bzip2,ca-certificates,cron,curl,fdisk,gnupg,htop,iputils-ping,locales,nano,p7zip,parted,procps,psmisc,sudo,systemd-sysv,tzdata,udev,unzip,wget,whiptail,'
(( $HW_MODEL == 75 )) && packages+='iproute2' || packages+='console-setup,ethtool,fake-hwclock,ifupdown,isc-dhcp-client,kmod,rfkill,systemd-timesyncd,usbutils'
G_EXEC_OUTPUT=1 G_EXEC debootstrap --variant=minbase --exclude="gcc-7-base,gcc-8-base,gcc-9-base$exclude" --include="$packages" --arch="$parch" --keyring="$keyring" "$distro" ./rootfs "$repo"

# Remove cached archives and list files created by debootstrap
Expand Down
41 changes: 21 additions & 20 deletions PREP_SYSTEM_FOR_DIETPI.sh
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,11 @@ _EOF_
done < <(blkid -s TYPE -o value -c /dev/null | sort -u)

# G_HW_MODEL specific
# - All but containers
if (( $G_HW_MODEL != 75 ))
# - Containers
if (( $G_HW_MODEL == 75 ))
then
aPACKAGES_REQUIRED_INSTALL+=('iproute2')
else
aPACKAGES_REQUIRED_INSTALL+=(
'console-setup' # DietPi-Config keyboard configuration + console fonts
'ethtool' # Force Ethernet link speed
Expand Down Expand Up @@ -1485,15 +1487,12 @@ _EOF_'
then
/boot/dietpi/func/dietpi-set_hardware serialconsole enable ttyS0

# Else on non-VM: Enable on all present serial consoles
elif (( $G_HW_MODEL != 20 ))
# Else for physical systems: Enable on all present serial consoles
elif (( $G_HW_MODEL != 20 && $G_HW_MODEL != 75 ))
then
/boot/dietpi/func/dietpi-set_hardware serialconsole enable
fi

# Re-set dietpi.txt setting on non-VMs to indicated enabled serial console
(( $G_HW_MODEL == 20 || $G_HW_MODEL == 75 )) || G_CONFIG_INJECT 'CONFIG_SERIAL_CONSOLE_ENABLE=' 'CONFIG_SERIAL_CONSOLE_ENABLE=1' /boot/dietpi.txt

G_DIETPI-NOTIFY 2 'Disabling static and automatic login prompts on consoles tty2 to tty6:'
G_EXEC systemctl mask --now getty-static
# - logind features are usually not needed and (aside of automatic getty spawn) require the libpam-systemd package.
Expand Down Expand Up @@ -1552,13 +1551,13 @@ _EOF_'
G_EXEC eval 'echo -e '\''apm = 127\nforce_spindown_time = 120'\'' > /etc/hdparm.conf'
fi

# - Odroid N2/C4: Modern single partition image
# Odroid N2/C4: Modern single partition image
if [[ $G_HW_MODEL == 1[56] && -f '/boot/dietpiEnv.txt' ]]
then
G_CONFIG_INJECT 'rootdev=' "rootdev=UUID=$(findmnt -Ufnro UUID -M /)" /boot/dietpiEnv.txt
G_CONFIG_INJECT 'rootfstype=' "rootfstype=$(findmnt -Ufnro FSTYPE -M /)" /boot/dietpiEnv.txt

# - Sparky SBC
# Sparky SBC
elif (( $G_HW_MODEL == 70 ))
then
# Install latest kernel/drivers
Expand Down Expand Up @@ -1630,7 +1629,7 @@ WantedBy=multi-user.target
_EOF_
G_EXEC systemctl enable dietpi-sparkysbc_ethernet

# - RPi
# RPi
elif (( $G_HW_MODEL < 10 )); then

# Creating RPi-specific groups
Expand Down Expand Up @@ -1703,7 +1702,7 @@ _EOF_
done < <(dpkg -L 'libraspberrypi0' | grep '^/usr/lib/arm-linux-gnueabihf/.*\.so.0$')
fi

# - Radxa Zero
# Radxa Zero
elif (( $G_HW_MODEL == 74 ))
then
# Use ondemand CPU governor since schedutil currently causes kernel errors and hangs
Expand All @@ -1719,15 +1718,15 @@ _EOF_
G_CONFIG_INJECT 'docker_optimizations=' 'docker_optimizations=off' /boot/uEnv.txt
fi

# - NanoPi R1
# NanoPi R1
elif [[ $G_HW_MODEL == 48 && -f '/boot/armbianEnv.txt' ]]
then
# Enable second USB port by default
local current=$(sed -n '/^[[:blank:]]*overlays=/{s/^[^=]*=//p;q}' /boot/armbianEnv.txt)
[[ $current == *'usbhost2'* ]] || G_CONFIG_INJECT 'overlays=' "overlays=$current usbhost2" /boot/armbianEnv.txt
fi

# - Armbian special
# Armbian special
if [[ -f '/boot/armbianEnv.txt' ]]
then
# Disable bootsplash logo, as we removed the file above: https://github.com/MichaIng/DietPi/issues/3932#issuecomment-852376681
Expand Down Expand Up @@ -1769,8 +1768,10 @@ _EOF_
G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "[$SETUP_STEP] Finalise system for first boot of DietPi"; ((SETUP_STEP++))
#------------------------------------------------------------------------------------------------

if (( $G_HW_MODEL != 75 ))
if (( $G_HW_MODEL == 75 ))
then
G_CONFIG_INJECT 'CONFIG_NTP_MODE=' 'CONFIG_NTP_MODE=0' /boot/dietpi.txt
else
G_EXEC_DESC='Enable Dropbear autostart' G_EXEC sed -i '/NO_START=1/c\NO_START=0' /etc/default/dropbear
G_EXEC systemctl unmask dropbear
G_EXEC systemctl enable dropbear
Expand All @@ -1786,15 +1787,12 @@ _EOF_
G_DIETPI-NOTIFY 2 'Removing swapfile from image'
/boot/dietpi/func/dietpi-set_swapfile 0 /var/swap
[[ -e '/var/swap' ]] && rm -v /var/swap # still exists on some images...
# - Re-enable for next run
# Re-enable for next run
(( $G_HW_MODEL == 75 )) || G_CONFIG_INJECT 'AUTO_SETUP_SWAPFILE_SIZE=' 'AUTO_SETUP_SWAPFILE_SIZE=1' /boot/dietpi.txt
# - Reset /tmp size to default (512 MiB)
# Reset /tmp size to default (512 MiB)
sed -i '\|/tmp|s|size=[^,]*,||' /etc/fstab

G_DIETPI-NOTIFY 2 'Disabling Bluetooth by default'
/boot/dietpi/func/dietpi-set_hardware bluetooth disable

# - Set WiFi
# Set WiFi
local tmp_info='Disabling'
local tmp_mode='disable'
if (( $WIFI_REQUIRED ))
Expand All @@ -1810,6 +1808,9 @@ _EOF_

if (( $G_HW_MODEL != 75 ))
then
G_DIETPI-NOTIFY 2 'Disabling Bluetooth by default'
/boot/dietpi/func/dietpi-set_hardware bluetooth disable

G_DIETPI-NOTIFY 2 "$tmp_info onboard WiFi modules by default"
/boot/dietpi/func/dietpi-set_hardware wifimodules onboard_$tmp_mode

Expand Down
6 changes: 3 additions & 3 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -15876,8 +15876,8 @@ This requires an account at: https://remote.it/
sed -i "\|[[:blank:]]/var/log[[:blank:]]|c\tmpfs /var/log tmpfs size=${AUTOINSTALL_RAMLOG_SIZE}M,noatime,lazytime,nodev,nosuid,mode=1777" /etc/fstab
findmnt /var/log > /dev/null && G_EXEC mount -o remount /var/log

# Set time sync mode
/boot/dietpi/func/dietpi-set_software ntpd-mode $AUTOINSTALL_TIMESYNCMODE
# Set time sync mode if no container system
(( $G_HW_MODEL == 75 )) || /boot/dietpi/func/dietpi-set_software ntpd-mode $AUTOINSTALL_TIMESYNCMODE

# Apply choice and preference system settings
Apply_SSHServer_Choices "$AUTOINSTALL_SSHINDEX"
Expand Down Expand Up @@ -15943,7 +15943,7 @@ This requires an account at: https://remote.it/
#hwclock &> /dev/null && G_AGP fake-hwclock

# x86_64 microcode updates, skip on VM
if (( $G_HW_ARCH == 10 && $G_HW_MODEL != 20 ))
if (( $G_HW_ARCH == 10 && $G_HW_MODEL != 20 && $G_HW_MODEL != 75 ))
then
grep -qi 'vendor_id.*intel' /proc/cpuinfo && G_AGI intel-microcode
grep -qi 'vendor_id.*amd' /proc/cpuinfo && G_AGI amd64-microcode
Expand Down
2 changes: 1 addition & 1 deletion dietpi/func/dietpi-globals
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ Press any key to continue...'
# Check for missing kernel modules, e.g. after a kernel upgrade, and in case create a flag
G_CHECK_KERNEL()
{
[[ -d /lib/modules/$(uname -r) ]] || systemd-detect-virt -c > /dev/null || return 1
[[ $G_HW_MODEL == 75 || -d /lib/modules/$(uname -r) ]] || grep -zaq '^container=' /proc/1/environ || return 1
return 0
}

Expand Down
33 changes: 10 additions & 23 deletions dietpi/func/dietpi-set_hardware
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ Do you want to continue and disable the serial login console?' || return 1
# - All
local aWIFI_MODULES=('cfg80211')

# + RPi with onboard WiFi
if (( $G_HW_ONBOARD_WIFI )); then
# + RPi with onboard WiFi and NanoPi NEO Air
if (( $G_HW_ONBOARD_WIFI || $G_HW_MODEL == 64 )); then

aWIFI_MODULES+=('brcmfmac' 'brcmutil')

Expand All @@ -1358,20 +1358,6 @@ Do you want to continue and disable the serial login console?' || return 1

aWIFI_MODULES+=('8723bs')

# + NanoPi NEO Air
elif (( $G_HW_MODEL == 64 )); then

# 4.9 uses brcm, only enable dhd for 3.x
if [[ -d '/boot/dtb' ]]; then

aWIFI_MODULES+=('brcmfmac' 'brcmutil')

else

aWIFI_MODULES+=('dhd')

fi

# + NanoPi M3/T3/Fire3
elif (( $G_HW_MODEL == 62 )); then

Expand All @@ -1384,10 +1370,13 @@ Do you want to continue and disable the serial login console?' || return 1
# Disable onboard WiFi as well
(( $G_HW_ONBOARD_WIFI )) && INPUT_DEVICE_VALUE='onboard_disable' Wifi_Modules_Main

# Reset blacklists and remove powersaving settings
> /etc/modprobe.d/dietpi-disable_wifi.conf
# Remove powersaving setting
[[ -f '/etc/modprobe.d/dietpi-disable_wifi_powersaving.conf' ]] && rm /etc/modprobe.d/dietpi-disable_wifi_powersaving.conf

# Reset blacklists
[[ -d '/etc/modprobe.d' ]] || G_EXEC mkdir /etc/modprobe.d
> /etc/modprobe.d/dietpi-disable_wifi.conf

# cfg80211 last
for ((i=$(( ${#aWIFI_MODULES[@]} - 1 )); i>=0; i--))
do
Expand All @@ -1398,19 +1387,17 @@ Do you want to continue and disable the serial login console?' || return 1
elif [[ $INPUT_DEVICE_VALUE == 'enable' ]]; then

# Disable known powersaving options for specific chipsets
[[ -d '/etc/modprobe.d' ]] || G_EXEC mkdir /etc/modprobe.d
cat << _EOF_ > /etc/modprobe.d/dietpi-disable_wifi_powersaving.conf
options 8192cu rtw_power_mgnt=0
options 8188eu rtw_power_mgnt=0
# OPi Plus
# NanoPi K1 Plus
options 8189es rtw_power_mgnt=0
# Pine A64
# PINE A64
options 8723bs rtw_power_mgnt=0
# Sparky SBC
options wlan_8192eu rtw_power_mgnt=0
# - https://github.com/sparky-sbc/sparky-test/tree/master/rtl8812au
options wlan_8812au rtw_power_mgnt=0
_EOF_

# Remove blacklists
[[ -f '/etc/modprobe.d/dietpi-disable_wifi.conf' ]] && rm /etc/modprobe.d/dietpi-disable_wifi.conf

Expand Down
4 changes: 2 additions & 2 deletions dietpi/func/dietpi-set_swapfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
Swap_Disable(){

G_DIETPI-NOTIFY 2 'Disabling and deleting all existing swap files'
G_EXEC_NOHALT=1 G_EXEC swapoff -a
(( $G_HW_MODEL == 75 )) || grep -zaq '^container=' /proc/1/environ || G_EXEC swapoff -a
rm -fv "${SWAP_FILES_ACTIVE[@]}"
sed -i '/[[:blank:]]swap[[:blank:]]/d' /etc/fstab
# zram-swap
Expand Down Expand Up @@ -179,7 +179,7 @@
SWAP_SIZE=0

# Unsupported in container
elif grep -qza '^container=' /proc/1/environ; then
elif (( $G_HW_MODEL == 75 )) || grep -zaq '^container=' /proc/1/environ; then

Error_Reset 'Swap space cannot be controlled form within a container.'

Expand Down
5 changes: 5 additions & 0 deletions dietpi/func/run_ntpd
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ NB: We highly recommend choosing "Retry" first. Failing that, try to change the
G_EXEC mkdir -p /run/systemd/timesync
> "$FP_FLAG"

# Container: Skip time sync
elif (( $G_HW_MODEL == 75 )) || grep -zaq '^container=' /proc/1/environ
then
G_DIETPI-NOTIFY 2 'Container detected, skipping time sync'

# Forced mode or flag does not exist: Sync
else
EXIT_CODE=1
Expand Down
79 changes: 41 additions & 38 deletions rootfs/var/lib/dietpi/services/dietpi-firstboot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -114,43 +114,9 @@
# Apply swap settings
/boot/dietpi/func/dietpi-set_swapfile

# Apply time zone
local autoinstall_timezone=$(sed -n '/^[[:blank:]]*AUTO_SETUP_TIMEZONE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
if [[ -f /usr/share/zoneinfo/$autoinstall_timezone && $autoinstall_timezone != $(</etc/timezone) ]]; then

G_DIETPI-NOTIFY 2 "Setting time zone $autoinstall_timezone. Please wait..."
rm -fv /etc/{timezoner,localtime}
ln -s "/usr/share/zoneinfo/$autoinstall_timezone" /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

fi

# Apply language (locale)
local autoinstall_language=$(sed -n '/^[[:blank:]]*AUTO_SETUP_LOCALE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
grep -q "^$autoinstall_language UTF-8$" /usr/share/i18n/SUPPORTED || autoinstall_language='C.UTF-8'
if ! locale | grep -qE "(LANG|LC_ALL)=[\'\"]?${autoinstall_language}[\'\"]?" || ! locale -a | grep -qiE 'C\.UTF-?8'; then

G_DIETPI-NOTIFY 2 "Setting locale $autoinstall_language. Please wait..."
/boot/dietpi/func/dietpi-set_software locale "$autoinstall_language"

fi

# Apply keyboard layout
local autoinstall_keyboard=$(sed -n '/^[[:blank:]]*AUTO_SETUP_KEYBOARD_LAYOUT=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
if [[ $autoinstall_keyboard ]] && ! grep -q "XKBLAYOUT=\"$autoinstall_keyboard\"" /etc/default/keyboard; then

G_DIETPI-NOTIFY 2 "Setting keyboard layout $autoinstall_keyboard. Please wait..."
G_CONFIG_INJECT 'XKBLAYOUT=' "XKBLAYOUT=\"$autoinstall_keyboard\"" /etc/default/keyboard
setupcon --save # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818065

fi

# Apply headless mode if set in dietpi.txt (RPi, Odroid C1/C2)
(( $G_HW_MODEL < 11 || $G_HW_MODEL == 12 )) && /boot/dietpi/func/dietpi-set_hardware headless "$(grep -cm1 '^[[:blank:]]*AUTO_SETUP_HEADLESS=1' /boot/dietpi.txt)"

# Apply forced Ethernet link speed if set in dietpi.txt
/boot/dietpi/func/dietpi-set_hardware eth-forcespeed "$(sed -n '/^[[:blank:]]*AUTO_SETUP_NET_ETH_FORCE_SPEED=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)"

# Set hostname
/boot/dietpi/func/change_hostname "$(sed -n '/^[[:blank:]]*AUTO_SETUP_NET_HOSTNAME=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)"

Expand Down Expand Up @@ -199,6 +165,45 @@ _EOF_
(( $G_HW_MODEL < 10 )) && (( $G_RASPBIAN )) && target_repo='CONFIG_APT_RASPBIAN_MIRROR'
/boot/dietpi/func/dietpi-set_software apt-mirror "$(sed -n "/^[[:blank:]]*$target_repo=/{s/^[^=]*=//p;q}" /boot/dietpi.txt)"

# Recreate machine-id: https://github.com/MichaIng/DietPi/issues/2015
[[ -f '/etc/machine-id' ]] && rm /etc/machine-id
[[ -f '/var/lib/dbus/machine-id' ]] && rm /var/lib/dbus/machine-id
systemd-machine-id-setup

# Apply time zone
local autoinstall_timezone=$(sed -n '/^[[:blank:]]*AUTO_SETUP_TIMEZONE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
if [[ -f /usr/share/zoneinfo/$autoinstall_timezone && $autoinstall_timezone != $(</etc/timezone) ]]; then

G_DIETPI-NOTIFY 2 "Setting time zone $autoinstall_timezone. Please wait..."
rm -fv /etc/{timezoner,localtime}
ln -s "/usr/share/zoneinfo/$autoinstall_timezone" /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

fi

# Apply language (locale)
local autoinstall_language=$(sed -n '/^[[:blank:]]*AUTO_SETUP_LOCALE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
grep -q "^$autoinstall_language UTF-8$" /usr/share/i18n/SUPPORTED || autoinstall_language='C.UTF-8'
if ! locale | grep -qE "(LANG|LC_ALL)=[\'\"]?${autoinstall_language}[\'\"]?" || ! locale -a | grep -qiE 'C\.UTF-?8'; then

G_DIETPI-NOTIFY 2 "Setting locale $autoinstall_language. Please wait..."
/boot/dietpi/func/dietpi-set_software locale "$autoinstall_language"

fi

# Skip keyboard, SSH and network setup on container systems
(( $G_HW_MODEL == 75 )) && return 0

# Apply keyboard layout
local autoinstall_keyboard=$(sed -n '/^[[:blank:]]*AUTO_SETUP_KEYBOARD_LAYOUT=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
if [[ $autoinstall_keyboard ]] && ! grep -q "XKBLAYOUT=\"$autoinstall_keyboard\"" /etc/default/keyboard; then

G_DIETPI-NOTIFY 2 "Setting keyboard layout $autoinstall_keyboard. Please wait..."
G_CONFIG_INJECT 'XKBLAYOUT=' "XKBLAYOUT=\"$autoinstall_keyboard\"" /etc/default/keyboard
setupcon --save # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818065

fi

# Regenerate unique Dropbear host keys
local i type
for i in /etc/dropbear/dropbear_*_host_key
Expand All @@ -209,10 +214,8 @@ _EOF_
dropbearkey -t "$type" -f "$i"
done

# Recreate machine-id: https://github.com/MichaIng/DietPi/issues/2015
[[ -f '/etc/machine-id' ]] && rm /etc/machine-id
[[ -f '/var/lib/dbus/machine-id' ]] && rm /var/lib/dbus/machine-id
systemd-machine-id-setup
# Apply forced Ethernet link speed if set in dietpi.txt
/boot/dietpi/func/dietpi-set_hardware eth-forcespeed "$(sed -n '/^[[:blank:]]*AUTO_SETUP_NET_ETH_FORCE_SPEED=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)"

# Network setup
# - Grab available network interfaces
Expand Down

0 comments on commit 78ba121

Please sign in to comment.