Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from pukkamustard/installer
Browse files Browse the repository at this point in the history
Installer
  • Loading branch information
pukkamustard authored Jul 28, 2018
2 parents ffb03f3 + f2cb268 commit 5e74915
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 0 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This repo contains tools for setting up a computer for usage with Divdat Play.

- `roles/`: Ansible roles
- `utils/`: Utilities
- `installer/`: Bootable installer

## Ansible playbook

Expand Down
39 changes: 39 additions & 0 deletions installer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
out ?= build

# Ubuntu fies
UBUNTU_FILES = $(out)/ubuntu/boot.ipxe $(out)/ubuntu/preseed.cfg

all: $(out)/installer.usb $(out)/boot.ipxe $(UBUNTU_FILES)
install: all

$(out)/installer.usb: $(IPXE_USB)
mkdir -p $(out)
cp $(IPXE_USB) $(out)/installer.usb

# Copy main ipxe script
$(out)/boot.ipxe: boot.ipxe
mkdir -p $(out)
cp boot.ipxe $(out)/boot.ipxe

# Copy Ubuntu boot script and preseed config
$(out)/ubuntu/boot.ipxe: ubuntu/boot.ipxe
mkdir -p $(out)/ubuntu
cp ubuntu/boot.ipxe $(out)/ubuntu/boot.ipxe

$(out)/ubuntu/preseed.cfg: ubuntu/preseed.cfg
mkdir -p $(out)/ubuntu
cp ubuntu/preseed.cfg $(out)/ubuntu/preseed.cfg

# Deploy website to boot.dividat.com
deploy: clean all
aws s3 sync $(out) "s3://boot.dividat.com" --region="eu-central-1" --delete --cache-control max-age=5

.PHONY: qemu
qemu: $(out)/installer.usb
@# Qemu requires write access to disk image
chmod +w $<
qemu-system-x86_64 -hda $<

.PHONY: clean
clean:
rm -rf $(out)
42 changes: 42 additions & 0 deletions installer/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Play Computer Installer

Installer for (as much as possible) automized installation of Ubuntu based system for usage with Dividat Play.

## Overview

The built artifacts are:

- `installer.usb`: A bootable USB image
- `boot.ipxe`: An iPXE script
- `ubuntu/`: Ubuntu specific iPXE script and preseed configuration

The bootable USB image is based on [iPXE](http://ipxe.org/) with an [embeded script](./ipxe/embed.ipxe) that will load the script [`boot.ipxe`](boot.ipxe) which is deployed to <https://boot.dividat.com>.

The script [`boot.ipxe`](boot.ipxe) will present a menu and ask for confirmation to continue with installation. Installation continues by loading the script [`ubuntu/boot.ipxe`](ubuntu/boot.ipxe).

The script [`ubunut/boot.ipxe`](ubuntu/boot.ipxe) downloads and starts an Ubuntu installer with [preseed](https://help.ubuntu.com/lts/installation-guide/s390x/apb.html).

The [preseed configuration](ubuntu/preseed.cfg) will run `ansible-pull` to set up system as play-computer.

## Development

### Prerequisites

- [Nix](https://nixos.org/nix) is required for installing dependencies and providing a suitable development environment.
- Qemu can be used for testing the created boot images

### Quick start

`nix-shell --command make`

### Testing with Qemu

`nix-shell --command 'make clean && make qemu'`

### Deploying to `boot.dividat.com`

`nix-shell --command 'make deploy'`

### Caveats

- The iPXE image is built by Nix as a buildInput to this derivation. If you start a `nix-shell`, make changes to the `ipxe/` folder and run `make` the changes in the `ipxe/` folder will not be picked up. This can be fixed by some Makefile hacking. An easy way out: restart your `nix-shell`. A nicer way: build using `nix-build -o build`. A subsequent `make deploy` will work as `awscli` follows symlinks.
30 changes: 30 additions & 0 deletions installer/boot.ipxe
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!ipxe
###################### boot.dividat.com #############################

:start

###################### MAIN MENU ####################################
isset ${menu-default} || set menu-default install

menu Setup computer for Dividat Play || goto shell
item --gap -- ------------------------- Setup ------------------------------
item install Remove USB stick and continue with setup. WARNING: THIS WILL DELETE ANY DATA ON HARD DRIVE!!!
item --gap -- ------------------------- Other ------------------------------
item shell Drop to iPXE shell
item exit Exit iPXE and continue BIOS boot
item reboot Reboot computer
choose selected && goto ${selected}

:reboot
reboot

:exit
exit

:shell
echo Type 'exit' to get the back to the menu
shell
goto :start

:install
chain --autofree ubuntu/boot.ipxe
27 changes: 27 additions & 0 deletions installer/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
with import <nixpkgs> {};
let
ipxe =
(import ./ipxe {
inherit stdenv fetchgit;
inherit lzma binutils mtools syslinux perl cdrtools;
});
in
stdenv.mkDerivation rec {
name = "play-computer-installer";
buildInputs = [
awscli
];

src = ./.;

shellHook = ''
export IPXE_USB=${ipxe}
# Setup build directory
export out=$(pwd)/build
'';

configurePhase = ''
export IPXE_USB=${ipxe}
'';
}
34 changes: 34 additions & 0 deletions installer/ipxe/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ stdenv, fetchgit
, lzma, binutils, mtools, syslinux, perl, cdrtools
, name ? "ipxe.usb"
}:
stdenv.mkDerivation {
inherit name;

buildInputs = [ lzma binutils mtools syslinux perl cdrtools ];

src = fetchgit {
url = "git://git.ipxe.org/ipxe.git";
rev = "d2063b7693e0e35db97b2264aa987eb6341ae779";
sha256 = "16sv591607v0anap63mw13d6gf4p98hb7w78npv3m041c2gbaldw";
};

hardeningDisable = [
"stackprotector"
];

patches = [
./init-reg.diff
./download-proto-https.diff
./makefile-echo.diff
];

buildPhase = ''
cd src/
make bin/ipxe.usb EMBED=${./embed.ipxe}
'';

installPhase = ''
cp bin/ipxe.usb $out
'';
}
13 changes: 13 additions & 0 deletions installer/ipxe/download-proto-https.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/config/general.h b/src/config/general.h
index 3c14a2cd..8867f152 100644
--- a/src/config/general.h
+++ b/src/config/general.h
@@ -54,7 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#define DOWNLOAD_PROTO_TFTP /* Trivial File Transfer Protocol */
#define DOWNLOAD_PROTO_HTTP /* Hypertext Transfer Protocol */
-#undef DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
+#define DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
#undef DOWNLOAD_PROTO_FTP /* File Transfer Protocol */
#undef DOWNLOAD_PROTO_SLAM /* Scalable Local Area Multicast */
#undef DOWNLOAD_PROTO_NFS /* Network File System Protocol */
5 changes: 5 additions & 0 deletions installer/ipxe/embed.ipxe
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!ipxe

dhcp

chain --autofree https://boot.dividat.com/
13 changes: 13 additions & 0 deletions installer/ipxe/init-reg.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c
index 2cd41d4cab51..fa696694639a 100644
--- a/src/drivers/net/etherfabric.c
+++ b/src/drivers/net/etherfabric.c
@@ -2210,7 +2210,7 @@ falcon_reset_xaui ( struct efab_nic *efab )
static int
falcon_xaui_link_ok ( struct efab_nic *efab )
{
- efab_dword_t reg;
+ efab_dword_t reg = { 0 };
int align_done, lane_status, sync;
int has_phyxs;
int link_ok = 1;
15 changes: 15 additions & 0 deletions installer/ipxe/makefile-echo.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index f8334921..ea9577d4 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -10,8 +10,8 @@
TAB := $(shell $(PRINTF) '\t')
ECHO_E_ECHO := $(ECHO)
ECHO_E_ECHO_E := $(ECHO) -e
-ECHO_E_BIN_ECHO := /bin/echo
-ECHO_E_BIN_ECHO_E := /bin/echo -e
+ECHO_E_BIN_ECHO := echo
+ECHO_E_BIN_ECHO_E := echo -e
ECHO_E_ECHO_TAB := $(shell $(ECHO_E_ECHO) '\t' | cat)
ECHO_E_ECHO_E_TAB := $(shell $(ECHO_E_ECHO_E) '\t' | cat)
ECHO_E_BIN_ECHO_TAB := $(shell $(ECHO_E_BIN_ECHO) '\t')
23 changes: 23 additions & 0 deletions installer/ubuntu/boot.ipxe
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!ipxe


set ubuntu_version artful
set arch amd64
set ubuntu_mirror ch.archive.ubuntu.com

#set kickstart_config http://boot.dividat.com/ubuntu/ks.cfg
#set params ks=${kickstart_config}

set install_params auto=true priority=critical locale=en_US keyboard-configuration/layoutcode=us preseed/url=http://boot.dividat.com/ubuntu/preseed.cfg preseed/interactive=false

set dir ubuntu/dists/${ubuntu_version}/main/installer-${arch}/current/images/netboot/ubuntu-installer/${arch}

echo Loading Ubuntu ${ubuntu_version} ${arch}
kernel http://${ubuntu_mirror}/${dir}/linux ${install_params} ${netcfg} ${mirrorcfg} ${console} -- quiet ${params} initrd=initrd.gz || goto error
initrd http://${ubuntu_mirror}/${dir}/initrd.gz || goto error

boot

:error
echo "Error! Starting shell."
shell
Loading

0 comments on commit 5e74915

Please sign in to comment.