Remove unused /var/lib/registry data

This commit is contained in:
2026-03-26 05:10:35 +08:00
parent e5dfe17ae6
commit 8acf025a9d
5 changed files with 40 additions and 15 deletions

View File

@@ -4,20 +4,11 @@ set -euo pipefail
/preload-k8s-images.sh || exit 1 /preload-k8s-images.sh || exit 1
REGISTRY_DATA_DIR="${KUBE_IMG_CACHE}/registry-data/${ARCH}/${KUBE_VERSION}"
mkdir -p "${ROOTFS}/var/lib/registry"
echo "Copying registry data into rootfs..."
cp -a "${REGISTRY_DATA_DIR}/." "${ROOTFS}/var/lib/registry/"
mkdir -p "$ROOTFS/var/cache/apk" mkdir -p "$ROOTFS/var/cache/apk"
mkdir -p "$ROOTFS/var/cache/k8s-images"
mkdir -p "$ROOTFS/opt/monok8s/config" mkdir -p "$ROOTFS/opt/monok8s/config"
mkdir -p "$ROOTFS/build" mkdir -p "$ROOTFS/build"
mount --bind /var/cache/apk "$ROOTFS/var/cache/apk" mount --bind /var/cache/apk "$ROOTFS/var/cache/apk"
mount --bind /var/cache/k8s-images "$ROOTFS/var/cache/k8s-images"
mount --bind /dev "$ROOTFS/dev" mount --bind /dev "$ROOTFS/dev"
mount --bind /proc "$ROOTFS/proc" mount --bind /proc "$ROOTFS/proc"
mount --bind /sys "$ROOTFS/sys" mount --bind /sys "$ROOTFS/sys"
@@ -42,7 +33,6 @@ chroot "$ROOTFS" /bin/bash /configure-system.sh || exit 1
rm "$ROOTFS/configure-system.sh" rm "$ROOTFS/configure-system.sh"
umount "$ROOTFS/var/cache/apk" umount "$ROOTFS/var/cache/apk"
umount "$ROOTFS/var/cache/k8s-images"
umount "$ROOTFS/dev" umount "$ROOTFS/dev"
umount "$ROOTFS/proc" umount "$ROOTFS/proc"
umount "$ROOTFS/sys" umount "$ROOTFS/sys"
@@ -60,8 +50,8 @@ dd if=/dev/zero of="$IMG" bs=1 count=0 seek=$SIZE
sgdisk -o "$IMG" \ sgdisk -o "$IMG" \
-n 1:2048:+64M -t 1:0700 -c 1:config \ -n 1:2048:+64M -t 1:0700 -c 1:config \
-n 2:0:+3G -t 2:8300 -c 2:rootfsA \ -n 2:0:+2G -t 2:8300 -c 2:rootfsA \
-n 3:0:+3G -t 3:8300 -c 3:rootfsB \ -n 3:0:+2G -t 3:8300 -c 3:rootfsB \
-n 4:0:0 -t 4:8300 -c 4:data -n 4:0:0 -t 4:8300 -c 4:data
losetup -D losetup -D
@@ -75,11 +65,18 @@ mkfs.ext4 -F "${TMP_LOOP}p2"
mkfs.ext4 -F "${TMP_LOOP}p3" mkfs.ext4 -F "${TMP_LOOP}p3"
mkfs.ext4 -F "${TMP_LOOP}p4" mkfs.ext4 -F "${TMP_LOOP}p4"
mkdir -p /mnt/img-root mkdir -p /mnt/img-root /mnt/data
mount "${TMP_LOOP}p2" /mnt/img-root mount "${TMP_LOOP}p2" /mnt/img-root
mount "${TMP_LOOP}p4" /mnt/data
# Put the real /var onto the data partition
cp -a "$ROOTFS/var" /mnt/data/
# Copy rootfs to root partition, but exclude /var
cp -a "$ROOTFS"/. /mnt/img-root/ cp -a "$ROOTFS"/. /mnt/img-root/
rm -rf /mnt/img-root/var
mkdir -p /mnt/img-root/var
mkdir -p /mnt/img-root/boot mkdir -p /mnt/img-root/boot
cp /build/Image.gz /mnt/img-root/boot/Image.gz cp /build/Image.gz /mnt/img-root/boot/Image.gz
@@ -88,6 +85,7 @@ cp /build/${DEVICE_TREE_TARGET}.dtb /mnt/img-root/boot/${DEVICE_TREE_TARGET}.dtb
sync sync
umount /mnt/img-root umount /mnt/img-root
umount /mnt/data
losetup -d "$LOOP" losetup -d "$LOOP"

View File

@@ -22,7 +22,7 @@ FUSE_OVERLAYFS="${FUSE_OVERLAYFS:-/usr/bin/fuse-overlayfs}"
ARCHIVE_DIR="${KUBE_IMG_CACHE}/archives/${ARCH}/${KUBE_VERSION}" ARCHIVE_DIR="${KUBE_IMG_CACHE}/archives/${ARCH}/${KUBE_VERSION}"
# Seed directly into the target rootfs image store. # Seed directly into the target rootfs image store.
TARGET_GRAPHROOT="${ROOTFS}/var/lib/containers/storage" TARGET_GRAPHROOT="${ROOTFS}/usr/lib/monok8s/imagestore"
# Build-host temporary runtime state for containers/storage. # Build-host temporary runtime state for containers/storage.
TMPDIR="$(mktemp -d)" TMPDIR="$(mktemp -d)"
@@ -117,4 +117,4 @@ done
echo echo
echo "Done." echo "Done."
echo "Archives: ${ARCHIVE_DIR}" echo "Archives: ${ARCHIVE_DIR}"
echo "CRI-O storage: ${TARGET_GRAPHROOT}" echo "CRI-O storage: ${TARGET_GRAPHROOT}"

View File

@@ -0,0 +1,9 @@
[storage]
driver = "overlay"
runroot = "/run/containers/storage"
graphroot = "/var/lib/containers/storage"
[storage.options]
additionalimagestores = [
"/usr/lib/monok8s/imagestore"
]

View File

@@ -1,2 +1,3 @@
PARTLABEL=config /opt/monok8s/config vfat defaults,noatime 0 0 PARTLABEL=config /opt/monok8s/config vfat defaults,noatime 0 0
PARTLABEL=data /data ext4 defaults,noatime 0 21 PARTLABEL=data /data ext4 defaults,noatime 0 21
/data/var /var none rbind,noatime 0 0

17
docs/partitions.md Normal file
View File

@@ -0,0 +1,17 @@
## config
The first partition (vfat).
```
/opt/monok8s/config # Config for starting up the cluster, flags, upgrade state, node identity
```
## Rootfs A/B (readonly)
OS partition for A/B deployment
## data
```
/data/
├── var/ # mounted to /var
├── var/lib/registry # overlay to upperdir for /var/lib/registry
└── etc-upper/ # optional split if you want control
```