Skip to content

Commit

Permalink
Added upgrade instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabbenD committed Sep 17, 2023
1 parent 0e30623 commit 5b6f159
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 24 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This serves to demonstrates how to:
2. Partition and prepare UEFI/GPT disks for a minimal OSTree host system
3. Generate OSTree repository in a empty filesystem
4. Integrate OSTree with GRUB2 bootloader
5. Upgrade existing installation with a rootfs image

# Usage

Expand Down Expand Up @@ -44,3 +45,11 @@ This serves to demonstrates how to:
$ chmod +x ostree.sh
$ sudo OSTREE_DEV_SCSI=scsi-360022480c22be84f8a61b39bbaed612f ./ostree.sh install
```

5. **Upgrade existing installation:**

While booted into a OSTree system, use:

```console
$ sudo ./ostree.sh upgrade
```
82 changes: 58 additions & 24 deletions ostree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ set -x
set -u
set -e

# [ENVIRONMENT]: REQUIRED
# OSTREE_DEV_SCSI=
# [ENVIRONMENT]: OPTIONS
function ENV_OPTS_CREATE {
# Required
# - OSTREE_DEV_SCSI (for install)

# [ENVIRONMENT]: CONFIGURABLE
export OSTREE_DEV_DISK=/dev/disk/by-id/${OSTREE_DEV_SCSI}
export OSTREE_DEV_BOOT=${OSTREE_DEV_DISK}-part1
export OSTREE_DEV_HOME=${OSTREE_DEV_DISK}-part2
export OSTREE_DEV_ROOT=${OSTREE_DEV_DISK}-part3
export OSTREE_SYS_ROOT=/mnt
export OSTREE_SYS_BUILD=/tmp/rootfs
# Configurable
export OSTREE_DEV_DISK=${OSTREE_DEV_DISK:=/dev/disk/by-id/${OSTREE_DEV_SCSI}}
export OSTREE_DEV_BOOT=${OSTREE_DEV_BOOT:=${OSTREE_DEV_DISK}-part1}
export OSTREE_DEV_HOME=${OSTREE_DEV_HOME:=${OSTREE_DEV_DISK}-part2}
export OSTREE_DEV_ROOT=${OSTREE_DEV_ROOT:=${OSTREE_DEV_DISK}-part3}
export OSTREE_SYS_ROOT=${OSTREE_SYS_ROOT:=/mnt}
export OSTREE_SYS_BUILD=${OSTREE_SYS_BUILD:=/tmp/rootfs}
}

# [ENVIRONMENT]: DEPENDENCIES
# | Todo: add persistent Pacman cache
function ENV_DEPS_CREATE {
# Skip in OSTree as filesystem is read-only
if ! grep -q ostree /proc/cmdline; then
pacman --noconfirm --needed -S $@
fi
}

# [DISK]: PARTITIONING (GPT+UEFI)
function DISK_CREATE_LAYOUT {
pacman --noconfirm --needed -S parted
ENV_DEPS_CREATE parted
umount --lazy --recursive ${OSTREE_SYS_ROOT} || :
parted -a optimal -s ${OSTREE_DEV_DISK} -- \
mklabel gpt \
Expand All @@ -28,7 +40,7 @@ function DISK_CREATE_LAYOUT {

# [DISK]: FILESYSTEM (ESP+EXT4)
function DISK_CREATE_FORMAT {
pacman --noconfirm --needed -S dosfstools e2fsprogs
ENV_DEPS_CREATE dosfstools e2fsprogs
mkfs.vfat -n SYS_BOOT -F 32 ${OSTREE_DEV_BOOT}
mkfs.ext4 -L SYS_ROOT -F ${OSTREE_DEV_ROOT}
mkfs.ext4 -L SYS_HOME -F ${OSTREE_DEV_HOME}
Expand All @@ -42,21 +54,20 @@ function DISK_CREATE_MOUNTS {

# [OSTREE]: INITIALIZATION
function OSTREE_CREATE_REPO {
pacman --noconfirm --needed -S ostree wget which
ENV_DEPS_CREATE ostree wget which
ostree admin init-fs --sysroot=${OSTREE_SYS_ROOT} --modern ${OSTREE_SYS_ROOT}
ostree admin os-init --sysroot=${OSTREE_SYS_ROOT} archlinux
ostree init --repo=${OSTREE_SYS_ROOT}/ostree/repo --mode=bare
ostree config --repo=${OSTREE_SYS_ROOT}/ostree/repo set sysroot.bootprefix 'true'
}

# [OSTREE]: CONTAINER
# | Todo: add persistent Pacman cache
# | Todo: delete /etc in Contailerfile (https://github.com/containers/podman/issues/20001)
# | Todo: use tar format (`podman build -f Containerfile -o dest=${OSTREE_SYS_BUILD}.tar,type=tar`)
function OSTREE_CREATE_IMAGE {
# Add support for overlay storage driver in LiveCD
if [[ $(df --output=fstype / | tail -n 1) = "overlay" ]]; then
pacman --noconfirm --needed -S "fuse-overlayfs"
ENV_DEPS_CREATE fuse-overlayfs
export TMPDIR="/tmp/podman"
PODMAN_ARGS=(
--root ${TMPDIR}/storage
Expand All @@ -65,7 +76,7 @@ function OSTREE_CREATE_IMAGE {
fi

# Create rootfs directory (workaround: `podman build --output local` doesn't preserve ownership)
pacman --noconfirm --needed -S podman
ENV_DEPS_CREATE podman
podman ${PODMAN_ARGS[@]} build -f Containerfile -t rootfs
rm -rf ${OSTREE_SYS_BUILD}
mkdir ${OSTREE_SYS_BUILD}
Expand All @@ -86,7 +97,7 @@ function OSTREE_DEPLOY_IMAGE {
function BOOTLOADER_CREATE {
grub-install --target=x86_64-efi --efi-directory=${OSTREE_SYS_ROOT}/boot/efi --removable --boot-directory=${OSTREE_SYS_ROOT}/boot/efi/EFI --bootloader-id=archlinux ${OSTREE_DEV_BOOT}

export OSTREE_SYS_PATH=$(ls -d ${OSTREE_SYS_ROOT}/ostree/deploy/archlinux/deploy/*|head -n 1)
export OSTREE_SYS_PATH=$(ls -d ${OSTREE_SYS_ROOT}/ostree/deploy/archlinux/deploy/* | head -n 1)

rm -rfv ${OSTREE_SYS_PATH}/boot/*
mount --mkdir --rbind ${OSTREE_SYS_ROOT}/boot ${OSTREE_SYS_PATH}/boot
Expand All @@ -98,13 +109,36 @@ function BOOTLOADER_CREATE {
umount -R ${OSTREE_SYS_ROOT}
}

# Tasks to perform
DISK_CREATE_LAYOUT
DISK_CREATE_FORMAT
DISK_CREATE_MOUNTS
# [CLI]: TASKS FINECONTROL
case ${1:-} in
"install")
ENV_OPTS_CREATE

DISK_CREATE_LAYOUT
DISK_CREATE_FORMAT
DISK_CREATE_MOUNTS

OSTREE_CREATE_REPO
OSTREE_CREATE_IMAGE
OSTREE_DEPLOY_IMAGE

BOOTLOADER_CREATE
;;

"upgrade")
if [[ ! -d "/ostree" ]]; then
exit 0
fi

export OSTREE_DEV_SCSI=
export OSTREE_SYS_ROOT=/
ENV_OPTS_CREATE

OSTREE_CREATE_REPO
OSTREE_CREATE_IMAGE
OSTREE_DEPLOY_IMAGE
OSTREE_CREATE_IMAGE
OSTREE_DEPLOY_IMAGE
;;

BOOTLOADER_CREATE
*)
echo "Usage: ostree.sh [install|upgrade]"
;;
esac

0 comments on commit 5b6f159

Please sign in to comment.