diff options
-rwxr-xr-x | bootstrap | 13 | ||||
-rw-r--r-- | doc/manual.cli | 47 | ||||
-rwxr-xr-x | init | 103 |
3 files changed, 154 insertions, 9 deletions
@@ -140,7 +140,7 @@ if [ "$stage" -eq "1" ]; then # # - systemd-container seems to be required by host systemd-nspawn. # - pkgs="locales,systemd-container" + pkgs="locales,klibc-utils,systemd-container" pkgs+=",linux-image-amd64,irqbalance,pciutils" @@ -230,6 +230,7 @@ Build OS 0.5.0 (Based on Debian) \n \l EOF1 cat <<EOF1 >/etc/motd + Welcome to Build OS 0.5.0 (https://build2.org)! EOF1 @@ -382,9 +383,17 @@ fi # # To test PXE boot, replace -kernel/-initrd with '-boot n'. # + +if [ ! -e /tmp/buildos-disk ]; then + qemu-img create -f raw /tmp/buildos-disk 100M +fi + sudo kvm \ -m 8G \ - -netdev 'tap,id=net0,script=./qemu-ifup' \ -device "e1000,netdev=net0,mac=$macaddr" \ + -netdev "tap,id=net0,script=./qemu-ifup" \ + -device "virtio-scsi-pci,id=scsi" \ + -device "scsi-hd,drive=disk1" \ + -drive "if=none,id=disk1,file=/tmp/buildos-disk,format=raw" \ -kernel buildos-image -initrd buildos-initrd \ -append "buildos.smtp_relay=build2.org buildos.admin_email=admin@build.org" diff --git a/doc/manual.cli b/doc/manual.cli index 1140db5..961627e 100644 --- a/doc/manual.cli +++ b/doc/manual.cli @@ -143,4 +143,51 @@ local network and you are using your organization's relay) or because the relay host accepts emails send to the admin address from anyone (which is normally the case if the relay is the final destination for the admin address, for example, \c{example.org} and \c{admin@example.org}). + +\h2#config-storage|Storage| + +Build OS configures storage based on the labels assigned to disks and +partitions (collectively refered to as disks from now on). + +For virtual machine and container storage we can use a single disk, in which +case it should be labeled \c{buildos.machines} or multiple disks, in which +case they should be labeled \c{buildos.machines.<volume>}. In both cases the +disks must be formatted as \c{btrfs}. + +In a single disk configuration, the disk is mounted as \c{/build/machines}. In +a multi-disk configuration, each disk is mounted as +\c{/build/machines/<volume>}. + +If no disks are found for required storage, then the boot process is +interrupted with a shell prompt where you can format and/or lable a suitable +disk. You can also view the storage configuration on a booted Build OS +instance by examining \c{/etc/fstab}. + +As an example, let's consider the first boot of a clean machine that has a 1TB +SSD disk as \c{/dev/sda} and which we would like to use for virtual machine +storage. We would also like to over-provision this SSD by 10% to (potentially) +prolong its life and increase performance (you may want to skip this step if +you are using a datacenter-grade SSD that would normally already be generously +over-provisioned). + +On the first boot we will be presented with a shell prompt which we use to +over-provision the disk: + +\ +# fdisk -l /dev/sda # Query disk information. +# hdparm -N /dev/sda # Query disk/host protection area sizes. +# hdparm -Np<COUNT> /dev/sda # COUNT = sector count * 0.9 +# hdparm -N /dev/sda # Verify disk/host protection area sizes. +# ^D # Exit shell and reboot. +\ + +After the reboot we will be presented with a shell prompt again where we +confirm over-provisioning, format the disk as \c{btrfs}, and label it as +\c{buildos.machines}: + +\ +# fdisk -l /dev/sda # Confirm disk size decreased by 10%. +# mkfs.btrfs -L buildos.machines -m single /dev/sda +# ^D # Exit shell and reboot. +\ " @@ -11,9 +11,23 @@ set -o errtrace # Trap in functions. # Note: diagnostics goes to stdout. # function info () { echo "$*"; } -function error () { info "$*"; exit 1; } +function error () +{ + if [ "$#" -gt 0 ]; then + info "$*"; + fi -export PATH=/sbin:/usr/sbin:/bin:/usr/bin + # The setsid voodoo (take from Debian init's panic()) is to enable job + # control. + # + info "type Ctrl-D to exit shell and reboot" + setsid /bin/bash -c "exec /bin/bash -i <>/dev/tty1 1>&0 2>&1" + reboot +} + +# Some pre-systemd utilities (like reboot) come from klibc-utils. +# +export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/klibc/bin/ # One would expect rootflags=size=1g to work but it doesn't (perhaps init # is expected to interpret it)? @@ -100,6 +114,7 @@ eth_all="$(cd /sys/class/net && ls -d en?*)" if [ -z "$eth_all" ]; then info "no ethernet interfaces found among:" ip link show + error fi eth= @@ -152,13 +167,15 @@ for s in 1 2 4 8; do done if [ -z "$eth_up" ]; then - error "no ethernet interfaces with carrier among:" + info "no ethernet interfaces with carrier among:" ip link show + error fi if [ -z "$eth" ]; then - error "no ethernet interfaces with DHCP among:" + info "no ethernet interfaces with DHCP among:" ip link show + error fi mac="$(cat "/sys/class/net/$eth/address")" @@ -182,7 +199,7 @@ info "hostname $hname" # based on what we have discovered and then let the systemd networking bringup # to configure everything (at which point we will hopefully reuse the lease). # -dhclient -q -x +dhclient -x 2>/dev/null # @@ Need to be make configurable. # @@ -236,15 +253,85 @@ sed -r -i \ -e "s%^(relayhost).*%\1 = $smtp_relay%" \ /etc/postfix/main.cf -# Make admin alias for buildos.admin_email, redirect root to admin. +# Make admin alias for buildos.admin_email, alias root as admin. # cat <<EOF >>/etc/aliases admin: $admin_email root: admin EOF - newaliases +# Figure out disk configuration and generate the corresponding /etc/fstab. +# +fstab=/etc/fstab +#fstab=/dev/stdout + +echo -n '' >$fstab + +l= +machines= +while read l || [ -n "$l" ]; do + d="$(sed -re 's/.*NAME=\"([^\"]+)\".*/\1/' <<<"$l")" + t="$(sed -re 's/.*FSTYPE=\"([^\"]*)\".*/\1/' <<<"$l")" + l="$(sed -re 's/.*LABEL=\"([^\"]*)\".*/\1/' <<<"$l")" + + # Strip the buildos. prefix from the label. If the result is empty then + # this disk/patition hasn't been labeled for use by buildos. + # + l="$(sed -n -re 's/^buildos\.([^ ]+)$/\1/p' <<<"$l")" + + if [ -z "$l" ]; then + continue + fi + + # Handle buildos.machines and buildos.machines.* mounts. + # + if [[ "$l" == "machines" ]] || [[ "$l" =~ "machines.".+ ]]; then + + if [ "$t" != "btrfs" ]; then + error "non-btrfs filesystem on $d labeled with buildos.machines" + fi + + if [ "$l" = "machines" ]; then + # Single mount. + # + if [ -n "$machines" ]; then + error "multiple disks labeled with buildos.machines/machines.*" + fi + + m=/build/machines + machines="single" + else + # Multiple mounts. + # + if [ "$machines" = "single" ]; then + error "multiple disks labeled with buildos.machines/machines.*" + fi + + n="$(sed -n -re 's/^machines\.([^ ]+)$/\1/p' <<<"$l")" + m="/build/machines/$n" + machines="multiple" + fi + + info "mounting $d (buildos.$l) on $m" + + echo mkdir -p "$m" + o="defaults,noatime,nodiratime,user_subvol_rm_allowed" + echo "$d $m btrfs $o 0 0" >>$fstab + fi +done < <(lsblk --pairs --paths --output NAME,FSTYPE,LABEL) +#done <<EOF +#NAME="/dev/sda" FSTYPE="btrfs" LABEL="buildos.machines.vol1" +#NAME="/dev/sdb" FSTYPE="btrfs" LABEL="buildos.machines.vol2" +#EOF + +if [ -z "$machines" ]; then + info "no disks labaled with buildos.machines* among:" + lsblk --paths --output NAME,TYPE,FSTYPE,SIZE,LABEL,UUID + info "consider formatting and/or labelling a suitable disk" + error +fi + /bin/bash # Hand off to systemd. But first arrange to keep console output (which @@ -256,6 +343,8 @@ cat <<EOF >/etc/systemd/system/getty@tty1.service.d/noclear.conf TTYVTDisallocate=no EOF +export PATH=/sbin:/usr/sbin:/bin:/usr/bin + exec /lib/systemd/systemd \ --show-status=1 \ --machine-id="00000000000000000000$mid" \ |