Compare commits

...
Author SHA1 Message Date
MickLesk f6e586d60c fstrim: read the root volume from the container config
The LVM usage before and after the trim looked for vm-<id>-disk-0 only, so
a restored or moved container (vm-<id>-disk-1) showed "not available
(non-LVM storage)" although the trim worked (#18888). The volume now comes
from /etc/pve/lxc/<id>.conf, a file read with no pct call per container.
2026-11-21 15:28:19 +01:00
+5 -1
View File
@@ -108,7 +108,11 @@ function trim_container() {
echo -e "${BL}[Info]${GN} Trimming ${BL}$container${CL} \n"
local before_trim after_trim
local lv_name="vm-${container}-disk-0"
# A restored or moved container's root is not always disk-0; the volume comes
# from its config file, which needs no pct call.
local lv_name
lv_name="$(awk -F'[:,]' '/^rootfs:/ {print $3; exit}' "/etc/pve/lxc/${container}.conf" 2>/dev/null)"
[[ -n "$lv_name" ]] || lv_name="vm-${container}-disk-0"
if lvs --noheadings -o lv_name 2>/dev/null | grep -qw "$lv_name"; then
before_trim=$(lvs --noheadings -o lv_name,data_percent 2>/dev/null | awk -v ctid="$lv_name" '$1 == ctid {gsub(/%/, "", $2); print $2}')
[[ -n "$before_trim" ]] && echo -e "${RD}Data before trim $before_trim%${CL}" || echo -e "${RD}Data before trim: not available${CL}"