Add update-initrd(8).

This commit is contained in:
Jonas 'Sortie' Termansen 2015-09-25 14:57:11 +02:00
parent caf632ccdd
commit 391680a468
6 changed files with 190 additions and 34 deletions

View File

@ -25,6 +25,7 @@ sf \
sh \
tix \
trianglix \
update-initrd \
utils \
kernel
@ -66,38 +67,6 @@ install: sysroot
done; \
fi
cp -RTv "$(SYSROOT)" "$(INSTALL_ROOTFS)"
@if test -n '$(INSTALL_ROOTFS_UUID)'; then \
echo '$(INSTALL_ROOTFS_UUID)' > "$(INSTALL_ROOTFS)/etc/rootfs.uuid"; \
SYSROOT="$(SYSROOT)" $(MAKE) create-install-rootfs-initrd; \
else \
echo "Warning: INSTALL_ROOTFS_UUID was not set"; \
echo "Therefore: /etc/rootfs.uuid was not created"; \
echo "Therefore: No initrd was created and installed"; \
fi
.PHONY: create-install-rootfs-initrd
create-install-rootfs-initrd:
ifeq ($(BUILD_IS_SORTIX),0)
@if test -z '$(INSTALL_ROOTFS)' || test 'x$(INSTALL_ROOTFS)' = 'x/'; then \
echo "error: Refusing to create an initrd for the local non-Sortix operating system" >&2; \
exit 1; \
fi
endif
mkdir -p "$(INSTALL_ROOTFS)/boot"
rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/sbin"
test ! -e "$(INSTALL_ROOTFS)/bin/fsck.ext2" || \
cp "$(INSTALL_ROOTFS)/bin/fsck.ext2" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin/fsck.ext2"
cp "$(INSTALL_ROOTFS)/sbin/extfs" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/sbin/extfs"
cp "$(INSTALL_ROOTFS)/sbin/init" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/sbin/init"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init"
cp "$(INSTALL_ROOTFS)/etc/fstab" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/fstab"
echo chain > "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init/target"
mkinitrd --format=sortix-initrd-2 "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" -o "$(INSTALL_ROOTFS)/boot/sortix.initrd"
rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
.PHONY: sysmerge
sysmerge: sysroot

View File

@ -37,6 +37,7 @@ system, run as root:
cd /src
make # build new operating system in /src/sysroot
make sysmerge # upgrade current operating system with /src/sysroot
update-initrd # update boot initrd with new files
.Ed
.Pp
The build system creates a minimal root filesystem structure in the
@ -57,6 +58,15 @@ configuration files and other things that could cause conflicts when merging
with an existing system. The new user-space is running on completition, though
existing processes will be running the old programs. Likewise a reboot is needed
to run the new kernel.
.Pp
The
.Xr update-initrd 8
program regenerates the
.Xr initrd 7
by embedding configuration and programs from the root filesystem. It needs to
be run when init system files,
.Xr fstab 5 ,
filesystem drivers, or filesystem checkers are modified.
.Ss Root Makefile
The
.Pa /src/Makefile
@ -257,4 +267,5 @@ formal online release.
.Sh SEE ALSO
.Xr make 1 ,
.Xr cross-development 7 ,
.Xr porting-guide 7
.Xr porting-guide 7 ,
.Xr update-initrd 8

View File

@ -20,9 +20,16 @@ The initrd is in the custom format made by
.Xr mkinitrd 8
and can be viewed with
.Xr initrdfs 8 .
.Pp
The
.Xr update-initrd 8
program creates a minimal initrd that locates the root filesystem and chain
boots it as described in
.Xr init 8 .
.Sh SEE ALSO
.Xr initrd 7 ,
.Xr kernel 7 ,
.Xr init 8 ,
.Xr initrdfs 8 ,
.Xr mkinitrd 8
.Xr mkinitrd 8 ,
.Xr update-initrd 8

14
update-initrd/Makefile Normal file
View File

@ -0,0 +1,14 @@
include ../build-aux/platform.mak
include ../build-aux/dirs.mak
all:
.PHONY: all install clean
clean:
install: all
mkdir -p $(DESTDIR)$(SBINDIR)
install update-initrd $(DESTDIR)$(SBINDIR)
mkdir -p $(DESTDIR)$(MANDIR)/man8
install update-initrd.8 $(DESTDIR)$(MANDIR)/man8/update-initrd.8

94
update-initrd/update-initrd Executable file
View File

@ -0,0 +1,94 @@
#!/bin/sh -e
################################################################################
#
# Copyright(C) Jonas 'Sortie' Termansen 2015.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
# update-initrd
# Generate a mkinitrd that locates and chain boots the real root filesystem.
#
################################################################################
show_version() {
cat << EOF
$0 (Sortix)
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
exit 0
}
show_help() {
cat << EOF
Usage: $0 [OPTION]...
Generate a mkinitrd that locates and chain boots the real root filesystem.
Configuration:
--help display this help and exit
--version display version information and exit
--sysroot=DIR operate on this root filesystem [/]
EOF
exit 0
}
sysroot=
dashdash=
previous_option=
for argument do
if test -n "$previous_option"; then
eval $previous_option=\$argument
previous_option=
continue
fi
case $argument in
*=?*) parameter=$(expr "X$argument" : '[^=]*=\(.*\)') ;;
*=) parameter= ;;
*) parameter=yes ;;
esac
case $dashdash$argument in
--) dashdash=yes ;;
--sysroot=*) sysroot=$parameter ;;
--sysroot) previous_option=sysroot ;;
--help) show_help ;;
--version) show_version ;;
-*) echo "$0: unrecognized option $argument" >&2
$option_checking && exit 1 ;;
*) echo "$0: unexpected operand $argument" >&2
exit 1 ;;
esac
done
if [ ! -e "$sysroot/etc/fstab" ]; then
echo "$0: $sysroot/etc/fstab: Need a filesystem table to make an initrd" >&2
exit 1
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT HUP INT QUIT TERM
mkdir "$tmp/bin"
mkdir "$tmp/sbin"
cp "$sysroot/sbin/init" "$tmp/sbin"
cp "$sysroot/sbin/extfs" "$tmp/sbin"
test -f "$sysroot/sbin/fsck.ext2" &&
cp "$sysroot/sbin/fsck.ext2" "$tmp/sbin"
mkdir "$tmp/etc"
cp "$sysroot/etc/fstab" "$tmp/etc/fstab"
mkdir "$tmp/etc/init"
echo chain > "$tmp/etc/init/target"
mkdir -p "$sysroot/boot"
mkinitrd --format=sortix-initrd-2 "$tmp" -o "$sysroot/boot/sortix.initrd" > /dev/null

View File

@ -0,0 +1,61 @@
.Dd $Mdocdate: October 6 2015 $
.Dt UPDATE-INITRD 8
.Os
.Sh NAME
.Nm update-initrd
.Nd generate initialization ramdisk
.Sh SYNOPSIS
.Nm update-initrd
.Op Fl \-sysroot Ns "=" Ns Ar sysroot
.Sh DESCRIPTION
.Nm update-initrd
generates the
.Pa /boot/sortix.initrd
.Xr initrd 7
containing a minimal system that searches for the root filesystem and chain
boots it as described in
.Xr initrd 7
and
.Xr init 8 .
It contains an init system, fsck, filesystem drivers and configuration.
.Pp
The produced minimal system contains copies of
.Xr fstab 5 ,
.Xr extfs 8 ,
.Xr fsck.ext2 8 ,
and
.Xr init 8 .
If any of those files are updated then the
.Xr initrd 7
should be regenerated by invoking
.Nm .
.Pp
The options are as follows:
.Bl -tag -width "12345678"
.It Fl \-sysroot Ns "=" Ns Ar sysroot
Rather than generating an
.Xr initrd 7
for the root filesystem, locate files in the
.Ar sysroot
directory instead and store the result as
.Ar sysroot Ns Pa /etc/sortix.initrd .
.El
.Sh FILES
.Bl -tag -width "/sbin/fsck.ext2" -compact
.It Pa /etc/fstab
.It Pa /sbin/extfs
.It Pa /sbin/fsck.ext2
.It Pa /sbin/init
.El
.Sh EXIT STATUS
.Nm
will exit 0 on success and non-zero otherwise.
.Sh SEE ALSO
.Xr fstab 5 ,
.Xr initrd 7 ,
.Xr disked 8 ,
.Xr extfs 8 ,
.Xr init 8 ,
.Xr initrdfs 8 ,
.Xr mkinitrd 8 ,
.Xr update-grub 8