You are not logged in.

#1 2024-09-03 14:05:10

victorsouzaleal
Member
Registered: 2024-09-03
Posts: 5

genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

I'm a new user of Linux systems in general, I've been on Arch for approximately 1 month and when i needed Timeshift to undo some things i was surprised by an 'emergency mode' and from what I understand this was caused by @home subvolid have changed and does not match the subvolid configured in fstab.

I ended up manually mounting @home and removing the subvolid from fstab and leaving just the subvol to make it work, but this can be frustrating for a first-timer.

It seems that someone has already identified this problem and made a PR on genfstab script but this continues in the current version of archinstall : https://github.com/archlinux/arch-insta … 00da68ec19

Does anyone more experienced know the importance of keeping subvolid and subvol in fstab?

Offline

#2 2024-09-03 14:56:32

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

The linked change is in the currently distributed archinstall script since November 2022?

Offline

#3 2024-09-03 15:11:20

victorsouzaleal
Member
Registered: 2024-09-03
Posts: 5

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

seth wrote:

The linked change is in the currently distributed archinstall script since November 2022?


From what I understand, this goes beyond archinstall, even in a manual installation when using the genfstab script it creates the fstab with subvolid and subvol. As archinstall also uses genfstab it is also affected.

It seems that genfstab is the big villain, I also tried installing CachyOS and they don't keep the subvolid in fstab.

For example, i already did an arch installation using this method: https://gist.github.com/mjkstra/96ce7a5 … 2cdc169bae but i got the same fstab like archinstall

Last edited by victorsouzaleal (2024-09-03 15:13:37)

Offline

#4 2024-09-03 15:29:18

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,121

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

Using what ISO?

Offline

#5 2024-09-03 15:30:20

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

Edit /usr/bin/genfstab, wrap optstring_apply_quirks()  w/ "set -x" and "set +x" (inside the function) and run "genstab /" (or whatever context is relevant) and see what it prints and does…

Offline

#6 2024-09-03 15:47:48

victorsouzaleal
Member
Registered: 2024-09-03
Posts: 5

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

Scimmia wrote:

Using what ISO?

Latest

Offline

#7 2024-09-03 16:34:41

victorsouzaleal
Member
Registered: 2024-09-03
Posts: 5

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

seth wrote:

Edit /usr/bin/genfstab, wrap optstring_apply_quirks()  w/ "set -x" and "set +x" (inside the function) and run "genstab /" (or whatever context is relevant) and see what it prints and does…

Same result, continues generating with subvolid and subvol :  https://imgur.com/SDBuvZN

Offline

#8 2024-09-03 16:44:06

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,307

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

That's expected, you need to inspect the output (in the terminal) that should get generated by the set +x option

Offline

#9 2024-09-03 19:13:09

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

…
optstring_apply_quirks() {
  set -x
  local varname=$1 fstype=$2

  # SELinux displays a 'seclabel' option in /proc/self/mountinfo. We can't know
  # if the system we're generating the fstab for has any support for SELinux (as
  # one might install Arch from a Fedora environment), so let's remove it.
  optstring_remove_option "$varname" seclabel

  # Prune 'relatime' option for any pseudofs. This seems to be a rampant
  # default which the kernel often exports even if the underlying filesystem
  # doesn't support it. Example: https://bugs.archlinux.org/task/54554.
  if awk -v fstype="$fstype" '$1 == fstype { exit 1 }' /proc/filesystems; then
    optstring_remove_option "$varname" relatime
  fi

  case $fstype in
    btrfs)
      # Having only one of subvol= and subvolid= is enough for mounting a btrfs subvolume
      # And having subvolid= set prevents things like 'snapper rollback' to work, as it
      # updates the subvolume in-place, leaving subvol= unchanged with a different subvolid.
      if optstring_has_option "$varname" subvol; then
        optstring_remove_option "$varname" subvolid
      fi
      ;;
    f2fs)
      # These are Kconfig options for f2fs. Kernels supporting the options will
      # only provide the negative versions of these (e.g. noacl), and vice versa
      # for kernels without support.
      optstring_remove_option "$varname" noacl,acl,nouser_xattr,user_xattr
      ;;
    vfat)
      # Before Linux v3.8, "cp" is prepended to the value of the codepage.
      if optstring_get_option "$varname" codepage && [[ $codepage = cp* ]]; then
        optstring_remove_option "$varname" codepage
        optstring_append_option "$varname" "codepage=${codepage#cp}"
      fi
      ;;
  esac
  set +x
}
…
genfstab / > /tmp/genfstab.trace 2>&1
cat /tmp/genfstab.trace | curl -F 'file=@-' 0x0.st

Post the link

Offline

#10 2024-09-03 20:22:12

victorsouzaleal
Member
Registered: 2024-09-03
Posts: 5

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

seth wrote:
…
optstring_apply_quirks() {
  set -x
  local varname=$1 fstype=$2

  # SELinux displays a 'seclabel' option in /proc/self/mountinfo. We can't know
  # if the system we're generating the fstab for has any support for SELinux (as
  # one might install Arch from a Fedora environment), so let's remove it.
  optstring_remove_option "$varname" seclabel

  # Prune 'relatime' option for any pseudofs. This seems to be a rampant
  # default which the kernel often exports even if the underlying filesystem
  # doesn't support it. Example: https://bugs.archlinux.org/task/54554.
  if awk -v fstype="$fstype" '$1 == fstype { exit 1 }' /proc/filesystems; then
    optstring_remove_option "$varname" relatime
  fi

  case $fstype in
    btrfs)
      # Having only one of subvol= and subvolid= is enough for mounting a btrfs subvolume
      # And having subvolid= set prevents things like 'snapper rollback' to work, as it
      # updates the subvolume in-place, leaving subvol= unchanged with a different subvolid.
      if optstring_has_option "$varname" subvol; then
        optstring_remove_option "$varname" subvolid
      fi
      ;;
    f2fs)
      # These are Kconfig options for f2fs. Kernels supporting the options will
      # only provide the negative versions of these (e.g. noacl), and vice versa
      # for kernels without support.
      optstring_remove_option "$varname" noacl,acl,nouser_xattr,user_xattr
      ;;
    vfat)
      # Before Linux v3.8, "cp" is prepended to the value of the codepage.
      if optstring_get_option "$varname" codepage && [[ $codepage = cp* ]]; then
        optstring_remove_option "$varname" codepage
        optstring_append_option "$varname" "codepage=${codepage#cp}"
      fi
      ;;
  esac
  set +x
}
…
genfstab / > /tmp/genfstab.trace 2>&1
cat /tmp/genfstab.trace | curl -F 'file=@-' 0x0.st

Post the link

http://0x0.st/XwMS.txt

Offline

#11 2024-09-03 20:37:10

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

Please stop the mindless full-quoting, it's unnecessary (the previous posts are still there) and bloats the thread.

+ declare -g opts=rw,relatime,compress=zstd:3,space_cache=v2,subvolid=256,subvol=/@
+ awk -v fstype=btrfs '$1 == fstype { exit 1 }' /proc/filesystems
+ case $fstype in
+ optstring_has_option opts subvol
+ local subvol
+ optstring_get_option opts subvol
+ local opts o
+ IFS=,
+ read -ra opts
+ return 1

Seems to fail to detect the subvol option because it operates on "opts", L557

- optstring_apply_quirks "opts" "$fstype"
+ optstring_apply_quirks "$opts" "$fstype"

and try again…
(You can remove the set -/+x trace-wrap)

Edit:  Hold on, optstring_get_option and optstring_get_option use dynamic variables, this should™ work w/o resolving "opts" and passing around that string.

optstring_get_option() {
  echo "${!1}"
  local opts o

  IFS=, read -ra opts <<<"${!1}"
  for o in "${opts[@]}"; do
    echo "------  $o"
    if optstring_match_option "$2" "$o"; then
      declare -g "$o"
      return 0
    fi
  done

  return 1
}

Last edited by seth (2024-09-03 20:55:50)

Offline

#12 2024-10-13 02:50:20

jefftp
Member
Registered: 2024-10-12
Posts: 3

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

optstring_get_option() is using a local variable "opts" that is shadowing the global variable opts.

The other optstring_ functions use "options_". Changing the local "opts" variable to "options_" fixes the issue with genfstab including subvolid and subvol at the same time.

optstring_get_option() {
  local options_ o
  
  IFS=, read -ra options_ <<<"${!1}"
  for o in "${options_[@]}"; do
    if optstring_match_option "$2" "$o"; then
      declare -g "$o"
      return 0
    fi
  done
  
  return 1
}

Offline

#13 2024-10-13 02:57:13

jefftp
Member
Registered: 2024-10-12
Posts: 3

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

This appears to be resolved here: https://gitlab.archlinux.org/archlinux/ … type=heads

Rather than using "options_" for the local variable, the version linked above uses "_opts".

However, genfstab on the latest Arch installer ISO (2024.10.01) still has this bug.

Here's a diff below to fix it:

@@ -318,10 +318,10 @@
 }

 optstring_get_option() {
-  local opts o
+  local _opts o

-  IFS=, read -ra opts <<<"${!1}"
-  for o in "${opts[@]}"; do
+  IFS=, read -ra _opts <<<"${!1}"
+  for o in "${_opts[@]}"; do
     if optstring_match_option "$2" "$o"; then
       declare -g "$o"
       return 0

Last edited by jefftp (2024-10-13 03:36:44)

Offline

#14 2024-10-13 07:17:27

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

optstring_get_option() is using a local variable "opts" that is shadowing the global variable opts.

Yes, the global opts gets passed via "${!1}", see the

echo "${!1}"

injection.

Offline

#15 2024-10-13 18:07:26

jefftp
Member
Registered: 2024-10-12
Posts: 3

Re: genfstab : why archinstall keep using "subvolid" in fstab (btrfs) ?

Because opts is getting shadowed by the local variable you can't access the global $opts indirectly. $1 just contains the name of the global variable as a string containing "opts". I'm not sure why the authors wouldn't just pass the contents of the opts string by value and return the contents of the modified string.

Adding an echo below the local variable declaration shows the problem more clearly:

optstring_get_option() {
  local opts o
  
  echo "opts = ${!1}"

When optstring_get_option() is called it will always print "opts =", because the local variable $opts is the only one you can see in the scope of this function and it's empty.

The maintainers of arch-install-scripts fixed this some time ago (more than 6 months it appears from the gitlab repo) but the install ISO continues to use an old version with the bug. I'm not familiar enough with the Arch community to know how to raise this issue to the installer team. It's already fixed in the repo, but they're using an old version of genfstab. For now I've worked around by just patching genfstab in my install scripts with the diff I included above.

Offline

Board footer

Powered by FluxBB