Skip to content

Commit

Permalink
Partitioning layout (#839)
Browse files Browse the repository at this point in the history
* Allow to partition with a cloud-init config file

Fixes #565
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Package bumps

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Change name for consistency

Also add the new variable to the example config file

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Custom layout only available with GPT

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Refactor common code, detect PERSISTENT

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Bump yip to 0.9.21

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
  • Loading branch information
mudler authored Nov 4, 2021
1 parent 93e8576 commit 3b9d49f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
3 changes: 3 additions & 0 deletions examples/standard/files/etc/cos/config
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ COSIGN_EXPERIMENTAL=1
# This can be set to file, URL, KMS URI or Kubernetes Secret
# This is only used if COSIGN_EXPERIMENTAL is set to 0
COSIGN_PUBLIC_KEY_LOCATION=""

# Default size (in MB) of disk image files (.img) created during upgrades
DEFAULT_IMAGE_SIZE=3240
6 changes: 1 addition & 5 deletions packages/cos/collection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ packages:
- &cos
name: "cos"
category: "system"
version: 0.7.2-2
version: "0.7.3"
description: "cOS base image, used to build cOS live ISOs"
brand_name: "cOS"
labels:
Expand All @@ -11,17 +11,13 @@ packages:
- !!merge <<: *cos
name: "cos-container"
description: "cOS container image, used to build cOS derivatives from scratch"
version: 0.7.1-7
- !!merge <<: *cos
category: "recovery"
brand_name: "cOS recovery"
description: "cOS recovery image, used to boot cOS for troubleshooting"
version: 0.7.2-2
- !!merge <<: *cos
name: "cos-img"
category: "recovery"
version: 0.7.2-2
- !!merge <<: *cos
name: "cos-squash"
category: "recovery"
version: 0.7.2-2
79 changes: 64 additions & 15 deletions packages/installer/cos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ RECOVERYDIR=/run/cos/recovery
RECOVERYSQUASHFS=${ISOMNT}/recovery.squashfs
GRUBCONF=/etc/cos/grub.cfg

# Default size (in MB) of disk image files (.img) created during upgrades
DEFAULT_IMAGE_SIZE=3240

## cosign signatures
COSIGN_REPOSITORY="${COSIGN_REPOSITORY:-raccos/releases-:FLAVOR:}"
COSIGN_EXPERIMENTAL="${COSIGN_EXPERIMENTAL:-1}"
Expand Down Expand Up @@ -99,15 +102,15 @@ prepare_deploy_target() {

mkdir -p ${STATEDIR}/cOS || true
rm -rf ${STATEDIR}/cOS/active.img || true
dd if=/dev/zero of=${STATEDIR}/cOS/active.img bs=1M count=3240
dd if=/dev/zero of=${STATEDIR}/cOS/active.img bs=1M count=$DEFAULT_IMAGE_SIZE
mkfs.ext2 ${STATEDIR}/cOS/active.img
mount -t ext2 -o loop ${STATEDIR}/cOS/active.img $TARGET
}

prepare_target() {
mkdir -p ${STATEDIR}/cOS || true
rm -rf ${STATEDIR}/cOS/transition.img || true
dd if=/dev/zero of=${STATEDIR}/cOS/transition.img bs=1M count=3240
dd if=/dev/zero of=${STATEDIR}/cOS/transition.img bs=1M count=$DEFAULT_IMAGE_SIZE
mkfs.ext2 ${STATEDIR}/cOS/transition.img
mount -t ext2 -o loop ${STATEDIR}/cOS/transition.img $TARGET
}
Expand All @@ -118,7 +121,7 @@ usage()
echo ""
echo "Example: $PROG-install /dev/vda"
echo " install:"
echo " [--force-efi] [--force-gpt] [--iso https://.../OS.iso] [--debug] [--tty TTY] [--poweroff] [--no-format] [--config https://.../config.yaml] DEVICE"
echo " [--partition-layout /path/to/config/file.yaml ] [--force-efi] [--force-gpt] [--iso https://.../OS.iso] [--debug] [--tty TTY] [--poweroff] [--no-format] [--config https://.../config.yaml] DEVICE"
echo ""
echo " upgrade:"
echo " [--strict] [--recovery] [--no-verify] [--no-cosign] [--directory] [--docker-image] (IMAGE/DIRECTORY)"
Expand Down Expand Up @@ -193,27 +196,72 @@ prepare_passive() {
sync
}

part_probe() {
local dev=$1
partprobe ${dev} 2>/dev/null || true

sync
sleep 2

dmsetup remove_all 2>/dev/null || true
}

blkid_probe() {
OEM=$(blkid -L COS_OEM || true)
STATE=$(blkid -L COS_STATE || true)
RECOVERY=$(blkid -L COS_RECOVERY || true)
BOOT=$(blkid -L COS_GRUB || true)
PERSISTENT=$(blkid -L COS_PERSISTENT || true)
}

do_format()
{
if [ "$COS_INSTALL_NO_FORMAT" = "true" ]; then
STATE=$(blkid -L COS_STATE || true)
if [ -z "$STATE" ] && [ -n "$DEVICE" ]; then
tune2fs -L COS_STATE $DEVICE
STATE=$(blkid -L COS_STATE)
fi
OEM=$(blkid -L COS_OEM || true)
STATE=$(blkid -L COS_STATE || true)
RECOVERY=$(blkid -L COS_RECOVERY || true)
BOOT=$(blkid -L COS_GRUB || true)
blkid_probe
return 0
fi

echo "Formatting drives.."

if [ -n "$COS_PARTITION_LAYOUT" ] && [ "$PARTTABLE" != "gpt" ]; then
echo "Custom layout only available with GPT based installations"
exit 1
fi

dd if=/dev/zero of=${DEVICE} bs=1M count=1
parted -s ${DEVICE} mklabel ${PARTTABLE}

# TODO: Size should be tweakable
# Partitioning via cloud-init config file
if [ -n "$COS_PARTITION_LAYOUT" ] && [ "$PARTTABLE" = "gpt" ]; then
if [ "$BOOTFLAG" == "esp" ]; then
parted -s ${DEVICE} mkpart primary fat32 0% 50MB # efi
parted -s ${DEVICE} set 1 ${BOOTFLAG} on
PREFIX=${DEVICE}
if [ ! -e ${PREFIX}${STATE_NUM} ]; then
PREFIX=${DEVICE}p
fi
BOOT=${PREFIX}1
mkfs.vfat -F 32 ${BOOT}
fatlabel ${BOOT} COS_GRUB
elif [ "$BOOTFLAG" == "bios_grub" ]; then
parted -s ${DEVICE} mkpart primary 0% 1MB # BIOS boot partition for GRUB
parted -s ${DEVICE} set 1 ${BOOTFLAG} on
fi

yip -s partitioning $COS_PARTITION_LAYOUT

part_probe $DEVICE

blkid_probe

return 0
fi

# Standard partitioning
if [ "$PARTTABLE" = "gpt" ] && [ "$BOOTFLAG" == "esp" ]; then
BOOT_NUM=1
OEM_NUM=2
Expand Down Expand Up @@ -251,10 +299,7 @@ do_format()
parted -s ${DEVICE} set 2 ${BOOTFLAG} on
fi

partprobe ${DEVICE} 2>/dev/null || true
sleep 2

dmsetup remove_all 2>/dev/null || true
part_probe $DEVICE

PREFIX=${DEVICE}
if [ ! -e ${PREFIX}${STATE_NUM} ]; then
Expand Down Expand Up @@ -297,7 +342,7 @@ do_mount()

mkdir -p ${STATEDIR}/cOS
# TODO: Size should be tweakable
dd if=/dev/zero of=${STATEDIR}/cOS/active.img bs=1M count=3240
dd if=/dev/zero of=${STATEDIR}/cOS/active.img bs=1M count=$DEFAULT_IMAGE_SIZE
mkfs.ext2 ${STATEDIR}/cOS/active.img -L COS_ACTIVE
sync
LOOP=$(losetup --show -f ${STATEDIR}/cOS/active.img)
Expand Down Expand Up @@ -850,7 +895,7 @@ copy_active() {

TARGET=$loop_dir
# TODO: Size should be tweakable
dd if=/dev/zero of=${STATEDIR}/cOS/transition.img bs=1M count=3240
dd if=/dev/zero of=${STATEDIR}/cOS/transition.img bs=1M count=$DEFAULT_IMAGE_SIZE
mkfs.ext2 ${STATEDIR}/cOS/transition.img -L COS_PASSIVE
sync
LOOP=$(losetup --show -f ${STATEDIR}/cOS/transition.img)
Expand Down Expand Up @@ -1194,6 +1239,10 @@ install() {
shift 1
COS_INSTALL_CONFIG_URL=$1
;;
--partition-layout)
shift 1
COS_PARTITION_LAYOUT=$1
;;
--iso)
shift 1
COS_INSTALL_ISO_URL=$1
Expand Down
2 changes: 1 addition & 1 deletion packages/installer/definition.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "installer"
category: "utils"
version: 0.20-1
version: "0.21"
description: "Installer, Upgrade and reset utilities to manage cOS derivatives"
4 changes: 2 additions & 2 deletions packages/toolchain/collection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ packages:
name: "yip"
upx: false
fips: true
version: "0.9.20"
version: "0.9.21"
labels:
github.repo: "yip"
github.owner: "mudler"
Expand All @@ -53,7 +53,7 @@ packages:
name: "yip"
upx: false
fips: false
version: "0.9.20"
version: "0.9.21"
labels:
github.repo: "yip"
github.owner: "mudler"
Expand Down

0 comments on commit 3b9d49f

Please sign in to comment.