Skip to content

Commit 256b90b

Browse files
authored
Merge pull request #19 from macmpi/dev
version 1.0
2 parents e263862 + f430fc3 commit 256b90b

21 files changed

+419
-297
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 macmpi
3+
Copyright (c) 2022-2023 macmpi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,46 @@
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

66
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.\
7-
An optional script may be launched at startup, to perform automated actions/setup.
7+
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 plaform 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 at the root of Alpine Linux boot media (or onto any custom side-media) and boot-up the system.\
15-
With default network interface definitions (and [SSID/pass file](#extra-configuration) if using wifi), system can then be remotely accessed with: `ssh root@<IP>`\
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.\
15+
With default DCHP-based network interface definitions (and [SSID/pass file](#extra-configuration) 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

18-
As with Alpine Linux initial bring-up, `root` account has no password initially (change that during setup!).\
18+
As with Alpine Linux initial bring-up, `root` account has no password initially (change that during target setup!).\
1919
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).
2020

2121
## Extra configuration:
2222
Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapping configuration (check sample files):
2323
- `wpa_supplicant.conf`[^3] (*mandatory for wifi usecase*): define wifi SSID & password.
24+
- `unattended.sh`[^3] (*optional*): provide a deployment script to automate setup & customizations during initial bootstrap.
2425
- `interfaces`[^3] (*optional*): define network interfaces at will, if defaults DCHP-based are not suitable.
2526
- `authorized_keys` (*optional*): provide client's public SSH key to secure `root` ssh login.
2627
- `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-
- `unattended.sh`[^3] (*optional*): create custom automated deployment script to further tune & extend actual setup (backgrounded).
2828

2929

30-
**Goody:** seamless USB-ethernet gadget boostrapping (PiZero for instance):\
31-
On supporting Pi devices, just add `dtoverlay=dwc2` in `usercfg.txt` (or `config.txt`), and plug USB cable into Computer port.\
32-
With Computer set-up to share networking with USB interface as 10.42.0.1 gateway, one can log into device from Computer with: `ssh [email protected]`
30+
**Goody:** seamless USB-serial & USB-ethernet gadget mode (PiZero for instance):\
31+
On supporting Pi devices, just add `dtoverlay=dwc2,dr_mode=peripheral` in `usercfg.txt` (or `config.txt`), and plug USB cable into host Computer port.\
32+
Serial terminal can then be connected-to from host Computer (xon/xoff flow control: e.g. on Linux with `cu -l ttyACM0`).\
33+
Alternatively, with host Computer set-up to share networking with USB interface as 10.42.0.1 gateway, one can log into device from host with: `ssh [email protected]`.
3334

34-
Main execution steps are logged in `/var/log/messages`.
35+
Main execution steps are logged: `cat /var/log/messages | grep headless`.
3536

3637
[^1]: Initial boot fully preserves system's original state (config files & installed packages): a fresh system will therefore come-up as unconfigured.
3738

38-
[^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/etc/ssh) 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).
39+
[^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).
3940

4041
[^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).
4142

4243

4344
## Want to tweak more ?
4445
This repository may be forked/cloned/downloaded.\
45-
Main script file is [`headless.start`](https://github.com/macmpi/alpine-linux-headless-bootstrap/blob/main/overlay/etc/local.d/headless.start).\
46+
Main script file is [`headless.start`](https://github.com/macmpi/alpine-linux-headless-bootstrap/tree/main/overlay/usr/local/bin/headless_bootstrap).\
4647
Execute `./make.sh` to rebuild `headless.apkovl.tar.gz` after changes.
4748

4849

headless.apkovl.tar.gz

1.08 KB
Binary file not shown.

make.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
#!/bin/sh
1+
#!/bin/busybox sh
22

3-
# Copyright 2022 - 2023, macmpi
3+
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
44
# SPDX-License-Identifier: MIT
55

6-
chmod 600 overlay/etc/ssh/ssh_host_*_key
7-
chmod +x overlay/etc/local.d/headless.start
8-
tar czvf headless.apkovl.tar.gz -C overlay etc --owner=0 --group=0
6+
7+
command -v doas > /dev/null || alias doas="/usr/bin/sudo"
8+
9+
build_path="$(mktemp -d)"
10+
if [ -n "$build_path" ]; then
11+
cp -r overlay "$build_path"/.
12+
find "$build_path"/overlay/ -exec touch -md "$(date '+%F 00:00:00')" {} \;
13+
14+
# setting owner/groups for runtime (won't affect mtime)
15+
find "$build_path"/overlay/etc -type d -exec chmod 755 {} \;
16+
chmod +x "$build_path"/overlay/etc/init.d/*
17+
find "$build_path"/overlay/usr -type d -exec chmod 755 {} \;
18+
chmod +x "$build_path"/overlay/usr/local/bin/*
19+
chmod 777 "$build_path"/overlay/tmp
20+
chmod 700 "$build_path"/overlay/tmp/.trash
21+
chmod 600 "$build_path"/overlay/tmp/.trash/ssh_host_*_key
22+
doas chown -R 0:0 "$build_path"/overlay/*
23+
24+
doas tar -cvf "$build_path"/headless.apkovl.tar -C "$build_path"/overlay etc usr tmp
25+
gzip -nk9 "$build_path"/headless.apkovl.tar && mv "$build_path"/headless.apkovl.tar.gz .
26+
touch -md "$(date '+%F 00:00:00')" headless.apkovl.tar.gz
27+
28+
doas rm -rf "$build_path"
29+
fi
30+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/sbin/openrc-run
2+
3+
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
4+
# SPDX-License-Identifier: MIT
5+
6+
description="Headless main boostrappring script"
7+
name="Headless bootstrap"
8+
9+
command="/usr/local/bin/headless_bootstrap"
10+
command_background=true
11+
pidfile="/run/${RC_SVCNAME}.pid"
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/sbin/openrc-run
2+
3+
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
4+
# SPDX-License-Identifier: MIT
5+
6+
description="Headless cleanup script"
7+
name="Headless cleanup"
8+
9+
command="/tmp/.trash/headless_cleanup"
10+
command_background=true
11+
pidfile="/run/${RC_SVCNAME}.pid"
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/sbin/openrc-run
2+
3+
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
4+
# SPDX-License-Identifier: MIT
5+
6+
description="Headless unattended setup script (optional)"
7+
name="Headless unattended"
8+
9+
command="/tmp/headless_unattended"
10+
command_background=true
11+
pidfile="/run/${RC_SVCNAME}.pid"
12+

overlay/etc/local.d/headless.start

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

overlay/etc/modprobe.d/g_ether.conf

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

0 commit comments

Comments
 (0)