Allow easy move data partition (#651)
* Allow easy move data partition * Cleanup handling systemd * Improve handling * fix pipeline * pipeline * fix shell handling * fix scripts * Add bin folder * fix lint * Fix service handling * Fix loading * hide output * Fix handling
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-NetworkManager-system\x2dconnections.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-docker.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-dropbear.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-hostname.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-hosts.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-modules\x2dload.d.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-systemd-timesyncd.conf.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/etc-udev-rules.d.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-user-rules-udev-trigger.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/root-.docker.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/root-.ssh.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/var-lib-NetworkManager.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/var-lib-bluetooth.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/var-lib-docker.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/var-lib-systemd.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/var-log-journal.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/zram-swap.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/zram-tmp.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/zram-var.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-expand.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-overlay.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/mnt-boot.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/mnt-data.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/mnt-overlay.mount
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/busybox-acpid.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-apparmor.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-bind.target
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-config.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-hardware.target
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-persists.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-supervisor.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/hassos-zram.target
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/rauc.service
|
||||
@@ -1 +0,0 @@
|
||||
/usr/lib/systemd/system/dev-zram0.swap
|
||||
31
buildroot-external/rootfs-overlay/usr/bin/datactl
Executable file
31
buildroot-external/rootfs-overlay/usr/bin/datactl
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
# ==============================================================================
|
||||
# HassOS data partition handling
|
||||
# ==============================================================================
|
||||
set -e
|
||||
|
||||
OPTION_FILE=/mnt/overlay/data.opt
|
||||
DATA_DEVICE_CHILD="$(findfs LABEL="hassos-data")"
|
||||
DATA_DEVICE_ROOT="/dev/$(lsblk -no pkname "${DATA_DEVICE_CHILD}")"
|
||||
|
||||
# Move command
|
||||
if [ "${1}" = "move" ] && [ -e "${2}" ]; then
|
||||
DEVICE="${2}"
|
||||
|
||||
# Check device
|
||||
if ! lsblk "${DEVICE}" | grep disk > /dev/null 2>&1; then
|
||||
echo "[ERROR] Is not disk!"
|
||||
exit 1
|
||||
elif [ "${DEVICE}" = "${DATA_DEVICE_ROOT}" ]; then
|
||||
echo "[ERROR] Can't be the same disk!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Flag device
|
||||
echo "WARNING: ${DEVICE} will be reset on next restart!"
|
||||
echo "Press a key to move forward"
|
||||
read -r
|
||||
|
||||
echo "${DEVICE}" > ${OPTION_FILE}
|
||||
fi
|
||||
|
||||
@@ -2,3 +2,6 @@
|
||||
Description=HassOS overlay targets
|
||||
Documentation=man:systemd.target(5)
|
||||
Before=sysinit.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=HassOS data partition
|
||||
DefaultDependencies=no
|
||||
RefuseManualStart=true
|
||||
RefuseManualStop=true
|
||||
Requires=mnt-overlay.mount dev-disk-by\x2dlabel-hassos\x2ddata.device
|
||||
Wants=hassos-expand.service
|
||||
After=mnt-overlay.mount dev-disk-by\x2dlabel-hassos\x2ddata.device
|
||||
Before=hassos-expand.service
|
||||
ConditionPathExists=/mnt/overlay/data.opt
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/hassos-data
|
||||
|
||||
[Install]
|
||||
WantedBy=local-fs.target
|
||||
@@ -10,7 +10,6 @@ After=dev-disk-by\x2dlabel-hassos\x2ddata.device
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/hassos-expand
|
||||
RemainAfterExit=true
|
||||
|
||||
[Install]
|
||||
WantedBy=local-fs.target
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
[Unit]
|
||||
Description=HassOS hardware targets
|
||||
Documentation=man:systemd.target(5)
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
[Unit]
|
||||
Description=HassOS zram targets
|
||||
Documentation=man:systemd.target(5)
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
68
buildroot-external/rootfs-overlay/usr/libexec/hassos-data
Executable file
68
buildroot-external/rootfs-overlay/usr/libexec/hassos-data
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2039
|
||||
# ==============================================================================
|
||||
# HassOS data partition handler
|
||||
# ==============================================================================
|
||||
set -e
|
||||
|
||||
OPTION_FILE=/mnt/overlay/data.opt
|
||||
|
||||
# New data partition exits
|
||||
if ! [ -e "${OPTION_FILE}" ]; then
|
||||
echo "[INFO] No data option found"
|
||||
exit 0
|
||||
else
|
||||
NEW_DEVICE_ROOT="$(cat ${OPTION_FILE})"
|
||||
rm ${OPTION_FILE}
|
||||
fi
|
||||
|
||||
# Get device information
|
||||
OLD_DEVICE_CHILD="$(findfs LABEL="hassos-data")"
|
||||
OLD_DEVICE_ROOT="/dev/$(lsblk -no pkname "${OLD_DEVICE_CHILD}")"
|
||||
OLD_PART_NUM="${OLD_DEVICE_CHILD: -1}"
|
||||
|
||||
# Create new partition
|
||||
echo "[INFO] Create new hassos-data partition"
|
||||
sgdisk -o "${NEW_DEVICE_ROOT}"
|
||||
sgdisk \
|
||||
-n "0:0:0" \
|
||||
-c "0:hassos-data" \
|
||||
-t "0:0FC63DAF-8483-4772-8E79-3D69D8477DE4" \
|
||||
-u "0:a52a4597-fa3a-4851-aefd-2fbe9f849079" \
|
||||
"${NEW_DEVICE_ROOT}"
|
||||
sgdisk -v "${NEW_DEVICE_ROOT}"
|
||||
partx -u "${NEW_DEVICE_ROOT}"
|
||||
|
||||
NEW_DEVICE_CHILD="$(fdisk -l "${NEW_DEVICE_ROOT}" | grep '^/dev' | cut -d' ' -f1 | head -n 1)"
|
||||
|
||||
echo "[INFO] Move hassos-data from ${OLD_DEVICE_CHILD} to ${NEW_DEVICE_CHILD}"
|
||||
if ! dd if="${OLD_DEVICE_CHILD}" of="${NEW_DEVICE_CHILD}" status=none; then
|
||||
echo "[ERROR] Data copy fails!"
|
||||
|
||||
# Reset new data partition
|
||||
sgdisk -o "${NEW_DEVICE_ROOT}"
|
||||
partx -u "${NEW_DEVICE_ROOT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[INFO] Remove old hassos-data partition ${OLD_PART_NUM} / ${OLD_DEVICE_ROOT}"
|
||||
if sfdisk -dq "${OLD_DEVICE_ROOT}" | grep -q 'label: gpt'; then
|
||||
sgdisk -d "${OLD_PART_NUM}" "${OLD_DEVICE_ROOT}"
|
||||
sgdisk -v "${OLD_DEVICE_ROOT}"
|
||||
|
||||
else
|
||||
sfdisk --delete "${OLD_PART_NUM}" "${OLD_DEVICE_ROOT}" --force
|
||||
sfdisk -V "${OLD_DEVICE_ROOT}"
|
||||
fi
|
||||
|
||||
echo "[INFO] fix filesystem & layout"
|
||||
|
||||
# Fix filesystem
|
||||
e2fsck -y "${NEW_DEVICE_CHILD}"
|
||||
resize2fs -f "${NEW_DEVICE_CHILD}"
|
||||
|
||||
# Fix partition layout
|
||||
partx -d "${OLD_DEVICE_CHILD}"
|
||||
partx -u "${NEW_DEVICE_ROOT}"
|
||||
|
||||
echo "[INFO] Finish hassos data movement"
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2039
|
||||
# ==============================================================================
|
||||
# HassOS partition expander
|
||||
# ==============================================================================
|
||||
set -e
|
||||
|
||||
DEVICE_CHILD="$(findfs LABEL="hassos-data")"
|
||||
@@ -13,11 +16,15 @@ if [ -z "${UNUSED}" ] || [ "${UNUSED}" -le "2048" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[INFO] Update hassos-data partition ${PART_NUM}"
|
||||
if sfdisk -dq "${DEVICE_ROOT}" | grep -q 'label: gpt'; then
|
||||
# Resize & Reload partition
|
||||
echo "[INFO] Update hassos-data partition ${PART_NUM}"
|
||||
sgdisk -e "${DEVICE_ROOT}"
|
||||
sgdisk -d "${PART_NUM}" -n "${PART_NUM}:0:0" -c "${PART_NUM}:hassos-data" -t "${PART_NUM}:0FC63DAF-8483-4772-8E79-3D69D8477DE4" -u "${PART_NUM}:a52a4597-fa3a-4851-aefd-2fbe9f849079" "${DEVICE_ROOT}"
|
||||
sgdisk -d "${PART_NUM}" \
|
||||
-n "${PART_NUM}:0:0" \
|
||||
-c "${PART_NUM}:hassos-data" \
|
||||
-t "${PART_NUM}:0FC63DAF-8483-4772-8E79-3D69D8477DE4" \
|
||||
-u "${PART_NUM}:a52a4597-fa3a-4851-aefd-2fbe9f849079" \
|
||||
"${DEVICE_ROOT}"
|
||||
sgdisk -v "${DEVICE_ROOT}"
|
||||
else
|
||||
echo ", +" | sfdisk -N "${PART_NUM}" "${DEVICE_ROOT}" --force
|
||||
|
||||
@@ -9,10 +9,10 @@ if [ -e /usr/sbin/fw_setenv ]; then
|
||||
|
||||
# machine-id
|
||||
if [ "$(fw_printenv -n MACHINE_ID)" != "${MACHINE_ID}" ]; then
|
||||
echo "[info] set machine-id to ${MACHINE_ID}"
|
||||
echo "[INFO] set machine-id to ${MACHINE_ID}"
|
||||
fw_setenv MACHINE_ID "${MACHINE_ID}"
|
||||
else
|
||||
echo "[info] machine-id is okay"
|
||||
echo "[INFO] machine-id is okay"
|
||||
fi
|
||||
|
||||
###
|
||||
@@ -21,10 +21,10 @@ else
|
||||
|
||||
# machine-id
|
||||
if [ "$(barebox-state -g state.machine_id -i /etc/barebox-state.dtb)" != "${MACHINE_ID}" ]; then
|
||||
echo "[info] set machine-id to ${MACHINE_ID}"
|
||||
echo "[INFO] set machine-id to ${MACHINE_ID}"
|
||||
barebox-state -s "state.machine_id=${MACHINE_ID}" -i /etc/barebox-state.dtb
|
||||
else
|
||||
echo "[info] machine-id is okay"
|
||||
echo "[INFO] machine-id is okay"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user