Add cdrom mounting live environment.

This commit is contained in:
Jonas 'Sortie' Termansen 2022-11-02 00:57:13 +01:00
parent c0bd144d66
commit 4204813d9b
4 changed files with 116 additions and 13 deletions

View File

@ -72,10 +72,13 @@ else
SORTIX_INCLUDE_SOURCE?=yes SORTIX_INCLUDE_SOURCE?=yes
endif endif
ISO_MOUNT?=no
include build-aux/dirs.mak include build-aux/dirs.mak
BUILD_NAME:=sortix-$(RELEASE)-$(MACHINE) BUILD_NAME:=sortix-$(RELEASE)-$(MACHINE)
CHAIN_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).chain.initrd
LIVE_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).live.initrd LIVE_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).live.initrd
OVERLAY_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).overlay.initrd OVERLAY_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).overlay.initrd
SRC_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).src.initrd SRC_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).src.initrd
@ -450,6 +453,24 @@ release-all-archs:
# Initial ramdisk # Initial ramdisk
$(CHAIN_INITRD).uuid:
mkdir -p `dirname $@`
uuidgen > $@
$(CHAIN_INITRD): $(CHAIN_INITRD).uuid sysroot
mkdir -p `dirname $(CHAIN_INITRD)`
rm -rf $(CHAIN_INITRD).d
mkdir -p $(CHAIN_INITRD).d
mkdir -p $(CHAIN_INITRD).d/etc
echo "UUID=`cat $(CHAIN_INITRD).uuid` / iso9660 ro 0 1" > $(CHAIN_INITRD).d/etc/fstab
mkdir -p $(CHAIN_INITRD).d/etc/init
echo require chain exit-code > $(CHAIN_INITRD).d/etc/init/default
mkdir -p $(CHAIN_INITRD).d/sbin
cp "$(SYSROOT)/sbin/init" $(CHAIN_INITRD).d/sbin
cp "$(SYSROOT)/sbin/iso9660fs" $(CHAIN_INITRD).d/sbin
mkinitrd --format=sortix-initrd-2 $(CHAIN_INITRD).d -o $(CHAIN_INITRD)
rm -rf $(CHAIN_INITRD).d
$(LIVE_INITRD): sysroot $(LIVE_INITRD): sysroot
mkdir -p `dirname $(LIVE_INITRD)` mkdir -p `dirname $(LIVE_INITRD)`
rm -rf $(LIVE_INITRD).d rm -rf $(LIVE_INITRD).d
@ -496,6 +517,42 @@ $(SORTIX_BUILDS_DIR):
# Bootable images # Bootable images
ifeq ($(ISO_MOUNT),yes)
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(CHAIN_INITRD) $(CHAIN_INITRD).uuid $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot
cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin
cp $(CHAIN_INITRD) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc
echo "UUID=`cat $(CHAIN_INITRD).uuid` / iso9660 ro 0 1" > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/fstab
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/init
echo require single-user exit-code > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/init/default
echo "root::0:0:root:/root:sh" > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/passwd
echo "include /etc/default/passwd.d/*" >> $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/passwd
echo "root::0:root" > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/group
echo "include /etc/default/group.d/*" >> $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/group
(echo 'channel = $(CHANNEL)' && \
echo 'release_key = $(RELEASE_KEY)' && \
echo 'release_sig_url = $(RELEASE_SIG_URL)') > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/etc/upgrade.conf
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/home
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/root -m 700
cp -RT "$(SYSROOT)/etc/skel" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/root
(echo "You can view the documentation for new users by typing:" && \
echo && \
echo " man user-guide" && \
echo && \
echo "You can view the installation instructions by typing:" && \
echo && \
echo " man installation") > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/root/welcome
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/grub
build-aux/iso-grub-cfg.sh --platform $(HOST) --version $(VERSION) --mount $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
grub-mkrescue -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso sysroot $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso -- -volid Sortix -volset_id `cat $(CHAIN_INITRD).uuid`
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
else
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(LIVE_INITRD) $(OVERLAY_INITRD) $(SRC_INITRD) $(SYSTEM_INITRD) $(SORTIX_BUILDS_DIR) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(LIVE_INITRD) $(OVERLAY_INITRD) $(SRC_INITRD) $(SYSTEM_INITRD) $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
@ -536,6 +593,8 @@ else # none
endif endif
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
endif
.PHONY: iso .PHONY: iso
iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso

View File

@ -23,8 +23,9 @@ set -e
this=$(which -- "$0") this=$(which -- "$0")
thisdir=$(dirname -- "$this") thisdir=$(dirname -- "$this")
platform=
directory= directory=
mount=false
platform=
version= version=
dashdash= dashdash=
@ -44,8 +45,9 @@ for argument do
case $dashdash$argument in case $dashdash$argument in
--) dashdash=yes ;; --) dashdash=yes ;;
--platform=*) platform=$parameter ;;
--platform) previous_option=platform ;; --platform) previous_option=platform ;;
--platform=*) platform=$parameter ;;
--mount) mount=true ;;
--version=*) version=$parameter ;; --version=*) version=$parameter ;;
--version) previous_option=version ;; --version) previous_option=version ;;
-*) echo "$0: unrecognized option $argument" >&2 -*) echo "$0: unrecognized option $argument" >&2
@ -111,13 +113,23 @@ isinset() {
cd "$directory" cd "$directory"
kernel=$(maybe_compressed boot/sortix.bin) kernel=$(maybe_compressed boot/sortix.bin)
live_initrd=$(maybe_compressed boot/live.initrd) if $mount; then
overlay_initrd=$(maybe_compressed boot/overlay.initrd) initrd=$(maybe_compressed boot/sortix.initrd)
src_initrd=$(maybe_compressed boot/src.initrd) initrds=$initrd
system_initrd=$(maybe_compressed boot/system.initrd) else
ports=$(ls repository | live_initrd=$(maybe_compressed boot/live.initrd)
grep -E '\.tix\.tar\.xz$' | overlay_initrd=$(maybe_compressed boot/overlay.initrd)
sed -E 's/\.tix\.tar\.xz$//') src_initrd=$(maybe_compressed boot/src.initrd)
system_initrd=$(maybe_compressed boot/system.initrd)
initrds="$system_initrd $src_initrd $live_initrd $overlay_initrd"
fi
if $mount; then
ports=
else
ports=$(ls repository |
grep -E '\.tix\.tar\.xz$' |
sed -E 's/\.tix\.tar\.xz$//')
fi
mkdir -p boot/grub mkdir -p boot/grub
mkdir -p boot/grub/init mkdir -p boot/grub/init
@ -183,6 +195,12 @@ fi
set version="$version" set version="$version"
set machine="$machine" set machine="$machine"
set mount=$mount
if \$mount; then
chain='-- /sbin/init --target=chain'
else
chain=
fi
set base_menu_title="Sortix \$version for \$machine" set base_menu_title="Sortix \$version for \$machine"
set menu_title="\$base_menu_title" set menu_title="\$base_menu_title"
set timeout=10 set timeout=10
@ -201,6 +219,8 @@ set enable_sshd=false
export version export version
export machine export machine
export mount
export chain
export base_menu_title export base_menu_title
export menu_title export menu_title
export timeout export timeout
@ -298,9 +318,10 @@ esac
cat << EOF cat << EOF
hook_kernel_pre hook_kernel_pre
echo -n "Loading /$kernel ($(human_size $kernel)) ... " echo -n "Loading /$kernel ($(human_size $kernel)) ... "
multiboot /$kernel \$no_random_seed \$enable_network_drivers "\$@" multiboot /$kernel \$no_random_seed \$enable_network_drivers \$chain "\$@"
echo done echo done
hook_kernel_post hook_kernel_post
# TODO: Injecting configuration doesn't work for mounted cdroms.
if ! \$enable_dhclient; then if ! \$enable_dhclient; then
echo -n "Disabling dhclient ... " echo -n "Disabling dhclient ... "
module /boot/grub/init/furthermore --create-to /etc/init/network module /boot/grub/init/furthermore --create-to /etc/init/network
@ -325,7 +346,7 @@ cat << EOF
echo done echo done
fi fi
EOF EOF
for initrd in $system_initrd $src_initrd $live_initrd $overlay_initrd; do for initrd in $initrds; do
if [ "$initrd" = "$src_initrd" ]; then if [ "$initrd" = "$src_initrd" ]; then
cat << EOF cat << EOF
if \$enable_src; then if \$enable_src; then
@ -421,9 +442,11 @@ menuentry "upgrade existing installation" '-- /sbin/init --target=sysupgrade'
cat << EOF cat << EOF
if ! $mount; then
menuentry "Select ports..." { menuentry "Select ports..." {
configfile /boot/grub/ports.cfg configfile /boot/grub/ports.cfg
} }
fi
menuentry "Advanced..." { menuentry "Advanced..." {
configfile /boot/grub/advanced.cfg configfile /boot/grub/advanced.cfg
@ -455,6 +478,7 @@ else
} }
fi fi
if ! $mount; then
if "\$enable_src"; then if "\$enable_src"; then
menuentry "Disable loading source code" { menuentry "Disable loading source code" {
enable_src=false enable_src=false
@ -466,6 +490,7 @@ else
configfile /boot/grub/advanced.cfg configfile /boot/grub/advanced.cfg
} }
fi fi
fi
if [ "\$enable_network_drivers" = --disable-network-drivers ]; then if [ "\$enable_network_drivers" = --disable-network-drivers ]; then
menuentry "Enable networking drivers" { menuentry "Enable networking drivers" {
@ -479,6 +504,7 @@ else
} }
fi fi
if ! $mount; then
if \$enable_dhclient; then if \$enable_dhclient; then
menuentry "Disable DHCP client" { menuentry "Disable DHCP client" {
enable_dhclient=false enable_dhclient=false
@ -518,6 +544,7 @@ fi
menuentry "Select binary packages..." { menuentry "Select binary packages..." {
configfile /boot/grub/tix.cfg configfile /boot/grub/tix.cfg
} }
fi
hook_advanced_menu_post hook_advanced_menu_post
EOF EOF

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, 2017, 2020, 2021 Jonas 'Sortie' Termansen. * Copyright (c) 2015, 2016, 2017, 2020, 2021, 2022 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -221,3 +221,17 @@ char** read_lines_file(const char* path, size_t* out_count)
*out_count = count; *out_count = count;
return lines; return lines;
} }
// TODO: Hack to support installing from a read-only root filesystem.
#undef mkdtemp
char* mkdtemp_hack(char* templ)
{
if ( mkdtemp(templ) )
return templ;
if ( errno != EROFS )
return NULL;
memcpy(templ + 1, "dev", 3);
mkdir("/dev/tmp", 01777);
setenv("TMPDIR", "/dev/tmp", 1);
return mkdtemp(templ);
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, 2020 Jonas 'Sortie' Termansen. * Copyright (c) 2015, 2016, 2020, 2022 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -28,4 +28,7 @@ void write_random_seed(const char* path);
char* read_string_file(const char* path); char* read_string_file(const char* path);
char** read_lines_file(const char* path, size_t* out_count); char** read_lines_file(const char* path, size_t* out_count);
char* mkdtemp_hack(char* templ);
#define mkdtemp mkdtemp_hack
#endif #endif