FS#45753 - [arch-install-scripts] genfstab generates wrong root mountpoint

Attached to Project: Arch Linux
Opened by Maurizio D'Addona (mauritiusdadd) - Thursday, 23 July 2015, 10:39 GMT
Last edited by Dave Reisner (falconindy) - Sunday, 12 June 2016, 14:59 GMT
Task Type Bug Report
Category Arch Projects
Status Closed
Assigned To Dave Reisner (falconindy)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
mounpoints generated by genfstab should should always be relative to the root mountpoint specified however, if the root mountpoint name ends with a / then the path generated is an absolute path. For example, let's assume that /dev/sda1 is the boot partition and /dev/sda2 is the root partition:

mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot

genfstab /mnt generates the correct fstab:

$ genfstab /mnt
# UUID=47b16691-bc7f-4147-8157-b21b4b87e58d
/dev/sda2 / ext4 rw,relatime,discard,data=ordered 0 1

# UUID=2dee380a-179b-4356-9005-b53fb9f5c409
/dev/sda1 /boot ext2 rw,relatime 0 2

on the contrary genfstab /mnt/ generates a wrong fstab

$ genfstab /mnt/
# UUID=47b16691-bc7f-4147-8157-b21b4b87e58d
/dev/sda2 /mnt ext4 rw,relatime,discard,data=ordered 0 1

# UUID=2dee380a-179b-4356-9005-b53fb9f5c409
/dev/sda1 /boot ext2 rw,relatime 0 2

Steps to reproduce:
* mount a filsystem to /mount/point
* use the command: genfstab /mount/point/

Additional info:
* the problem could be fixed replacing the line

root=$1; shift

with

root="$(realpath -eL $1)"; shift

I also crated a patch for genfstab.in from the git sources (see attachment)
This task depends upon

Closed by  Dave Reisner (falconindy)
Sunday, 12 June 2016, 14:59 GMT
Reason for closing:  Fixed
Additional comments about closing:  https://git.archlinux.org/arch-install-s cripts.git/commit/?id=daa2fac5b27cee8dca 404b03d9cf41c328574ba7
Comment by Dave Reisner (falconindy) - Friday, 24 July 2015, 09:05 GMT
Thanks for the detailed report. I guess the real problem is that there's some canonicalization done by findmnt and the parameter expansion on line 140 fails, specifically:

target=${target#$root}

Given something like target=/mnt and root=/mnt/, target remains /mnt/. A similar problem exists for relative paths.
Comment by Maurizio D'Addona (mauritiusdadd) - Friday, 24 July 2015, 11:09 GMT
Yes, you're right, that's the actual problem. Since the existence of $root is already checked using 'mountpoint' and $target should always exists since it's returned directly by 'foundmnt', then why not let realpath do the job of computing the relative path and canonicalizing the resulting absolute mountpoint? Something like the following should work even with relative paths and it eliminates the need for $root and $target to be canonical:

# retrieve the relative path
target="$(realpath --relative-to=$root $target)"

# convert to a canonicalized absolute path
target="$(realpath -m /${target})"
Comment by Dave Reisner (falconindy) - Friday, 24 July 2015, 13:08 GMT
Using a single call to 'realpath -mL', or -eL, for extra paranoia and as in your original fix, seems sufficient.
Comment by Maurizio D'Addona (mauritiusdadd) - Saturday, 25 July 2015, 07:20 GMT
Ok, thank you for the fast response!
Comment by Reverend Homer (reverendhomer) - Sunday, 11 October 2015, 10:10 GMT
Any progress? I still can reproduce this bug today.

Loading...