Page MenuHomeVyOS Platform

Add environmental variable pointing to current rootfs directory
Closed, ResolvedPublicFEATURE REQUEST

Description

In VyOS 1.4-rolling there are currently following environmental variables available:

vyos@vyos:~$ export | grep -i vyatta
declare -rx VYATTA_CFG_GROUP_NAME="vyattacfg"
declare -x VYATTA_PAGER="less 	--buffers=64	--auto-buffers	--no-lessopen		--QUIT-AT-EOF	--quit-if-one-screen	--RAW-CONTROL-CHARS	--squeeze-blank-lines	--no-init"
declare -rx VYATTA_USER_LEVEL_DIR="/opt/vyatta/etc/shell/level/admin"
declare -ax _vyatta_pipe_completions='()'
declare -ax _vyatta_pipe_noncompletions='()'
declare -rx vyatta_bindir="/opt/vyatta/bin"
declare -rx vyatta_cfg_templates="/opt/vyatta/share/vyatta-cfg/templates"
declare -rx vyatta_configdir="/opt/vyatta/config"
declare -rx vyatta_datadir="/opt/vyatta/share"
declare -rx vyatta_datarootdir="/opt/vyatta/share"
declare -rx vyatta_htmldir="/opt/vyatta/share/html"
declare -rx vyatta_infodir="/opt/vyatta/share/info"
declare -rx vyatta_libdir="/opt/vyatta/lib"
declare -rx vyatta_libexecdir="/opt/vyatta/libexec"
declare -rx vyatta_localedir="/opt/vyatta/share/locale"
declare -rx vyatta_localstatedir="/opt/vyatta/var"
declare -rx vyatta_op_templates="/opt/vyatta/share/vyatta-op/templates"
declare -rx vyatta_prefix="/opt/vyatta"
declare -rx vyatta_sbindir="/opt/vyatta/sbin"
declare -rx vyatta_sharedstatedir="/opt/vyatta/com"
declare -rx vyatta_sysconfdir="/opt/vyatta/etc"
declare -rx vyos_cfg_templates="/opt/vyatta/share/vyatta-cfg/templates"
declare -rx vyos_configdir="/opt/vyatta/config"
declare -rx vyos_datadir="/opt/vyatta/share"
declare -rx vyos_datarootdir="/opt/vyatta/share"
declare -rx vyos_libdir="/opt/vyatta/lib"
declare -rx vyos_op_templates="/opt/vyatta/share/vyatta-op/templates"
declare -rx vyos_prefix="/opt/vyatta"

and:

vyos@vyos:~$ export | grep -i vyos
declare -x HOME="/home/vyos"
declare -x LOGNAME="vyos"
declare -x PWD="/home/vyos"
declare -x USER="vyos"
declare -rx vyos_bin_dir="/usr/bin"
declare -rx vyos_cfg_templates="/opt/vyatta/share/vyatta-cfg/templates"
declare -rx vyos_completion_dir="/usr/libexec/vyos/completion"
declare -rx vyos_conf_scripts_dir="/usr/libexec/vyos/conf_mode"
declare -rx vyos_configdir="/opt/vyatta/config"
declare -rx vyos_datadir="/opt/vyatta/share"
declare -rx vyos_datarootdir="/opt/vyatta/share"
declare -rx vyos_libdir="/opt/vyatta/lib"
declare -rx vyos_libexec_dir="/usr/libexec/vyos"
declare -rx vyos_op_scripts_dir="/usr/libexec/vyos/op_mode"
declare -rx vyos_op_templates="/opt/vyatta/share/vyatta-op/templates"
declare -rx vyos_prefix="/opt/vyatta"
declare -rx vyos_sbin_dir="/usr/sbin"
declare -rx vyos_validators_dir="/usr/libexec/vyos/validators"

I would like that something such as "vyos_rootfs_dir" would be added pointing to the current rootfs path, basically the same path as loop0 is currently using:

vyos@vyos:~$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=4058428k,nr_inodes=1014607,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=815040k,mode=755)
/dev/sda1 on /usr/lib/live/mount/persistence type ext4 (rw,noatime)
/dev/loop0 on /usr/lib/live/mount/rootfs/1.4-rolling-202308060317.squashfs type squashfs (ro,noatime,errors=continue)
tmpfs on /usr/lib/live/mount/overlay type tmpfs (rw,relatime)
overlay on / type overlay (rw,noatime,lowerdir=/live/rootfs/1.4-rolling-202308060317.squashfs/,upperdir=/live/persistence/boot/1.4-rolling-202308060317/rw,workdir=/live/persistence/boot/1.4-rolling-202308060317/work)
/dev/sda1 on /opt/vyatta/etc/config type ext4 (rw,noatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
ramfs on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
ramfs on /run/credentials/systemd-tmpfiles-setup-dev.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
tmpfs on /var/tmp type tmpfs (rw,nosuid,nodev,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,relatime)
ramfs on /run/credentials/systemd-sysctl.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
ramfs on /run/credentials/systemd-tmpfiles-setup.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /etc/frr/frr.conf type tmpfs (rw,nosuid,nodev,noexec,relatime,size=815040k,mode=755)
none on /sys/fs/bpf type bpf (rw,relatime)
none on /etc/cni/net.d type tmpfs (rw,relatime)
none on /opt/vyatta/config type tmpfs (rw,nosuid,nodev,relatime,nr_inodes=0,mode=775)
/dev/sda1 on /boot type ext4 (rw,noatime)
/dev/sda1 on /boot/grub type ext4 (rw,noatime)
/dev/sda1 on /usr/lib/live/mount/persistence/boot/1.4-rolling-202308060317/grub type ext4 (rw,noatime)
tmpfs on /run/user/1002 type tmpfs (rw,nosuid,nodev,relatime,size=815036k,nr_inodes=203759,mode=700,uid=1002,gid=100)

That is something like:

declare -rx vyos_rootfs_dir="/usr/lib/live/mount/rootfs/1.4-rolling-202308060317.squashfs"

This would be helpful for scripting whereone want to fetch the original file of the iso being used (and avoid using wildcards), for example as in this case: https://vyos.dev/T5440

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Improvement (missing useful functionality)

Event Timeline

Viacheslav changed the task status from Open to In progress.Aug 10 2023, 10:48 AM
Viacheslav changed the task status from In progress to Needs testing.Aug 10 2023, 1:57 PM

Im biased but here are my testresults using modified VyOS 1.4-rolling-202308060317:

1:

vyos@vyos:~$ show system image 
The system currently has the following image(s) installed:

   1: 1.4-rolling-202308060317 (default boot) (running image)
   2: 1.4-rolling-202308050917
   3: 1.4-rolling-202308040317

meaning I have multiple images installed at once (expected outcome is that path for "1.4-rolling-202308060317" is being selected/used).

2:

vyos@vyos:~$ export | grep -i rootfs
declare -rx vyos_rootfs_dir="/usr/lib/live/mount/rootfs/1.4-rolling-202308060317.squashfs"

3:

Modified /config/scripts/vyos-preconfig-bootup.script and /config/scripts/vyos-postconfig-bootup.script to include:

echo ${vyos_rootfs_dir} > /config/testX.txt

and rebooted.

Result was that both files (text1.txt and test2.txt) were created and containing:

/usr/lib/live/mount/rootfs/1.4-rolling-202308060317.squashfs

Still works in VyOS 1.4-rolling-202308140557:

vyos@vyos:~$ export | grep -i rootfs
declare -rx vyos_rootfs_dir="/usr/lib/live/mount/rootfs/1.4-rolling-202308140557.squashfs"
vyos@vyos:~$ cd ${vyos_rootfs_dir}
vyos@vyos:/usr/lib/live/mount/rootfs/1.4-rolling-202308140557.squashfs$ ls -la
total 4
drwxr-xr-x  17 root root  308 Aug 14 07:57 .
drwxr-xr-x   3 root root 4096 Aug 14 22:20 ..
lrwxrwxrwx   1 root root    7 Aug 14 07:57 bin -> usr/bin
drwxr-xr-x   3 root root  197 Aug 14 07:57 boot
drwxr-xr-x   4 root root  191 Aug 14 07:57 dev
drwxr-xr-x 134 root root 4352 Aug 14 07:57 etc
drwxr-xr-x  18 root root  261 Aug 14 07:57 home
lrwxrwxrwx   1 root root    7 Aug 14 07:57 lib -> usr/lib
lrwxrwxrwx   1 root root    9 Aug 14 07:57 lib32 -> usr/lib32
lrwxrwxrwx   1 root root    9 Aug 14 07:57 lib64 -> usr/lib64
lrwxrwxrwx   1 root root   10 Aug 14 07:57 libx32 -> usr/libx32
drwxr-xr-x   2 root root    3 Aug 14 07:57 media
drwxr-xr-x   2 root root    3 Aug 14 07:57 mnt
drwxr-xr-x   3 root root   29 Aug 14 07:57 opt
drwxr-xr-x   2 root root    3 Jul 14 18:00 proc
drwx------   4 root root   72 Aug 14 07:57 root
drwxr-xr-x  28 root root  436 Aug 14 07:57 run
lrwxrwxrwx   1 root root    8 Aug 14 07:57 sbin -> usr/sbin
drwxr-xr-x   4 root root   42 Aug 14 07:57 srv
drwxr-xr-x   2 root root    3 Jul 14 18:00 sys
drwxrwxrwt   2 root root    3 Aug 14 07:57 tmp
drwxr-xr-x  14 root root  217 Aug 14 07:57 usr
drwxr-xr-x  13 root root  183 Aug 14 07:57 var