Commit f52fb320 authored by Jonas Termansen's avatar Jonas Termansen

Add sysinstall(8), sysmerge(8), and sysupgrade(8).

parent 8af81a18
......@@ -24,6 +24,7 @@ mkinitrd \
regress \
sf \
sh \
sysinstall \
tix \
trianglix \
update-initrd \
......@@ -67,37 +68,13 @@ SYSTEM_INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).system.initrd
.PHONY: all
all: sysroot
.PHONY: install
install: sysroot
@if test -z '$(INSTALL_ROOTFS)' ; then \
echo "error: You must set INSTALL_ROOTFS to where you want Sortix installed" >&2; \
exit 1; \
fi
@if test -d '$(INSTALL_ROOTFS)' && test -z '$(STUPIDLY_FORCE_SORTIX_INSTALL_OVERWRITE)'; then \
for ENTRY in $$(ls -A "$(SYSROOT)"); do \
if test -e "$(INSTALL_ROOTFS)/$$ENTRY"; then \
echo "Error: Refusing to corrupt the existing installation at $(INSTALL_ROOTFS)" >&2; \
echo "Use sysmerge to update an existence installation." >&2; \
exit 1; \
fi; \
done; \
fi
cp -RTv "$(SYSROOT)" "$(INSTALL_ROOTFS)"
.PHONY: sysmerge
sysmerge: sysroot
ifeq ($(BUILD_IS_SORTIX),0)
if test -z '$(DESTDIR)' || test 'x$(DESTDIR)' = 'x/'; then \
echo "error: Refusing to corrupt the local operating system by sysmerging it with Sortix" >&2 \
exit 1 \
fi
endif
for ENTRY in $$(ls -A "$(SYSROOT)" | grep -Ev '^(dev|etc|home|mnt|root|src|tix|tmp|var)$$'); do \
cp -RTv "$(SYSROOT)/$$ENTRY" "$(DESTDIR)/$$ENTRY" || exit $$?; \
done
cp -TPv "$(SYSROOT)/etc/machine" "$(DESTDIR)/etc/machine"
cp -TPv "$(SYSROOT)/etc/os-release" "$(DESTDIR)/etc/os-release"
cp -TPv "$(SYSROOT)/etc/sortix-release" "$(DESTDIR)/etc/sortix-release"
"$(SYSROOT)/sbin/sysmerge" "$(SYSROOT)"
.PHONY: sysmerge-wait
sysmerge-wait: sysroot
"$(SYSROOT)/sbin/sysmerge" --wait "$(SYSROOT)"
.PHONY: clean-build-tools
clean-build-tools:
......
......@@ -138,3 +138,5 @@ EOF
}
menuentry "live environment" ''
menuentry "new installation" '--init="/sbin/init --target=sysinstall"'
menuentry "upgrade existing installation" '--init="/sbin/init --target=sysupgrade"'
You can view the documentation for new users by typing:
man user-guide
You can view the installation instructions by typing:
man installation
......@@ -43,6 +43,10 @@ otherwise. Supported targets are:
.It chain
mount real root filesystem and run its
.Nm
.It chain-merge
complete a
.Xr sysmerge 8
upgrade during a chain boot
.It multi-user
boot to
.Xr login 8
......@@ -173,4 +177,5 @@ exits with the same exit status as its target session if it terminates normally.
.Xr initrd 7 ,
.Xr kernel 7 ,
.Xr login 8 ,
.Xr sysmerge 8 ,
.Xr update-initrd 8
......@@ -765,6 +765,16 @@ static int init(const char* target)
activate_terminal = true;
program = shell;
}
if ( !strcmp(target, "sysinstall") )
{
activate_terminal = true;
program = "sysinstall";
}
if ( !strcmp(target, "sysupgrade") )
{
program = "sysupgrade";
activate_terminal = true;
}
if ( activate_terminal )
{
tio.c_cflag |= CREAD;
......@@ -868,16 +878,40 @@ static int init_chain(const char* target)
fatal("chroot: %s: %m", chain_location);
if ( chdir("/") < 0 )
fatal("chdir: %s: %m", chain_location);
(void) target;
unsetenv("INIT_PID");
const char* argv[] = { "init", NULL };
execv("/sbin/init", (char* const*) argv);
fatal("Failed to load chain init: %s: %m", argv[0]);
if ( !strcmp(target, "chain-merge") )
{
const char* argv[] = { "sysmerge", "--booting", NULL };
execv("/sysmerge/sbin/sysmerge", (char* const*) argv);
fatal("Failed to run automatic update: %s: %m", argv[0]);
}
else
{
unsetenv("INIT_PID");
const char* argv[] = { "init", NULL };
execv("/sbin/init", (char* const*) argv);
fatal("Failed to load chain init: %s: %m", argv[0]);
}
}
int status;
if ( waitpid(child_pid, &status, 0) < 0 )
fatal("waitpid");
const char* back = ": Trying to bring it back up again";
if ( !strcmp(target, "chain-merge") )
{
if ( WIFEXITED(status) && WEXITSTATUS(status) == 0 )
{
target = "chain";
continue;
}
if ( WIFEXITED(status) )
fatal("Automatic upgrade failed: Exit status %i",
WEXITSTATUS(status));
else if ( WIFSIGNALED(status) )
fatal("Automatic upgrade failed: %s",
strsignal(WTERMSIG(status)));
else
fatal("Automatic upgrade failed: Unexpected unusual termination");
}
if ( WIFEXITED(status) )
{
result = WEXITSTATUS(status);
......@@ -990,17 +1024,20 @@ int main(int argc, char* argv[])
fclose(target_fp);
}
else
target = "single-user";
fatal("Refusing to initialize because %s doesn't exist", target_path);
}
if ( getenv("INIT_PID") )
fatal("System is already managed by an init process");
if ( !strcmp(target, "single-user") ||
!strcmp(target, "multi-user") )
!strcmp(target, "multi-user") ||
!strcmp(target, "sysinstall") ||
!strcmp(target, "sysupgrade") )
return init(target);
if ( !strcmp(target, "chain") )
if ( !strcmp(target, "chain") ||
!strcmp(target, "chain-merge") )
return init_chain(target);
fatal("Unknown initialization target `%s'", target);
......
.Dd $Mdocdate: January 4 2016 $
.Dt UPGRADE.CONF 5
.Os
.Sh NAME
.Nm upgrade.conf
.Nd upgrade configuration
.Sh SYNOPSIS
.Nm /etc/upgrade.conf
.Sh DESCRIPTION
The
.Nm upgrade.conf
controls the actions taken by
.Xr sysupgrade 8
during a system upgrade as described in
.Xr upgrade 7 .
The file allows customizing whether the system itself is replaced, whether new
ports are installed, whether the new source code is installed and what happens
to the old source code. It also records information about the system such as
how the system is booted. The file is created automatically by
.Xr sysinstall 8
as part of
.Xr installation 7
to match what was installed.
.Pp
Developers may wish to customize what happens to
.Pa /src
on a system upgrade. The new source code can be installed or not. If it is
installed, it can be installed in
.Pa /newsrc
or by default in
.Pa /src .
Any existing source code will be safely moved inside a subdirectory of
.Pa /oldsrc .
.Pp
It is possible to disable any upgrading whatsoever. If you do this, except the
new source code is installed, then you can upgrade to the new system manually as
described in
.Xr development 7 .
Upgrading to the next release from source is not supported.
.Sh FORMAT
The file is read line by line. The # character starts a comment and the rest of
the line is ignored. Lines are supposed to contain assignments to variables. An
assignment is the name of the variable, whitespace, an equal character,
whitespace, the value, whitespace, and then the end of the line.
.Bl -tag -width "12345678"
.It Sy grub Ns "=" Ns Oo Sy no "|" yes Oc (default Sy no ) .
States GRUB is used as the bootloader. If either the
.Sy system
or
.Sy ports
are set to
.Sy yes ,
then the bootloader is reinstalled
.Xr ( grub-install 8 )
and updated
.Xr ( update-grub 8 ) .
.It Sy newsrc Ns "=" Ns Oo Sy no "|" yes Oc (default Sy no ) .
Place the new source code in
.Pa /newsrc
and move any existing
.Pa /newsrc
into
.Pa /oldsrc .
This preserves the current
.Pa /src
directory. This takes precedence over and disables the behavior described under
.Sy src .
.It Sy ports Ns "=" Ns Oo Sy no "|" yes Oc (default Sy yes ) .
Install the new ports.
.It Sy src Ns "=" Ns Oo Sy no "|" yes Oc (default Sy no ) .
Place the new source code in
.Pa /src
and move any existing
.Pa /src
into
.Pa /oldsrc .
.It Sy system Ns "=" Ns Oo Sy no "|" yes Oc (default Sy yes ) .
Install the new system. This will run
.Xr update-initrd 8
and if
.Sy grub
is set to
.Sy no ,
then regenerate
.Pa /etc/grub.d/10_sortix.cache .
.El
.Pp
The defaults will be used if
.Pa /etc/upgrade.conf
is missing.
.Sh FILES
.Bl -tag -width "/etc/upgrade.conf" -compact
.It Pa /etc/upgrade.conf
Upgrade configuration.
.El
.Sh EXAMPLES
.Bd -literal
system = yes
ports = yes
src = no
grub = yes
.Ed
.Sh SEE ALSO
.Xr upgrade 7 ,
.Xr sysupgrade 8
......@@ -39,7 +39,6 @@ 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
......@@ -55,20 +54,22 @@ The
.Sy sysmerge
make target ensures a system is built in
.Pa /src/sysroot
and then uses it to replace the current operating system. It ignores
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
and then runs the
.Xr sysmerge 8
program which installs the new system files onto the existing system. It
updates the system manifest as well all ports installed in the sysroot. 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.
is automatically regenerated using
.Xr update-initrd 8 .
The bootloader, if enabled in
.Xr upgrade.conf 5 ,
is reinstalled and configured as necessary. The new user-space is running on
completion, though existing processes will be running the old programs.
A reboot is needed to run the new kernel. If the ABI changed and the current
kernel isn't able to run the new programs, then the upgrade is delayed and will
be automatically completed on the next boot. The
.Sy sysmerge-wait
make target forces waiting until the next boot.
.Ss Root Makefile
The
.Pa /src/Makefile
......@@ -112,6 +113,10 @@ and place it in the current directory as
Upgrade the current operating system using the sysroot after making the
.Sy all
target.
.It Sy sysmerge-wait
Like
.Sy sysmerge
but delay the upgrade until the next boot.
.It Sy sysroot-base-headers
Create the sysroot and install only the headers of the standard library and
kernel into it. This is useful when bootstrapping the runtime libraries of the
......@@ -314,6 +319,10 @@ formal online release.
.Xr git 1 ,
.Xr make 1 ,
.Xr cross-development 7 ,
.Xr installation 7 ,
.Xr porting-guide 7 ,
.Xr serial-transfer 7 ,
.Xr upgrade 7 ,
.Xr sysinstall 8 ,
.Xr sysmerge 8 ,
.Xr update-initrd 8
......@@ -6,7 +6,7 @@
.Nd layout of filesystems
.Sh DESCRIPTION
The filesystem hierarchy is as follows:
.Bl -tag -width "12345678"
.Bl -tag -width "12345678910"
.It Pa /
Root directory.
.It Pa /bin
......@@ -38,6 +38,10 @@ System programs.
Architecture independent files.
.It Pa /src
System source code.
.It Pa /sysmerge
Temporary area for
.Xr sysmerge 8
delayed upgrades.
.It Pa /tix
Package management
.It Pa /tmp
......
This diff is collapsed.
.Dd $Mdocdate: January 5 2016 $
.Dt UPGRADE 7
.Os
.Sh NAME
.Nm upgrade
.Nd operating system upgrade instructions
.Sh DESCRIPTION
This document describes how to upgrade an existing Sortix installation to a
newer release. The
.Xr installation 7
manual page covers creating a new installation.
.Ss Prerequisites
You need to prepare a bootable medium with the new release as described in
.Xr installation 7 .
Read all the instructions up to Bootloader Menu and continue with this document.
.Pp
It is not possible to skip releases. If you want to upgrade to a release, you
must upgrade first to all releases before that one. If the existing installation
is a development snapshot, you must either upgrade to a newer development
snapshot of that version, or a the final release of that version.
.Ss Bootloader Menu
Pick the
.Li upgrade existing installation
option in the bootloader menu to begin the upgrade. This will load a live
environment set to automatically run the
.Xr sysupgrade 8
program.
.Ss Upgrader
This guide assumes you selected the upgrade option in the bootloader. If not,
you can run the installer by running the
.Xr sysupgrade 8
command.
.Pp
The upgrader is an interactive command line program that asks you questions and
you answer them. It provides useful information you shouldn't accidentally
overlook. Before answering any question, read all output since your last
answer.
.Pp
You should have this upgrade guide ready at all times. You can view this
.Xr upgrade 7
page during the installation by answering
.Sy '!man'
to any regular prompt (excluding password prompts). Likewise you can answer
.Sy '!'
to get an interactive shell. Upon completion, you will be asked the question
again.
.Ss Keyboard Layout
You need to choose the applicable keyboard layout. By default, a standard US
keyboard layout is used. You can view a list of keyboard layouts if you wish.
.Ss Display Resolution
If a driver exists for your graphics card, then you will be asked for your
preferred display resolution by
.Xr chvideomode 1 .
.Ss Installation Search
The upgrader will search for existing Sortix installations by probing local
filesystems for
.Pa /etc/sortix-release .
You will be asked which installation you wish to upgrade. Enter the name of the
root filesystem device. If none are found, it asks if you want to run
.Xr sysinstall 8 . Filesystems will be repaired by
.Xr fsck 8
as needed.
.Ss Confirmation
The upgrader will warn you if it detects you are not following proper upgrade
procedure either by downgrading or by skipping a release, neither of which is
supported. It will also warn you if it detects an ABI downgrade.
.Pp
The upgrade will load the upgrade preferences from
.Pa /etc/upgrade.conf
file of the target system as described in
.Xr upgrade.conf 5 .
.Pp
The new release may have a new ABI. A major ABI change means the new kernel
will be unable to properly execute old programs. A minor ABI change means the
new kernel has new compatible features and will be able to run older programs,
but older kernels will not be able to run programs using the new ABI.
.Pp
A confirmation screen will tell you what actions the upgrader plan on doing.
Answer
.Sy yes
to proceed with the upgrade. Otherwise you can escape to a shell, edit
.Xr upgrade.conf 5 ,
return and answer
.Sy no
and the upgrader will reload the configuration.
.Ss Upgrade
The upgrader will take the appropriate actions:
.Pp
.Bl -bullet -compact
.It
Updating the system.
.It
Updating the ports.
.It
Updating the source code.
.It
Updating the initrd.
.It
Updating the bootloader.
.El
.Ss Completion
The upgrade is now complete. The new system will run after a reboot. The
upgrader will give you an overview of what it has done. If you upgraded across
a major ABI change, then you will be told that you need to recompile all local
programs to use the new ABI.
.Pp
Congratulations on your freshly upgraded Sortix system.
.Sh SEE ALSO
.Xr chkblayout 1 ,
.Xr chvideomode 1 ,
.Xr man 1 ,
.Xr development 7 ,
.Xr initrd 7 ,
.Xr installation 7 ,
.Xr kernel 7 ,
.Xr user-guide 7 ,
.Xr sysinstall 8 ,
.Xr sysupgrade 8 ,
.Xr update-grub 8 ,
.Xr update-initrd 8
......@@ -9,8 +9,13 @@ Sortix is a small self-hosting Unix-like operating system developed since 2011.
This document covers matters relevant to new users from other Unix-like
operating systems.
.Ss Introduction
You will be presented a with standard Unix command line environment upon booting
the live environment.
The installation process is covered in
.Xr installation 7 .
Bootable cdrom releases will offer the options of running a live environment,
installing the operating system, or upgrading an existing installation.
.Pp
You will be presented a with standard Unix command line environment upon login or
booting the live environment.
.Ss Shutdown
.Xr init 8
spawns a session after boot. This is
......@@ -125,4 +130,6 @@ but it is becoming feasible to build a large number of them natively.
.Sh SEE ALSO
.Xr cross-development 7 ,
.Xr development 7 ,
.Xr serial-transfer 7
.Xr installation 7 ,
.Xr serial-transfer 7 ,
.Xr upgrade 7
sysinstall
sysmerge
sysupgrade
*.o
SOFTWARE_MEANT_FOR_SORTIX=1
include ../build-aux/platform.mak
include ../build-aux/compiler.mak
include ../build-aux/version.mak
include ../build-aux/dirs.mak
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
CFLAGS?=$(OPTLEVEL)
CFLAGS:=$(CFLAGS) -Wall -Wextra
CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\"
MAIN_OBJS=\
sysinstall.o \
sysmerge.o \
sysupgrade.o \
UTIL_OBJS=\
conf.o \
devices.o \
execute.o \
fileops.o \
interactive.o \
manifest.o \
release.o \
OBJS=$(MAIN_OBJS) $(UTIL_OBJS)
SYSINSTALL_DEPS=devices execute fileops interactive manifest
SYSMERGE_DEPS=conf fileops execute manifest release
SYSUPGRADE_DEPS=conf devices execute fileops interactive manifest release
SYSINSTALL_OBJS:=sysinstall.o $(SYSINSTALL_DEPS:=.o)
SYSMERGE_OBJS:=sysmerge.o $(SYSMERGE_DEPS:=.o)
SYSUPGRADE_OBJS:=sysupgrade.o $(SYSUPGRADE_DEPS:=.o)
all: sysinstall sysmerge sysupgrade
.PHONY: all install clean
install: all
mkdir -p $(DESTDIR)$(SBINDIR)
install sysinstall $(DESTDIR)$(SBINDIR)
install sysmerge $(DESTDIR)$(SBINDIR)
install sysupgrade $(DESTDIR)$(SBINDIR)
mkdir -p $(DESTDIR)$(MANDIR)/man8
install sysinstall.8 $(DESTDIR)$(MANDIR)/man8/sysinstall.8
install sysmerge.8 $(DESTDIR)$(MANDIR)/man8/sysmerge.8
install sysupgrade.8 $(DESTDIR)$(MANDIR)/man8/sysupgrade.8
sysinstall: $(SYSINSTALL_OBJS)
$(CC) $(SYSINSTALL_OBJS) -o $@ -lmount
sysmerge: $(SYSMERGE_OBJS)
$(CC) $(SYSMERGE_OBJS) -o $@ -lmount
sysupgrade: $(SYSUPGRADE_OBJS)
$(CC) $(SYSUPGRADE_OBJS) -o $@ -lmount
%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -std=gnu11 -c $< -o $@
sysinstall.o: $(SYSINSTALL_DEPS:=.h)
sysmerge.o: $(SYSMERGE_DEPS:=.h)
sysupgrade.o: $(SYSUPGRADE_DEPS:=.h)
conf.o: conf.h
devices.o: devices.h
execute.o: execute.h
fileops.o: fileops.h
interactive.o: interactive.h execute.h
manifest.o: manifest.h execute.h fileops.h
release.o: release.h
clean:
rm -f sysinstall sysmerge sysupgrade $(OBJS)
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2015, 2016.
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/>.
conf.c
Utility functions to handle upgrade.conf(5).
*******************************************************************************/
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
static bool conf_boolean(const char* name, const char* value, const char* path)
{
if ( !strcmp(value, "yes") )
return true;
if ( !strcmp(value, "no") )
return false;
printf("%s: %s: Expected yes or no instead of unsupported value\n",
path, name);
return false;
}
static void conf_assign(struct conf* conf,
const char* name,
const char* value,
const char* path)
{
if ( !strcmp(name, "grub") )
conf->grub = conf_boolean(name, value, path);
else if ( !strcmp(name, "newsrc") )
conf->newsrc = conf_boolean(name, value, path);
else if ( !strcmp(name, "ports") )
conf->ports = conf_boolean(name, value, path);
else if ( !strcmp(name, "src") )
conf->src = conf_boolean(name, value, path);
else if ( !strcmp(name, "system") )
conf->system = conf_boolean(name, value, path);
else
printf("%s: %s: Unsupported variable\n", path, name);
}
void load_upgrade_conf(struct conf* conf, const char* path)
{
memset(conf, 0, sizeof(*conf));
conf->ports = true;
conf->system = true;
FILE* fp = fopen(path, "r");
if ( !fp )
{
if ( errno == ENOENT )
return;
err(2, "%s", path);
}
char* line = NULL;
size_t line_size = 0;
ssize_t line_length;
while ( 0 < (errno = 0, line_length = getline(&line, &line_size, fp)) )
{
if ( line[line_length - 1] == '\n' )
line[--line_length] = '\0';
line_length = 0;
while ( line[line_length] && line[line_length] != '#' )
line_length++;
line[line_length] = '\0';
while ( line_length && isblank((unsigned char) line[line_length - 1]) )
line[--line_length] = '\0';
char* name = line;
while ( *name && isblank((unsigned char) *name) )
name++;
if ( !*name || *name == '=' )
continue;
size_t name_length = 1;
while ( name[name_length] &&
!isblank((unsigned char) name[name_length]) &&
name[name_length] != '=' )
name_length++;
char* value = name + name_length;
while ( *value && isblank((unsigned char) *value) )
value++;
if ( *value != '=' )
continue;
value++;
while ( *value && isblank((unsigned char) *value) )
value++;
name[name_length] = '\0';
conf_assign(conf, name, value, path);
}
if ( errno )
err(2, "%s", path);
free(line);
fclose(fp);
}
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2015, 2016.
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/>.
conf.h
Utility functions to handle upgrade.conf(5).
*******************************************************************************/
#ifndef CONF_H
#define CONF_H
struct conf
{
bool grub;
bool newsrc;
bool ports;
bool src;
bool system;
};
void load_upgrade_conf(struct conf* conf, const char* path);
#endif
This diff is collapsed.
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2015, 2016.
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.