In this article, we explore an efficient bash script, debian_firmware_setup.sh
, that simplifies the process of integrating non-free firmware, such as Wi-Fi drivers, into your Debian installation. The script automates the preparation of a USB stick by formatting it, downloading a specified version of Debian non-free firmware, and extracting it onto the USB stick. This results in a ready-to-use USB device that can be deployed during a Debian installation process, thereby easing the setup of non-free firmware elements and reducing the hassle often associated with manual firmware integration.
In this tutorial you will learn:
- USB Formatting: The script automates the process of wiping and formatting a selected USB stick, preparing it for the installation of firmware.
- Firmware Download: It downloads a specific version of the non-free Debian firmware as specified by the user.
- Firmware Installation: The downloaded firmware is automatically extracted onto the newly formatted USB stick, making it ready to use.
- Assisting Debian Installation: The resultant USB stick serves as a convenient tool during the Debian installation process, helping users to effortlessly integrate non-free firmware, like Wi-Fi drivers.

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | N/A |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Debian Firmware USB creator
n this guide, we’ll walk you through the process of using the debian_firmware_setup.sh
script. This script automates the process of preparing a USB stick with a specific version of non-free Debian firmware. Here are the detailed steps to use this script:
- Get the script: You will need to have the
debian_firmware_setup.sh
script on your system. It can be placed in any directory you find suitable. This could be achieved by copy-pasting the script from the source where it’s provided. Here is the script:#!/bin/bash # Check if root if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi # Check if correct number of arguments are provided if [ "$#" -ne 1 ]; then echo "Usage: $0 " exit 1 fi VERSION=$1 MOUNT_POINT="/mnt/usb" # Get a list of USB devices USB_DEVICES=$(lsblk -do NAME,MODEL,SIZE,TRAN | grep 'usb') # Check if any USB devices were found if [ -z "$USB_DEVICES" ]; then echo "No USB devices found. Please plug in a USB device and try again." exit 1 fi # Convert the devices into an array USB_DEVICES=($USB_DEVICES) # Print the USB devices and ask the user to choose one IFS=$'\n' for i in $(lsblk -do NAME,MODEL,SIZE,TRAN | grep 'usb'); do DEVICES+=("$i") done for i in "${!DEVICES[@]}"; do echo "$((i+1)). ${DEVICES[$i]}" done echo "Please enter the number of the device you want to format:" read NUMBER DEVICE="/dev/$(echo ${DEVICES[$((NUMBER-1))]} | awk '{print $1}')" # Unmount if mounted if mount | grep -q $DEVICE; then echo "Device $DEVICE is mounted. Unmounting..." umount $DEVICE* fi # Wipe old signatures wipefs --all --force $DEVICE # Create the partition echo -e "o\nn\np\n1\n\n\nt\nb\nw" | fdisk $DEVICE # Create the filesystem with a delay sleep 5 # Add delay to ensure /dev/sda1 will be available PARTITION=${DEVICE}1 mkfs.vfat $PARTITION # Create mount point if it doesn't exist mkdir -p $MOUNT_POINT # Mount the partition mount $PARTITION $MOUNT_POINT # Verify if the partition is mounted if ! mount | grep -q $PARTITION; then echo "Failed to mount $PARTITION. Cannot proceed with writing data." exit 1 fi # Download the firmware FIRMWARE_URL="http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$VERSION/current/firmware.tar.gz" wget -P $MOUNT_POINT $FIRMWARE_URL # Extract the firmware tar -xvzf $MOUNT_POINT/firmware.tar.gz -C $MOUNT_POINT # Unmount the partition if it's mounted if mount | grep -q $PARTITION; then umount $PARTITION fi echo "The script has finished."
- Make the script executable: Once you have the script on your system, navigate to the directory where it’s located using the terminal, and make it executable using the following command:
$ chmod +x debian_firmware_setup.sh
- Run the script: The script needs to be run as a root user. Also, you must provide the Debian version of the non-free firmware you want to download. Use the following command to run the script:
$ sudo ./debian_firmware_setup.sh <Debian version> eg. bookworm
Replace
<Debian version>
with the version of the Debian firmware you want to download. - Choose the USB stick: The script will list all connected USB devices with their names and sizes, and prompt you to select one. Type the number corresponding to the USB device you want to format and press Enter. Be careful at this step as the chosen USB stick will be formatted, and all data on it will be erased.
- Wait for the process to complete: The script will then unmount the selected device (if it was mounted), wipe it, create a new partition, format it, mount it, download the specified version of Debian firmware, extract the firmware onto the newly created partition, and then finally unmount the partition.
Please note, the internet connection is necessary for the script to download the Debian firmware. Make sure to use this USB stick during your Debian installation process to seamlessly integrate the non-free firmware.
Remember, always use this script with caution as it formats the selected USB device, resulting in loss of all data on the device.
Conclusion
In conclusion, the debian_firmware_setup.sh
script is a powerful tool that simplifies the process of preparing a USB stick with specific non-free Debian firmware. Its automation eliminates the complexities often associated with manual USB formatting, firmware download, and extraction processes. By prompting the user to choose from connected USB devices, ensuring successful mount and unmount, and handling all operations related to the firmware setup, this script streamlines the Debian installation process, especially when it comes to the integration of non-free firmware like Wi-Fi drivers. However, always proceed with caution while using such scripts as they involve formatting operations, which result in the loss of all existing data on the selected USB stick. With this utility in your arsenal, setting up Debian with specific non-free firmware becomes an effortless task.