Automate the network config but DHCP is still used

Hi,

I created a dietpi.txt file under the /boot dir to configure the Eth0 interface

AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0
AUTO_SETUP_NET_ETH_FORCE_SPEED=0
AUTO_SETUP_NET_WIFI_COUNTRY_CODE=FR

AUTO_SETUP_NET_USESTATIC=1
AUTO_SETUP_NET_STATIC_IP=192.168.1.200
AUTO_SETUP_NET_STATIC_MASK=255.255.255.0
AUTO_SETUP_NET_STATIC_GATEWAY=192.168.1.1
AUTO_SETUP_NET_STATIC_DNS=192.168.1.1

but when DietPi boots, then the /etc/network/interface still refers to another config

cat /etc/network/interfaces
# Location: /etc/network/interfaces
# Please modify network settings via: dietpi-config
# Or create your own drop-ins in: /etc/network/interfaces.d/

# Drop-in configs
source interfaces.d/*

# Ethernet
allow-hotplug eth0
iface eth0 inet dhcp
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
#dns-nameservers 9.9.9.9 149.112.112.112

# WiFi
#allow-hotplug wlan0
iface wlan0 inet dhcp
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
#dns-nameservers 9.9.9.9 149.112.112.112
wireless-power off
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

What is the problem ?

Cheers

Charles

Configuration values AUTO_SETUP are used on first initial boot to configure the initial setup. They are not used during normal operation. To change IP address to static, you would need to use configuration tool dietpi-config

So I cannot at first boot configure the static IP adresss - correct ?

maybe we misunderstood. All AUTO_SETUP_* parameter inside dietpi.txt are used during first boot only.

This is the statement from config file

#------------------------------------------------------------------------------------------------------
##### DietPi-Automation settings, applied on first boot of DietPi only, ONCE! #####
#------------------------------------------------------------------------------------------------------

You can specify them right after flashing the image, before you start the system the first time.

Many thanks. What then do you recommend to do to automate completely the installation of DietPi (including network setup, software installation, services configured, …) ?

I did a test on RPi4B using the ARMv8 Bullseye image and adjusted dietpi.txt after flashing and set following

# Enter your static network details below, if applicable.
AUTO_SETUP_NET_USESTATIC=1
AUTO_SETUP_NET_STATIC_IP=192.168.0.222
AUTO_SETUP_NET_STATIC_MASK=255.255.255.0
AUTO_SETUP_NET_STATIC_GATEWAY=192.168.0.1
AUTO_SETUP_NET_STATIC_DNS=192.168.0.11

This was correctly taken into account during first boot

Network details

root@DietPi4:~# cat /etc/network/interfaces
# Location: /etc/network/interfaces
# Please modify network settings via: dietpi-config
# Or create your own drop-ins in: /etc/network/interfaces.d/

# Drop-in configs
source interfaces.d/*

# Ethernet
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.222
netmask 255.255.255.0
gateway 192.168.0.1
#dns-nameservers 9.9.9.9 149.112.112.112

DNS config

root@DietPi4:~# cat /etc/resolv.conf
nameserver 192.168.0.11
root@DietPi4:~#

Here is what I did without success as the IP address assigned is the one coming the router DHCP: 192.68.1.35

What I did :

  • Copy DietPi_ROCKPro64-ARMv8-Bullseye.img to eMMC card
  • Copy the dietpi.txt file to /boot
  • Plug the eMMC card on the RockPro64

Here is a snipped part of the config file - https://github.com/cmoulliard/home-devices/blob/27d74d33907cb9d6d0fadeaf618e45eafab72f68/config/dietpi-server.txt#L26-L44

AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0

AUTO_SETUP_NET_ETH_FORCE_SPEED=0
AUTO_SETUP_NET_WIFI_COUNTRY_CODE=FR

AUTO_SETUP_NET_USESTATIC=1
AUTO_SETUP_NET_STATIC_IP=192.168.1.200
AUTO_SETUP_NET_STATIC_MASK=255.255.255.0
AUTO_SETUP_NET_STATIC_GATEWAY=192.168.1.1
AUTO_SETUP_NET_STATIC_DNS=192.168.1.1

#AUTO_SETUP_DHCP_TO_STATIC=0

hm strange, as I don’t have a ROCKPro64, I’m not able to test the specific case. But usually it should work same on all images

MichaIng
can you have a look

Here is how I copy the files from my macbook to the eMMC card

flavor=server
vagrant ssh -c "pmount /dev/sdb1"
vagrant ssh -c "sudo touch /media/sdb1/boot/dietpi-{server,desktop,wifi}.txt && sudo chmod 666 /media/sdb1/boot/*.txt"
vagrant scp ../config/dietpi-wifi.txt /media/sdb1/boot
vagrant scp ../config/dietpi-${flavor}.txt /media/sdb1/boot
vagrant ssh -c "cp /media/sdb1/boot/dietpi-${flavor}.txt /media/sdb1/boot/dietpi.txt"
vagrant ssh -c "ls -la /media/sdb1/boot"
 vagrant ssh -c "ls -la /media/sdb1/boot"
total 70696
drwxr-xr-x  4 root root     4096 Oct 19 14:07 .
drwxr-xr-x 18 root root     4096 Oct 19 14:15 ..
-rw-r--r--  1 root root      217 Oct 19 14:06 armbianEnv.txt
-rw-r--r--  1 root root   307322 Oct 19 13:56 boot.bmp
-rw-r--r--  1 root root     3113 Aug 26 11:04 boot.cmd
-rw-rw-r--  1 root root     3185 Aug 26 11:08 boot.scr
-rw-r--r--  1 root root   221500 Sep  8 10:57 config-5.10.63-rockchip64
drwxr-xr-x  4 root root     4096 Oct 19 14:07 dietpi
-rw-rw-r--  1 root root    18092 Oct 18 17:03 dietpi-LICENSE.txt
-rw-rw-r--  1 root root    14711 Oct 18 17:03 dietpi-README.md
-rw-rw-r--  1 root root    15085 Oct 19 14:07 dietpi.txt
-rw-------  1 root root     2955 Oct 19 14:07 dietpi-wifi.txt
lrwxrwxrwx  1 root root       22 Oct 19 13:39 dtb -> dtb-5.10.63-rockchip64
drwxr-xr-x  6 root root     4096 Oct 19 13:23 dtb-5.10.63-rockchip64
lrwxrwxrwx  1 root root       26 Oct 19 13:36 Image -> vmlinuz-5.10.63-rockchip64
-rw-r--r--  1 root root 12443797 Oct 19 13:02 initrd.img-5.10.60-rockchip64
-rw-r--r--  1 root root 12442464 Oct 19 13:36 initrd.img-5.10.63-rockchip64
-rw-r--r--  1 root root        0 Oct 19 13:36 .next
-rw-r--r--  1 root root  5840624 Sep  8 10:57 System.map-5.10.63-rockchip64
lrwxrwxrwx  1 root root       26 Oct 19 13:36 uInitrd -> uInitrd-5.10.63-rockchip64
-rw-r--r--  1 root root 12442528 Oct 19 13:36 uInitrd-5.10.63-rockchip64
-rw-r--r--  1 root root 28580352 Sep  8 10:57 vmlinuz-5.10.63-rockchip64

where dietpi-server.txt is the one containing the minimal server config and IP static network config

What is also strange is that when I log on after the first boot, I got many screen asking me questions like by example: Accept Licence, Disable console, software list to be installed whicj have been defined within the ditpi.txt file - https://gist.github.com/cmoulliard/d5a3aa73436322bcff9936e6de03be39. Could it be possible that the dietpi.txt was not used by dietpi when the OS started for the first time ?

Yes obviously dietpi.txt was not respected at all. Can you check after first boot of the system (from the booted system):

cat /boot/dietpi.txt # whether it is really the one you copied
cat /var/tmp/dietpi/logs/dietpi-firstboot.log # for error messages when settings should have been applied

If I plug the eMMC car to my macbook and mount the volume /boot, then the content of dietpi.txt file is not mine

vagrant@vagrant:/media/sdb1/boot$ cat dietpi.txt | grep  AUTO_SETUP_
# - This setting is ignored (and assumed to be affirmative) if AUTO_SETUP_AUTOMATED=1
AUTO_SETUP_ACCEPT_LICENSE=0
AUTO_SETUP_LOCALE=C.UTF-8
AUTO_SETUP_KEYBOARD_LAYOUT=gb
AUTO_SETUP_TIMEZONE=Europe/London
AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0
AUTO_SETUP_NET_ETH_FORCE_SPEED=0
AUTO_SETUP_NET_WIFI_COUNTRY_CODE=GB
AUTO_SETUP_NET_USESTATIC=0
AUTO_SETUP_NET_STATIC_IP=192.168.0.100
AUTO_SETUP_NET_STATIC_MASK=255.255.255.0
AUTO_SETUP_NET_STATIC_GATEWAY=192.168.0.1
AUTO_SETUP_NET_STATIC_DNS=9.9.9.9 149.112.112.112
AUTO_SETUP_DHCP_TO_STATIC=0
AUTO_SETUP_NET_HOSTNAME=DietPi
AUTO_SETUP_BOOT_WAIT_FOR_NETWORK=1
AUTO_SETUP_SWAPFILE_SIZE=0
AUTO_SETUP_SWAPFILE_LOCATION=/var/swap
AUTO_SETUP_HEADLESS=0
# - Option 1 = Host your script online, then use e.g. AUTO_SETUP_CUSTOM_SCRIPT_EXEC=https://myweb.com/myscript.sh and it will be downloaded and executed automatically.
AUTO_SETUP_CUSTOM_SCRIPT_EXEC=0
AUTO_SETUP_BACKUP_RESTORE=0
AUTO_SETUP_SSH_SERVER_INDEX=-1
AUTO_SETUP_FILE_SERVER_INDEX=0
AUTO_SETUP_LOGGING_INDEX=-1
AUTO_SETUP_RAMLOG_MAXSIZE=50
AUTO_SETUP_WEB_SERVER_INDEX=-2
AUTO_SETUP_DESKTOP_INDEX=0
AUTO_SETUP_BROWSER_INDEX=-1
# - Related software titles must be installed either on firstrun installs or via AUTO_SETUP_AUTOMATED=1 + AUTO_SETUP_INSTALL_SOFTWARE_ID (see below).
AUTO_SETUP_AUTOSTART_TARGET_INDEX=0
AUTO_SETUP_AUTOSTART_LOGIN_USER=root
# - Setting this to "1" indicates that you accept the DietPi GPLv2 license, available at /boot/dietpi-LICENSE.txt, superseding any setting of AUTO_SETUP_ACCEPT_LICENSE.
AUTO_SETUP_AUTOMATED=0
#AUTO_SETUP_GLOBAL_PASSWORD= # Password has been encrypted and saved to rootfs
#AUTO_SETUP_INSTALL_SOFTWARE_ID=23

Here is the content of the log

vagrant@vagrant:/media/sdb1$ cat var/tmp/dietpi/logs/dietpi-firstboot.log
[ SUB1 ] DietPi-Set_swapfile > Applying 1 /var/swap
[ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files
[ .... ] DietPi-Set_swapfile | swapoff -a
[  OK  ] DietPi-Set_swapfile | swapoff -a
[  OK  ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=0
[  OK  ] DietPi-Set_swapfile | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_SWAPFILE_LOCATION=/var/swap
[ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 1931 MiB
[ .... ] DietPi-Set_swapfile | mount -o remount /tmp
[  OK  ] DietPi-Set_swapfile | mount -o remount /tmp
[ INFO ] DietPi-FirstBoot | Setting time zone Europe/London. Please wait...
removed '/etc/localtime'

Current default time zone: 'Europe/London'
Local time is now:      Tue Oct 19 15:08:09 BST 2021.
Universal Time is now:  Tue Oct 19 14:08:09 UTC 2021.

[ SUB1 ] DietPi-Set_hardware > eth-forcespeed (disable)
[  OK  ] eth-forcespeed disable | Completed
[  OK  ] DietPi-Change_hostname | Desired setting in /etc/hosts was already set: 127.0.1.1 DietPi
[ .... ] DietPi-Change_hostname | hostname DietPi
[  OK  ] DietPi-Change_hostname | hostname DietPi
[ SUB1 ] DietPi-Set_software > apt-mirror (https://deb.debian.org/debian/)
[ .... ] DietPi-Set_software | eval echo 'deb https://deb.debian.org/debian/ bullseye main contrib non-free
deb https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye/updates main contrib non-free
deb https://deb.debian.org/debian/ bullseye-backports main contrib non-free' > /etc/apt/sources.list
[  OK  ] DietPi-Set_software | eval echo 'deb https://deb.debian.org/debian/ bullseye main contrib non-free
deb https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye/updates main contrib non-free
deb https://deb.debian.org/debian/ bullseye-backports main contrib non-free' > /etc/apt/sources.list
[ .... ] DietPi-Set_software | sed -i 3s|/updates|-security| /etc/apt/sources.list
[  OK  ] DietPi-Set_software | sed -i 3s|/updates|-security| /etc/apt/sources.list
[  OK  ] DietPi-Set_software | Desired setting in /boot/dietpi.txt was already set: CONFIG_APT_DEBIAN_MIRROR=https://deb.debian.org/debian/
[  OK  ] apt-mirror https://deb.debian.org/debian/ | Completed
removed '/etc/dropbear/dropbear_ecdsa_host_key'
Generating 256 bit ecdsa key, this may take a while...
Public key portion is:
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOy1w59pYQNih7/bjU7sQXOq/eqbVFf00sJGSh/rHIpEkHFH9pmyQtnfyR8C59WBJwfde8ArG9XAwKqE4Ifz2hk= root@DietPi
Fingerprint: sha1!! 0b:3d:95:78:37:84:42:24:fc:59:b6:c0:23:4d:8c:df:87:a7:a6:55
removed '/etc/dropbear/dropbear_ed25519_host_key'
Generating 256 bit ed25519 key, this may take a while...
Public key portion is:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGrriTf1lDni/EUFOj7YXv+z21k6KfnsH4Yo2p7XHW8Z root@DietPi
Fingerprint: sha1!! 6b:7a:e3:1c:65:a3:f3:9d:49:20:cb:8b:ca:f4:5b:1e:72:17:66:f2
removed '/etc/dropbear/dropbear_rsa_host_key'
Generating 2048 bit rsa key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSeX++984/lMcaKLDyRKUjTwZJdZRU6bqJpE0HCXTGzHuFVMn7hAhGuoZ7vVj/kwUW0oMm0yT1qpAhxeq86lJpoyxm86AfuI5rwj1hOrX7aiCKLTadtQrmOG7+H+g9ercv4WZpt3D746ByF1/m5u+qmlTcE/MTvNl9HwIDvJlql8E32y8BlTtBj11b4+wpeIQ4YVhLckIYXrFEGEptuk/dAeqR9XAcOKrvs2pHbl7X1SSxicZCxvb9Xww3qkTbc6cJNK+3S7QjKSOMXVpeTC9pJl0Bt+ssK826GjnCqtOeeOxf+YVgHo5vEkRVXp2QjjCom1csz92QdivJa8t1U6s9 root@DietPi
Fingerprint: sha1!! 2a:5b:14:9c:e8:14:23:f2:57:e0:bc:26:13:0f:73:9d:ee:cd:0a:3f
Initializing machine ID from random generator.
[ SUB1 ] DietPi-Set_hardware > wifimodules (disable)
[  OK  ] wifimodules disable | Completed
[ SUB1 ] DietPi-Set_hardware > enableipv6 (enable)
[  OK  ] DietPi-Set_hardware | Desired setting in /etc/hosts was already set: ::1 localhost ip6-localhost ip6-loopback
[  OK  ] DietPi-Set_hardware | Desired setting in /etc/hosts was already set: ff02::1 ip6-allnodes
[  OK  ] DietPi-Set_hardware | Desired setting in /etc/hosts was already set: ff02::2 ip6-allrouters
[  OK  ] DietPi-Set_hardware | Desired setting in /boot/dietpi.txt was already set: CONFIG_ENABLE_IPV6=1
[  OK  ] enableipv6 enable | Completed
[ SUB1 ] DietPi-Set_hardware > preferipv4 (enable)
[  OK  ] DietPi-Set_hardware | Desired setting in /etc/wgetrc was already set: prefer-family = IPv4
[  OK  ] DietPi-Set_hardware | Desired setting in /boot/dietpi.txt was already set: CONFIG_PREFER_IPV4=1
[  OK  ] preferipv4 enable | Completed
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/12:eb:64:62:74:e2
Sending on   LPF/eth0/12:eb:64:62:74:e2
Sending on   Socket/fallback
Created duid "\000\001\000\001)\001\215\314\022\353dbt\342".
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPOFFER of 192.168.1.36 from 192.168.1.1
DHCPREQUEST for 192.168.1.36 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.36 from 192.168.1.1
bound to 192.168.1.36 -- renewal in 1450 seconds.
[ SUB1 ] DietPi-Set_software > boot_wait_for_network (1)
[  OK  ] DietPi-Set_software | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_BOOT_WAIT_FOR_NETWORK=1
[  OK  ] boot_wait_for_network 1 | Completed
Removed /etc/systemd/system/multi-user.target.wants/dietpi-firstboot.service.

looking to the provided information, it seems dietpi.txt has not been copied to eMMC at all. It still seems to be the original file according the time stamp



-rw-rw-r--  1 root root    15085 Oct 19 14:07 dietpi.txt

What do you mean by “mount the volume /boot”? There is (or should be) only a single partition on that image holding a single ext4 filesystem with the /boot directory inside, next to all other root directories.

And MacOS should not be able to access ext4 partition without special tools

Many thanks. I flashed again the eMMC card and copied now correctly the dietpi.txt files. That works !!!

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
 ─────────────────────────────────────────────────────
 DietPi v7.8.2 : 14:40 - Wed 12/08/2021
 ─────────────────────────────────────────────────────
 - LAN IP : 192.168.1.200 (eth0)

Many thanks :smiley:

This is why I mount the eMMC card using vagrant :wink:

That is actually nice to know. Something for our docs. I wanted to add as well a guide about how to mount ext4 on Windows via WSL2.

Here is my README file to setup vagrant for ext4: https://gist.github.com/cmoulliard/061269762326f9304005f42fe37adc43
using as vagantfile

$script = <<SCRIPT
apt-get install pmount -y
SCRIPT
Vagrant.configure("2") do |config|
  config.vm.box = 'bento/ubuntu-20.04'
  config.vm.provider :virtualbox do |vb|
    vb.customize ['modifyvm', :id, '--usb', 'on']
    vb.customize ['usbfilter', 'add', '0',
      '--target', :id,
      '--name', 'DietPi',
      '--vendorid', '0x05e3',
      '--productid', '0x0727']
  config.vm.provision "shell", inline: $script
  end
end

NOTE That shuld be improved to by example config using ENV var the VendorID and ProductID of the USB card, eMMC card, …

Nice, thanks for sharing :slight_smile:.