summaryrefslogtreecommitdiff
path: root/README.md
blob: 31ec98c5500226ff107f48d8c5feb56db48d7b07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# craft

`craft` is a minimal build automation tool for Linux.

## Build

Executing the `build.sh` script inside the root of the craft source code will
create the craft Linux executable. Only the `go` tool and a posix shell is
required.

## Usage

Call the `craft` tool like this:

```
./craft -repo https://example.com -commit 8f36088eee1cfbec4ddac4d652101db3b29eed45
```

This will create a temporary directory, clone the repository including
submodules to that location, execute the `build` function from the `craft.sh`
file inside the root of the repo and remove the temporary directory.

Log output is redirected to the calling terminal.

## Build Arch Linux guest virtual machine for builds

Craft will use a QEMU virtual machine to execute build processes. The following
commands can be used to create an Arch Linux based virtual machine suitable for
this purpose.

It is expected that the Arch Linux installation image file
(`archlinux-2024.02.01-x86_64.iso`) or a symbolic link to it is present in the
root of the craft repository.

```
# create virtual machine disk file and boot with installation media
qemu-img create -f qcow2 vms/archlinux.qcow2 30G
qemu-system-x86_64 \
    -enable-kvm \
    -m 4G \
    -nic user,model=virtio \
    -drive file=vms/archlinux.qcow2,media=disk,if=virtio \
    -smp cpus=4 \
    -nographic \
    -cdrom archlinux-2024.02.01-x86_64.iso

# press TAB in bootloader menu and append ` console=ttyS0` to kernel args

# check if time is synchronized
timedatectl

# create partitions and file systems
parted /dev/vda --script mklabel msdos
parted /dev/vda --script mkpart primary 1MiB 2GiB
parted /dev/vda --script set 1 boot on
parted /dev/vda --script mkpart primary 2GiB 100%
mkfs.vfat -n BOOT /dev/vda1
mkfs.btrfs -L ROOT /dev/vda2

# mount root and boot partition
mount /dev/vda2 /mnt
mount --mkdir /dev/vda1 /mnt/boot

# install Arch Linux packages
pacstrap -K /mnt \
    base \
    linux \
    linux-firmware \
    syslinux \
    btrfs-progs \
    networkmanager \
    chrony \
    nano \
    neovim \
    htop \
    which \
    openssh \
    rsync \
    base-devel \
    git \
    go

# system configuration
genfstab -L /mnt >> /mnt/etc/fstab
arch-chroot /mnt
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
locale-gen
echo 'LANG=en_US.UTF-8' > /etc/locale.conf
echo 'craft-archlinux' > /etc/hostname
mkinitcpio -P
echo 'root' | passwd -s
systemctl enable NetworkManager
systemctl enable chronyd
sed -i 's|#PermitRootLogin prohibit-password|PermitRootLogin yes|g' /etc/ssh/sshd_config
systemctl enable sshd

# bootloader installation
mkdir -p /boot/syslinux
cp /usr/lib/syslinux/bios/*.c32 /boot/syslinux/
extlinux --install /boot/syslinux
dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/bios/mbr.bin of=/dev/vda
sed -i 's|root=/dev/sda3 rw|root=/dev/vda2 rw console=ttyS0|g' /boot/syslinux/syslinux.cfg

exit
poweroff
```

## Start Arch Linux virtual machine for automated builds

The following command starts the Arch Linux QEMU virtual machine in a read-only
mode (`snapshot=on`) to prevent altering the original image file.

Furthermore the local port 22 of the VM is forwarded to the localhost port 9999
of the host. Thus clients on the host can use SSH to connect to the VM.

Again no graphical display is used and only output of the serial console is
shown in the terminal. Since the `console=ttyS0` kernel parameter was set in
the bootloader configuration of the VM, no manual editing of kernel parameters
during runtime is needed (in contrast to the current Arch Linux installation
image).

```
qemu-system-x86_64 \
    -enable-kvm \
    -m 4G \
    -net nic,model=virtio -net user,hostfwd=tcp:127.0.0.1:9999-:22 \
    -drive file=vms/archlinux.qcow2,media=disk,snapshot=on,if=virtio \
    -smp cpus=4 \
    -nographic
```

## Use SSH to log into guest virtual machine

Since the SSH server of the guest VM is available to the host on localhost port
9999 it is possible to use the `ssh` command to log into the VM from the host
using the password set in image creation with the `passwd` command.

```
ssh \
    -p 9999 \
    -o UserKnownHostsFile=/dev/null \
    -o StrictHostKeyChecking=no \
    root@localhost
```