Skip to content

Commit 9872873

Browse files
authored
Merge pull request #49 from macmpi/dev
Version 1.4
2 parents d8fbe8d + e636e9c commit 9872873

13 files changed

+92
-90
lines changed

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
11
# Bootstrap Alpine Linux on a headless system
22

3-
[Alpine Linux documentation](https://docs.alpinelinux.org/user-handbook/0.1a/Installing/setup_alpine.html) assumes **initial setup** is carried-out on a system with a keyboard & display to interract with.\
3+
[Alpine Linux documentation](https://docs.alpinelinux.org/user-handbook/0.1a/Installing/setup_alpine.html) assumes **initial setup** is carried-out on a system with a keyboard & display.\
44
However, in many cases one might want to deploy a headless system that is only available through a network connection (ethernet, wifi or as USB ethernet gadget).
55

6-
This repo provides an **overlay file** to initially bootstrap[^1] a headless system (leveraging Alpine distro's `initramfs` feature): it starts a ssh server to log-into from another Computer, so that actual install on fresh system (or rescue on existing disk-based system) can then be performed remotely.\
6+
This repo provides an **overlay file** to initially bootstrap[^1] such headless system (leveraging Alpine distro's `initramfs` feature): it starts a ssh server to log-into from another Computer, so that actual install on fresh system (or rescue on existing disk-based system[^2]) can then be performed remotely.\
77
An optional script may also be launched during that same initial bootstrap, to perform fully automated setup.
88

99

1010
## Setup procedure:
1111
Please follow [Alpine Linux Wiki](https://wiki.alpinelinux.org/wiki/Installation#Installation_Overview) to download & create installation media for the target platform.\
1212
Tools provided here can be used on any hardware platform to prepare for any install modes (diskless, data disk, system disk).
1313

14-
Just add [**headless.apkovl.tar.gz**](https://is.gd/apkovl_master)[^2] overlay file *as-is* at the root of Alpine Linux boot media (or onto any custom side-media) and boot-up the system.\
14+
Just add [**headless.apkovl.tar.gz**](https://is.gd/apkovl_master) overlay file *as-is* at the root of Alpine Linux boot media (or onto any custom side-media) and boot-up the system.\
1515
With default DCHP-based network interface definitions (and [SSID/pass](#extra-configuration) file if using wifi), system can then be remotely accessed with: `ssh root@<IP>`\
1616
(system IP address may be determined with any IP scanning tools such as `nmap`).
1717

1818
As with Alpine Linux initial bring-up, `root` account has no password initially.\
19-
From there, actual system install can be performed as usual with `setup-alpine` for instance (check [wiki](https://wiki.alpinelinux.org/wiki/Alpine_setup_scripts#setup-alpine) for details).
19+
From there, actual system install can be performed as usual with `setup-alpine` for instance (check Alpine [wiki](https://wiki.alpinelinux.org/wiki/Alpine_setup_scripts#setup-alpine) for details).
2020

2121
## Extra configuration:
2222
Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapping configuration (check sample files):
23-
- `wpa_supplicant.conf`[^3] (*mandatory for wifi usecase*): define wifi SSID & password.
23+
- `wpa_supplicant.conf`[^3] (*mandatory for wifi*): define wifi SSID, password and regulatory country [code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
2424
- `unattended.sh`[^3] (*optional*): provide a deployment script to automate setup & customizations during initial bootstrap.
2525
- `interfaces`[^3] (*optional*): define network interfaces at will, if defaults DCHP-based are not suitable.
2626
- `authorized_keys` (*optional*): provide client's public SSH key to secure `root` ssh login.
27-
- `ssh_host_*_key*` (*optional*): provide server's custom ssh keys to be injected (may be stored), instead of using bundled ones[^2] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
27+
- `ssh_host_*_key*` (*optional*): provide server's custom ssh keys to be injected (may be stored), instead of using bundled ones[^4] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
2828
- `opt-out` (*optional*): dummy file to opt-out internet features (connection status, version check, auto-update) and related links usage anonymous [telemetry](https://is.gd/privacy.php).
2929
- `auto-updt` (*optional*): enable automatic `headless.apkovl.tar.gz` file update with latest from master branch. If it contains `reboot` keyword all in one line, system will reboot after succesful update (unless ssh session is active or `unattended.sh` script is available).
3030

3131
Main execution steps are logged: `cat /var/log/messages | grep headless`.
3232

3333
## Goody:
34-
Seamless USB-gadget mode: serial console, ethernet and mass-storage (*e.g. on PiZero*), leveraging [xg_multi](https://github.com/macmpi/xg_multi/).
35-
- Make sure `dwc2` (or `dwc3`) driver is previously loaded on device, and configuration is set to **OTG peripheral** mode: this may be driven by hardware (including cable) and/or software.\
34+
Seamless USB-gadget mode on capable devices (*e.g. on PiZero*): serial console, ethernet and mass-storage
35+
- Make sure `dwc2` (or `dwc3`) driver is previously loaded on capable device, and configuration is set to **OTG peripheral** mode: this may be driven by hardware (including cable) and/or software.\
3636
(on supporting Pi devices, just add `dtoverlay=dwc2,dr_mode=peripheral` in `usercfg.txt` (or `config.txt`) to force both by software)
37-
- Plug USB cable into host Computer port before boot.\
38-
-- serial terminal can then be connected-to from host Computer (e.g. `cu -l ttyACM0` on Linux. xon/xoff flow control).\
39-
-- alternatively, with host Computer ECM/RNDIS interface set-up as 10.42.0.1 (sharing internet or not), one can log into device from host with: `ssh [email protected]`.\
40-
-- volume containing `headless.apkovl.tar.gz` file may be accessed/mounted from host, and config files easily edited. Make sure to unmount properly before removing USB plug.
41-
42-
[^1]: Initial boot fully preserves system's original state (config files & installed packages): a fresh system will therefore come-up as unconfigured.
43-
44-
[^2]: About bundled ssh keys: this overlay is meant to **quickly bootstrap** system in order to then proceed with proper install; therefore it purposely embeds [some ssh keys](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.trash) so that bootstrapping is as fast as possible. Those temporary keys are moved in RAM /tmp: they will **not be stored/reused** once actual system install is performed (whether or not ssh server is installed in final setup).
45-
46-
[^3]: These files are linux text files: Windows/macOS users need to use text editors supporting linux text line-ending (such as [notepad++](https://notepad-plus-plus.org/), BBEdit or any similar).
37+
- Plug USB cable into host Computer port before booting device.
38+
- serial terminal can then be connected-to from host Computer (e.g. `cu -l ttyACM0` on Linux. xon/xoff flow control).
39+
- alternatively, with host Computer ECM/RNDIS interface set-up as 10.42.0.1 (sharing internet or not), one can log into device from host with: `ssh [email protected]`.
40+
- volume containing `headless.apkovl.tar.gz` file may be accessed/mounted from host, and config files easily edited. Make sure to unmount properly before removing USB plug.
4741

42+
_Note:_ optionally, same USB-gadget feature may be easily enabled on final system by installing `xg_multi` Alpine [package](https://pkgs.alpinelinux.org/packages?name=xg_multi&branch=edge&repo=&arch=&origin=&flagged=&maintainer=) and service during system setup phase (refer to [`xg_multi`](https://github.com/macmpi/xg_multi/) project).
4843

4944
## Want to tweak more ?
5045
This repository may be forked/cloned/downloaded.\
51-
Main script file is [`headless_bootstrap`](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/usr/local/bin/headless_bootstrap).\
52-
Execute `./make.sh` to rebuild `headless.apkovl.tar.gz` after changes.\
46+
Main script file is [`headless_bootstrap`](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB/headless_bootstrap).\
47+
Execute `./make_ALHB.sh` to rebuild `headless.apkovl.tar.gz` after changes.\
5348
(requires `busybox`; check `busybox` build options if not running from Alpine or Ubuntu)
5449

5550

5651
## Credits
5752
Thanks for the initial guides & scripts from @sodface and @davidmytton.
53+
54+
[^1]: Initial boot fully preserves system's original state (config files & installed packages): a fresh system will therefore come-up as unconfigured.
55+
56+
[^2]: Temporarily remove `root=*` statement from kernel command-line parameters list to disable disk-based boot mode.
57+
58+
[^3]: These files are linux text files: Windows/macOS users need to use text editors supporting linux text line-ending (such as [notepad++](https://notepad-plus-plus.org/), BBEdit or any similar).
59+
60+
[^4]: About bundled ssh keys: this overlay is meant to **quickly bootstrap** system in order to then proceed with proper install; therefore it purposely embeds [some ssh keys](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/tmp/.ALHB) so that bootstrapping is as fast as possible. Those temporary keys are moved in RAM /tmp: they will **not be stored/reused** once actual system install is performed (whether or not ssh server is installed in final setup).

headless.apkovl.tar.gz

700 Bytes
Binary file not shown.

headless.apkovl.tar.gz.sha512

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7d72e7a46066aebb0572f1431d6e9f354b3d0df4fce0a05090c1667f68738e876c195460d294a0c279c86d02b65d101625ed9c86a1f465c2f2f29ee59bdde5fa headless.apkovl.tar.gz
1+
0e29b7d2488c97b144c39a76ca3c0793fbc96e18e6e1c1947896144c9ac38b16ace717208d639d23859d764703c2e7f6e41f7b269f78072b98ac8ce866f1c8a9 headless.apkovl.tar.gz

make.sh renamed to make_ALHB.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ if [ -n "$build_path" ]; then
1818
# prefer timestamp option for touch as it works on directories too
1919
t_stamp="$( TZ=UTC date +%Y%m%d0000.00 )"
2020
cp -a overlay "$build_path"/.
21-
cp xg_multi/xg_multi "$build_path"/overlay/usr/local/bin/.
21+
cp -a LICENSE "$build_path"/overlay/tmp/ALHB_LICENSE
22+
cp -a xg_multi/xg_multi "$build_path"/overlay/tmp/.ALHB/.
2223
find "$build_path"/overlay/ -exec sh -c 'TZ=UTC touch -chm -t "$0" "$1"' "$t_stamp" {} \;
2324
# setting modes and owner/groups for runtime (won't affect mtime)
2425
find "$build_path"/overlay/etc -type d -exec chmod 755 {} \;
2526
chmod 755 "$build_path"/overlay/etc/init.d/*
2627
chmod 755 "$build_path"/overlay/etc/runlevels/default/*
2728
chmod 777 "$build_path"/overlay/tmp
28-
chmod 700 "$build_path"/overlay/tmp/.trash
29-
chmod -R 600 "$build_path"/overlay/tmp/.trash/ssh_host_*_key
30-
find "$build_path"/overlay/usr -type d -exec chmod 755 {} \;
31-
chmod 755 "$build_path"/overlay/usr/local/bin/*
29+
chmod 644 "$build_path"/overlay/tmp/ALHB_LICENSE
30+
chmod 700 "$build_path"/overlay/tmp/.ALHB
31+
chmod 755 "$build_path"/overlay/tmp/.ALHB/*
32+
chmod 600 "$build_path"/overlay/tmp/.ALHB/ssh_host_*_key
33+
chmod 644 "$build_path"/overlay/tmp/.ALHB/ssh_host_*_key.pub
3234
doas chown -Rh 0:0 "$build_path"/overlay/*
3335

3436
# busybox config on Alpine & Ubuntu has FEATURE_TAR_GNU_EXTENSIONS

overlay/etc/init.d/headless_bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
description="Headless main boostrappring script"
77
name="Headless bootstrap"
88

9-
command="/usr/local/bin/headless_bootstrap"
9+
command="/tmp/.ALHB/headless_bootstrap"
1010
command_background=true
1111
pidfile="/run/${RC_SVCNAME}.pid"
1212

overlay/etc/init.d/headless_cleanup

Lines changed: 0 additions & 12 deletions
This file was deleted.

overlay/etc/init.d/headless_unattended

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)