Unattended Boot and Install: Difference between revisions
Line 142: | Line 142: | ||
└── default | └── default | ||
└── local -> /etc/init.d/local | └── local -> /etc/init.d/local | ||
}} | |||
{{Cat|headless.start| | |||
<nowiki>#!/bin/sh | |||
__clean_up() | |||
{ | |||
rc-update del local | |||
rm /etc/local.d/headless.start | |||
} | |||
__config_net() | |||
{ | |||
if [ ${ssid} ] | |||
then | |||
for dev in /sys/class/net/* | |||
do | |||
if [ -e "${dev}"/wireless -o -e "${dev}"/phy80211 ] | |||
then | |||
iface="${dev##*/}" | |||
fi | |||
done | |||
apk add wpa_supplicant | |||
cat <<-EOF > /etc/wpa_supplicant/wpa_supplicant.conf | |||
ap_scan=1 | |||
autoscan=periodic:10 | |||
disable_scan_offload=1 | |||
network={ | |||
ssid="${ssid}" | |||
psk="${psk}" | |||
} | |||
EOF | |||
rc-service wpa_supplicant start | |||
else | |||
iface="eth0" | |||
fi | |||
cat <<-EOF > /etc/network/interfaces | |||
auto lo | |||
iface lo inet loopback | |||
auto ${iface} | |||
iface ${iface} inet dhcp | |||
EOF | |||
rc-service networking start | |||
} | |||
__enable_ssh() | |||
{ | |||
setup-sshd -c openssh | |||
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig | |||
echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config | |||
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config | |||
rc-service sshd restart | |||
mv /etc/ssh/sshd_config.orig /etc/ssh/sshd_config | |||
} | |||
__login_root() | |||
{ | |||
cat <<-EOF > /root/.profile | |||
rm -f /root/.profile | |||
if [ -e ${ovlpath}/unattended.sh ] && [ \$(tty) = /dev/tty7 ] | |||
then | |||
source ${ovlpath}/unattended.sh | |||
fi | |||
EOF | |||
openvt -s -c 7 -- /bin/login -f root | |||
} | |||
ovlpath=$(find /media -name *.apkovl.tar.gz -exec dirname {} \;) | |||
read ssid psk < "${ovlpath}/wifi.txt" | |||
__config_net | |||
__enable_ssh | |||
__clean_up | |||
__login_root</nowiki> | |||
}} | }} |
Revision as of 01:00, 30 April 2022
This material is work-in-progress ... Do not follow instructions here until this notice is removed. |
Introduction
This wiki describes a modified version of the original method I posted for Headless installation on a Raspberry Pi. While the original version worked for other architectures, like x86_64, it was targeted at and posted in the Raspberry Pi section since that was my primary focus at the time. Revisions to that page by other authors removed the mention of x86_64 altogether so this version will be more generally written in the hopes that it will be easier to find and that it's applicability will be clearer.
Additionally, this version improves upon the original (in my opinion) by automatically logging in the root user and optionally running a shell script. This provides a means to perform unattended installations or other scripted tasks and does not require modification of the stock Alpine installation media / files.
The following functionality is provided:
- Automatic DHCP configuration of a network interface, either wired or wireless
- Automatic configuration of sshd with password-less root login enabled
- Automatic login of the root user on tty7
- Automatic script execution (optional)
This is accomplished by using an overlay file that Alpine extracts at boot. Download a pre-built overlay file here.
Basic Use
For Alpine supported Raspberry Pi models:
- Download the applicable Alpine installation tarball and extract it to an SD card formatted with a single FAT partition.
- Copy the headless.apkovl.tar.gz file to the root of the SD card.
- Optionally, create a file named wifi.txt in the root of the SD card. See below for file format.
- Optionally, create a file named unattended.sh in the root of the SD card. See below for an example.
- Boot the Pi with the SD card.
For other architectures (tested on various x86_64 hardware and a Qemu VM)
- Download the applicable Alpine installation file and write it to usb stick or other media as needed.
- Copy the headless.apkovl.tar.gz file to a second usb stick or other media separate from the installation media.
- Optionally, create a file named wifi.txt in the root of second media. See below for file format.
- Optionally, create a file named unattended.sh in the root of the second media. See below for an example.
- Boot the device with both the installation and the secondary media connected.
For basic interactive ssh access, only the headless.apkovl.tar.gz file is required. The wifi.txt file can be omitted if wired ethernet is used. The unattended.sh file can be omitted.
Wifi Support
Create a text file named wifi.txt with the SSID and Password on the first line of the file:
SSID Password
Example Scripts
If a shell script named unattended.sh is found in the root of the same media that contains the headless.apkovl.tar.gz file, it will be executed (sourced) by the root user after the auto login occurs on tty7. This can be used to script the installation of Alpine to local disk for example. Note too, that since network is available, the unattended.sh script can also just fetch and execute another script from the local network or internet, if available.
I've experimented with different installation scripts. The first is derived from the setup-alpine script. It skips the sshd and network interface setup scripts as they are already configured and running.
Contents of unattended.sh
The next one creates an answer file and runs setup-alpine. Note that sshd and network interface setup are included this time, even though they are both already up. It seems to work but not without complaint. More experimentation is required.
Contents of unattended.sh
The third is like the second except without the separate answer file and using cat to set the INTERFACEOPTS variable based on the interface currently in use.
Contents of unattended.sh
The above scripts need to be improved, tested, and tailored for your own use. Edits welcome!
Overlay File Reference
The headless.apkovl.tar.gz file has the following structure:
└── etc ├── .default_boot_services ├── local.d │ └── headless.start └── runlevels └── default └── local -> /etc/init.d/local
Contents of headless.start