Skip to content

Commit

Permalink
Feature: Convert LVM to zpool (with secure init/trim). Poweroff comma…
Browse files Browse the repository at this point in the history
…nd. Bug fixes (#4)

* Pin ZBM tag
* Bug fixes. Feature: Convert LVM root to ZFS root
  • Loading branch information
midzelis authored Nov 7, 2023
1 parent 37ab415 commit d902d5a
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tailscaled.state*
cache
*test*
*ssh_host*
.code-workspace
*.code-workspace
authorized_keys
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ARG ZBM_COMMIT_HASH
RUN <<-EOF
# Record a commit hash if one was provided
if [ -n "${ZBM_COMMIT_HASH}" ]; then
echo "Using zfsbootmenu commit hash: ${ZQUICKINIT_COMMIT_HASH}"
echo "Using zfsbootmenu commit hash: ${ZBM_COMMIT_HASH}"
echo "${ZBM_COMMIT_HASH}" > /etc/zbm-commit-hash
mkdir -p /zbm
echo "Cloning https://github.com/zbm-dev/zfsbootmenu.git"
Expand All @@ -104,14 +104,16 @@ RUN <<-EOF
fi
EOF

COPY . /input/
# ZQuickInit source
ARG ZQUICKINIT_COMMIT_HASH
RUN <<-EOF
ZQUICKINIT_COMMIT_HASH=$(git rev-parse HEAD)
echo "Using zquickinit commit hash: ${ZQUICKINIT_COMMIT_HASH}"
echo "${ZQUICKINIT_COMMIT_HASH}" > /etc/zquickinit-commit-hash
if [ -n "${ZQUICKINIT_COMMIT_HASH}" ]; then
echo "Using zquickinit commit hash: ${ZQUICKINIT_COMMIT_HASH}"
echo "${ZQUICKINIT_COMMIT_HASH}" > /etc/zquickinit-commit-hash
fi
EOF

COPY . /input/
COPY --chmod=755 zquickinit.sh /

# Run the build script with no arguments by default
Expand Down
36 changes: 36 additions & 0 deletions recipes/zquick_core/fs/libexec/hooks/early-setup.d/lvm_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

log() {
echo "zquick: $1" > /dev/kmsg
}

if command -v lvm >/dev/null 2>&1; then

log "Scanning for LVM"
modprobe dm_thin_pool
lvm vgscan -v 2>/dev/null
lvm vgchange -a y 2>/dev/null

lvm_volumes=$(lvm lvscan 2>/dev/null | awk '{print $2}' | tr -d "'")
for volume in $lvm_volumes; do
# Get the logical volume path
lv_path=$(lvm lvdisplay "${volume}" 2>/dev/null | grep "LV Path" | awk '{print $3}')

if [[ $(lsblk -no FSTYPE "${lv_path}") = "swap" ]]; then
log "Skipping swap: ${lv_path}"
continue;
fi

# Get the volume path
volume=$(echo "${lv_path}" | awk -F'/' '{for(i=3;i<=NF;i++) printf "/%s", $i}')

# Create the mount point directory
mkdir -p "/mnt${volume}"

# Mount the volume
log "Mounting ${lv_path} on /mnt${volume}"
mount "${lv_path}" "/mnt${volume}"
done
else
log "Skipping LVM setup, lvm not part of this image"
fi
5 changes: 5 additions & 0 deletions recipes/zquick_end/initcpio/install/zquick_end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

build() {
rm -rf "${BUILDROOT}/input"
}
1 change: 1 addition & 0 deletions recipes/zquick_end/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
help: "Required - last thing to be built"
1 change: 1 addition & 0 deletions recipes/zquick_fsextras/initcpio/install/zquick_fsextras
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build() {
add_binary mkfs.vfat
add_binary efibootmgr
add_binary cryptsetup
add_binary tune2fs

add_module ext4
add_module ext3
Expand Down
Loading

0 comments on commit d902d5a

Please sign in to comment.