Skip to content

Commit dc71579

Browse files
authored
fix: quota fstab mount error on XFS filesystem (hestiacp#5048)
* fix: quota fstab mount error on XFS filesystem * Fix XFS Quota hestiacp#5046
1 parent ae6a5db commit dc71579

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

bin/v-add-sys-quota

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,47 @@ check_hestia_demo_mode
4747

4848
# Adding group and user quota on /home partition
4949
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
50+
fs_type=$(df -T "$mnt" | awk '{print $2}' | tail -n1)
5051
lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
5152
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
52-
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
53-
if [ "$(echo "$opt" | tr ',' '\n' | grep -c -x $fnd)" -ne 5 ]; then
54-
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
53+
54+
if [[ "$fs_type" == "xfs" ]]; then
55+
log_history "XFS filesystem detected on $mnt. Modifying GRUB for XFS quota."
56+
grub_conf="/etc/default/grub"
57+
58+
if ! grep -q "rootflags=.*uquota" "$grub_conf" || ! grep -q "systemd.unified_cgroup_hierarchy=1" "$grub_conf"; then
59+
params="rootflags=uquota,pquota,gquota systemd.unified_cgroup_hierarchy=1"
60+
sed -i 's/^\(GRUB_CMDLINE_LINUX="[^"]*\)/\1 '"$params"'/' "$grub_conf"
61+
check_result $? "Failed to add kernel parameters to $grub_conf"
62+
update-grub > /dev/null 2>&1
63+
log_history "GRUB updated. A system reboot is required to apply changes."
64+
reboot_req="Y"
65+
else
66+
log_history "XFS quota flags already present in GRUB configuration."
67+
fi
68+
else
69+
# >> Non XFS Filesystem
70+
log_history "$fs_type filesystem on $mnt. Using standard quota parameters."
71+
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
5572
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
56-
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
57-
systemctl daemon-reload
58-
mount -o remount "$mnt"
73+
74+
# >> Modify /etc/fstab
75+
if [ "$(echo "$opt" | tr ',' '\n' | grep -c -xE "$fnd")" -ne "$(echo "$fnd" | tr '\|' '\n' | wc -l)" ]; then
76+
old=$(echo "$opt" | tr ',' '\n' | grep -vE 'usrquota|grpquota|usrjquota=|grpjquota=|jqfmt=|uquota|gquota' | tr '\n' ',' | sed 's/,$//')
77+
if [ -n "$old" ]; then
78+
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
79+
fi
80+
systemctl daemon-reload
81+
mount -o remount "$mnt"
82+
fi
5983
fi
6084

61-
# Adding v2 group and user quota index
62-
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
63-
quotacheck -avcugm > /dev/null 2>&1
85+
# >> Adding v2 group and user quota index
86+
# >> For XFS, aquota files are not typically used, quota is managed directly within filesystem.
87+
if [ "$fs_type" != "xfs" ]; then
88+
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
89+
quotacheck -avcugm > /dev/null 2>&1
90+
fi
6491
fi
6592

6693
# Adding quotacheck on reboot
@@ -94,4 +121,9 @@ $BIN/v-log-action "system" "Info" "Plugins" "System Quota enforcement enabled."
94121
log_history "system quota enforcement enabled"
95122
log_event "$OK" "$ARGUMENTS"
96123

124+
if [ "$reboot_req" = "Y" ]; then
125+
log_history "A system reboot is required to complete enable quota."
126+
echo "Warning: A system reboot is required to complete enable quota."
127+
fi
128+
97129
exit

0 commit comments

Comments
 (0)