Pre-setup WiFi connection from Linux

I am installing OSMC on a RPi 3 B+, from a Linux (Fedora 31) machine.

Entering WiFi connection setting post-install on the RPi is tedious (or I’m just quite lazy), so I would like to burn the image with network settings preconfigured — so I insert the SD card, fire the RPi, and can directly ssh to it to finish the install.

The wiki says that pre-configuring network can be done using the OSMC installer. However the installer has gone missing for Linux, and burning the image should be done via dd

Question: How to pre-configure WiFi settings when the image is burn from Linux?

1 Like

Thank you!

For the record (and because the accepted answer in the link can be misleading) here is what I did (and was successful):

  • Create a preseed.cfg file as follows (and replace YOUR_WIFI_NAME and YOUR_WIFI_PWD by your actual SSID and password):

    d-i target/storage string sd
    d-i network/interface string wlan
    d-i network/auto boolean true
    d-i network/ssid string YOUR_WIFI_NAME
    d-i network/wlan_keytype string 1
    d-i network/wlan_key string YOUR_WIFI_PWD
    
  • Burn the image with your network connection pre-configured:

    • Insert you SD card, and retrieve its location via lsblk -p.
      (The disk — i.e. SD card — location should be something like sdb, or sdc, not followed by a digit. Then replace sdX with this value in the script below.)

    • Run the following commands (as root):

      # Burn the image on SD card (use the relevant path after `if=`)
      dd bs=1M if=OSMC_TGT_rbp2_20200402.img of=/dev/sdX conv=fsync
      
      # Mount SD card
      mkdir /mnt/osmc
      mount /dev/sdX1 /mnt/osmc
      
      # Copy config
      cp preseed.cfg /mnt/osmc
      
      # Unmount partition and clean mounting point
      umount /dev/sdX1
      rm -r /mnt/osmc
      
  • Insert the SD card in the RPi, power it up, and… that’s it!

That step should be not necessary as the dd will overwrite the whole card

1 Like

As sda always is the first disk (normally the one that has your OS) this is quite unlikely the SD Card to be sda unless a very special setup.

Thanks for the hint about dd.

(Regarding sda, I’ve listed here because it’s my case as my disk connected via NVMe port, rather than SATA — but I’ll remove it as it can be misleading indeed.)

Anyway, assuming that the preseed.cfg has been created, I’ve created the following script that can be called as follows:

# ./burn_osmc <disk> <path/to/img> <path/to/cfg>

For example:

./burn_osmc sdb ~/downloads/OSMC_TGT_rbp2_20200402.img ~/sandbox/preseed.cfg

burn_osmc:

# Retrieve arguments
disk_name=$1
img_path=$2
config_path=${3:-preseed.cfg}

# Burn the image on SD card
dd bs=1M if=$img_path of=/dev/$disk_name conv=fsync

# Mount SD card
mkdir /mnt/osmc
mount /dev/${disk_name}1 /mnt/osmc

# Copy config
cp $config_path /mnt/osmc

# Unmount partition and clean mounting point
umount /dev/${disk_name}1
rm -r /mnt/osmc
1 Like