md
Creating a Custom Armbian Image
2019-01-31
<-Creating a Custom Raspbian Image (in French) --

Lately, I'm using the Orange Pi Zero bought some time ago for new projects. It is important to validate procedures by repeating them in fresh installation of the operating system. That means burning the OS image on a microSD card and then performing a number of initial steps such as setting up the network, upgrading all installed packages and so on that need to be repeated in exactly the same way each time a new image is used. All this takes time and somewhat error prone. So I decided to create a binary image that avoids these steps.

It is much easier to create a custom image of Armbian than it was to do it for Raspbian. However, it is necessary to have access to a Linux machine with a microSD card reader and with GParted installed. Probably the command line utility parted could be used in place of the latter.

The elegant way of doing this would be to build the OS image from sources modifying it to meet my needs. But a cursory look at the Developer Guide was enough to convince me that such an endeavour was above my pay scale.

Table of Contents

  1. Copy Armbian on a microSD card
  2. Updating Armbian Stretch
  3. Save the Modified OS Image
  4. Usage

Copy Armbian on a microSD card toc

Get the Armbian image from the download page. Since the target is an Orange Pi Zero, I ended up getting Armbian Stretch even though Bionic is already available.

The downloaded file is a 7z compressed archive so it is necessary to extract the image file, Armbian_5.69_Orangepizero_Debian_stretch_next_4.19.13.img in order to use Balena Etcher as recommended by Igor Pečovnik et al at Armbian.com.

Updating Armbian Stretch toc

The initial boot and configuration of the Orange Pi Zero are done with the serial connection as described before. It could be done with an SSH session over a wired Ethernet connection. I connected a USB to serial adapter to the header on the Opiz, opened a serial connection using screen and powered up the Opiz with the microSD card in its reader of course.

michel@hp:~$ screen /dev/ttyUSB0 115200 ... U-Boot SPL 2018.05-armbian (Jan 09 2019 - 22:27:17 +0100) DRAM: 512 MiB Trying to boot from MMC1 U-Boot 2018.05-armbian (Jan 09 2019 - 22:27:17 +0100) Allwinner Technology CPU: Allwinner H3 (SUN8I 1680) Model: Xunlong Orange Pi Zero DRAM: 512 MiB MMC: SUNXI SD/MMC: 0 Loading Environment from EXT4... ** File not found /boot/boot.env ** .... The typical Linux startup messages will scroll by. They can be reviewed with dmesg latter. None of this will be seen if an SSH connection is used instead of a serial connection. ... Debian GNU/Linux 9 orangepizero ttyS0 orangepizero login: root Password: 1234 not echoed to the screen You are required to change your password immediately (root enforced) Changing password for root. (current) UNIX password: 1234 not echoed to the screen Enter new UNIX password: xyxyxy your chosen password, not echoed to the screen Retype new UNIX password: xyxyxy repeat the chosen password, not echoed to the screen ___ ____ _ _____ / _ \ _ __ __ _ _ __ __ _ ___ | _ \(_) |__ /___ _ __ ___ | | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | | / // _ \ '__/ _ | |_| | | | (_| | | | | (_| | __/ | __/| | / /| __/ | | (_) | \___/|_| \__,_|_| |_|\__, |\___| |_| |_| /____\___|_| \___/ |___/ Welcome to ARMBIAN 5.69 stable Debian GNU/Linux 9 (stretch) 4.19.13-sunxi System load: 0.11 0.26 0.15 Up time: 4 min Memory usage: 11 % of 493MB IP: CPU temp: 38°C Usage of /: 6% of 15G [ General system configuration (beta): armbian-config ] New to Armbian? Check the documentation first: https://docs.armbian.com Thank you for choosing Armbian! Support: www.armbian.com Creating a new user account. Press <Ctrl-C> to abort Please provide a username (eg. your forename): zero Trying to add user zero Adding user `zero' ... Adding new group `zero' (1000) ... Adding new user `zero' (1000) with group `zero' ... Creating home directory `/home/zero' ... Copying files from `/etc/skel' ... Enter new UNIX password: xxxyyy Retype new UNIX password: xxxyyy passwd: password updated successfully Changing the user information for zero Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y Dear zero, your account zero has been created and is sudo enabled. Please use this account for your daily work from now on.

On the first boot, you are made to change the root password and to create a default user. I chose zero at its name and did not bother entering any personal information.

As can be seen, the file system has been expanded to the full 15 GB on the microSD card. It takes forever to create backup images of this size card which is quite frustrating. So after setting up a minimal common configuration, the file system will be shrunk back down to 2 GB. Note that the current user is root so there will not be any need for the sudo prefix.

root@orangepizero:~# armbian-config Warning. Configurator can't work properly without internet connection. Press CTRL C to stop or any key to ignore and continue. k ────────────────────────────────────────────────────────────────────────────── Configuration utility, Armbian 5.69 stable ────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────── armbian-config ──────────────────────────────┐ │ │ │ Configure Debian stretch based Armbian for the Orange Pi Zero │ │ │ │ Support: https://forum.armbian.com │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ System System and security settings │ │ │ │ Network Wired, wireless, Bluetooth, access point │ │ │ │ Personal Timezone, language, hostname │ │ │ │ Software System and 3rd party software install │ │ │ │ Help Documentation, support, sources │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────┤ │ < OK > <Cancel> │ └─────────────────────────────────────────────────────────────────────────┘

In the main screen shown above, use the cursor keys to highlight Network, then press Tab to get to the < OK > button and press the space bar or the Enter key go on to configure the wireless network interface.

┌──────Select default interface────────┐ │ ┌──────────────────────────────────┐ │ │ │ eth0 │ │ │ │ wlan0 │ │ │ └──────────────────────────────────┘ │ ├──────────────────────────────────────┤ │ < OK > │ └──────────────────────────────────────┘

Use the cursor keys to highlight wlan0, then press Tab to get to the < OK > button and press the space bar or the Enter key to go on.

┌────────────── Wired, Wireless, Bluetooth, Hotspot ─────────────────┐ │ │ │ IP (wlan0) via Network Manager: │ │ │ │ Note: This tool can be successful only when drivers are in good │ │ shape. If autodetection fails, you are on your own. │ │ │ │ ┌────────────────────────────────────────────────────────────────┐ │ │ │ IP Select dynamic or edit static IP address │ │ │ │ Hotspot Create WiFi access point │ │ │ │ IPV6 Disable IPV6 for APT and system │ │ │ │ Iperf3 Enable network throughput tests daemon │ │ │ │ WiFi Manage wireless networking │ │ │ │ IR Install IR support │ │ │ │ BT install Install Bluetooth support │ │ │ │ Advanced Edit /etc/network/interfaces │ │ │ └────────────────────────────────────────────────────────────────┘ │ ├────────────────────────────────────────────────────────────────────┤ │ < OK > <Cancel> │ └────────────────────────────────────────────────────────────────────┘

Use the cursor keys to highlight WiFi, then press Tab to get to the < OK > button and press the space bar or the Enter key to go on.

┌───────────────────────────────────────────────┐ │ │ │ ┌──────────────────────────────┐ │ │ │ Wired ↑ │ <Activate> │ │ │ Wired connection 1 ▒ │ │ │ │ ▒ │ │ │ │ Wi-Fi ▒ │ │ │ │ MY_SSID *** ▒ │ │ │ │ WELCOME! * ▒ │ │ │ │ ▒ │ │ │ │ ▮ │ │ │ │ ↓ │ <Quit> │ │ └──────────────────────────────┘ │ │ │ └───────────────────────────────────────────────┘

Use the cursor keys to highlight the name of the local Wi-Fi network, in this case MY_SSID, then press the Enter key to enter the password.

┌───────┤ Authentication required by wireless network ├────────┐ │ │ │ Passwords or encryption keys are required to access the │ │ wireless network 'MY_SSID'. │ │ │ │ Password ______________________________ │ │ │ │ <Cancel> <OK> │ │ │ └──────────────────────────────────────────────────────────────┘

Once the password has been entered activate the <OK> button and the Authentication window will close and a connection will be attempted. Once the Connecting... pop-up is no longer displayed, select the network name again and if there is no * appearing to the left of the name, use Tab to highlight <Activate> and space bar or the Enter key. Finally, once the connection to the Wi-Fi network is established, activate the <Quit> button.

Back in the Wired, Wireless, Bluetooth, Hotspot screen, I chose to Disable IPV6 for APT and system by highlighting and then activating the <OK> button. Now that IPV6 is disabled, the menu entry becomes Enable IPV6 for APT and system.

Press <Cancel>, to return to the main armbian-config menu and select Personal to change the time zone, proceeding much like above. Since the Orange Pi Zero will be used as a headless server, there is no point in changing the keyboard layout, locale and so on. When the basic configuration is completed, press on <Cancel> enough times to back out of the configuration utility.

Check that the wireless interface is up. This is a good time to update all packages.

root@orangepizero:~# ifconfig wlan0 wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.137 netmask 255.255.255.0 broadcast 192.168.1.255 ... root@orangepizero:~# apt update && apt upgrade -y

On January 30, 2019, a total of 22 packages were updated which require downloading 35.4MB from the archives.

As can be seen below, avahi (zero configuration) is not installed, so I chose to install it.

root@orangepizero:~# apt-cache policy avahi-daemon avahi-daemon: Installed: (none) Candidate: 0.6.32-2 Version table: 0.6.32-2 500 500 http://httpredir.debian.org/debian stretch/main armhf Packages root@orangepizero:~# apt install -y avahi-daemon

I did this because I want to be able to connect to the device with a simple command: ssh zero@orangepizero.local without having to look up the IP address. Some would not agree, but the daemon can always be removed later on if a fixed IP is assigned and in the meantime I find it useful. Note that it would not be a good idea to set a fixed IP address at this point; think of the problem if an image with a fixed IP address were copie onto a second Orange Pi Zero.

The last step I undertook was to modify the sudoers configuration file so that the default user would not be constantly asked to supply its password whenever the sudo prefix is used

root@orangepizero:~# nano /etc/sudoers
... # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL zero ALL=(ALL:ALL) NOPASSWD: ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
.

Now there remains to shut down the Orange Pi Zero in an orderly fashion so as to be able to resize the partition and copy the image on the desktop computer.

root@orangepizero:~# shutdown now

With the Orange Pi Zero, it is easy to spot when everything is stopped; the green LED above the microSD card goes off.

Save the Modified OS Image toc

Insert the modified microSD card into a reader connected to a Linux box and start GParted. The latter is not installed by default on Ubuntu so I used the software library to install. After the utility has scanned all the storage drives connected to the computer, which can take some time, select the microSD card containing the modified Armbian image. It was /dev/sde on my machine and very easy to find as all the other drives were much bigger than it.

/dev/sde in GParted

Right click on its ext4 partition, the only partition, and select unmount in the menu if you see a keys icon to the right of the partition. Gparted will again read the information, and the keys icon will no longer be visible. Select the ext4 partition again, and click on the resize icon which is the orange arrow pointing right. The Partition/Resize Move menu selection could be used instead.

resizing /dev/sde1

I chose to set the partition size to 2044 MiB. Given that there was 4 MiB not allocated ahead of the partition, that made for an image size of 2 GiB on the dot with 826.73 MiB free.

resizing /dev/sde1

Click on apply button (with the green check icon) and let Gparted do its thing. All that remains is to copy the first 2 GiB from the microSD card into an image file. This is easily done with the dd utility. The partition should not be mounted, but if it is then un mount it as shown below before saving it.

michel@hp:~/Téléchargements/OS/Armbian$ df -h Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur udev 5,9G 0 5,9G 0% /dev ... /dev/sde1 2,0G 931M 1015M 48% /media/michel/9cecf84e-027e-40ad-b711-ae5d323d9043 michel@hp:~/Téléchargements/OS/Armbian$ sudo umount /dev/sde1 if found with df -h as above michel@hp:~/Téléchargements/OS/Armbian$ sudo dd bs=4M count=512 if=/dev/sde of=armbian_2019-01-30.img

Usage toc

There is not much to using this customized image. Copy it to an microSD card with Etcher. Once that is done, just insert the microSD card in the Orange Pi Zero card reader and power it up. The initial boot of the Orange Pi Zero can take a very long time, many minutes, so be patient. Eventually, it will be possible to reach it over a wireless connection.

michel@hp:~$ ssh zero@orangepizero.local zero@orangepizero.local's password: xyxyxy not echoed to the screen. You did save that password right? ___ ____ _ _____ / _ \ _ __ __ _ _ __ __ _ ___ | _ \(_) |__ /___ _ __ ___ | | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | | / // _ \ '__/ _ \ | |_| | | | (_| | | | | (_| | __/ | __/| | / /| __/ | | (_) | \___/|_| \__,_|_| |_|\__, |\___| |_| |_| /____\___|_| \___/ |___/ Welcome to ARMBIAN 5.73 stable Debian GNU/Linux 9 (stretch) 4.19.17-sunxi System load: 0.18 0.11 0.07 Up time: 8 min Memory usage: 12 % of 493MB IP: 192.168.1.137 CPU temp: 42°C Usage of /: 48% of 2.0G [ General system configuration (beta): armbian-config ] New to Armbian? Check the documentation first: https://docs.armbian.com

Reboots will be much faster. Note how the partition is 2 GiB in size and slightly more than half is free.

Packages should also be upgraded with the usual commands.

zero@orangepizero:~ sudo apt update && sudo apt upgrade -y

As time goes on, this will take ever longer and it could become worthwhile to save the updated image as shown in the previous section for future use.

It is a very good idea to change the host name immediately using armbian-config. Otherwise, avahi will assign a different name to a second Orange Pi Zero on which this same image has been copied because of the common orangepizero host name. It will be harder to open an SSH session.

<-Creating a Custom Raspbian Image (in French) --