I have a /etc/rc.d/S11 link to a /etc/init.d file that is trying to set a bash variable of the file system type of a given blkid entry.
root@OpenWrt:/# blkid /dev/mmcblk1p3
/dev/mmcblk1p3: UUID="77111d8a-feb7-470c-a489-ffa0e5415c4c" TYPE="f2fs"
root@OpenWrt:/#
I attempted to tack a awk
onto the command
root@OpenWrt:/# blkid /dev/mmcblk1p3 | awk '{print $3}'
TYPE="f2fs"
root@OpenWrt:/#
Ideally, I just need the f2fs
without the rest. Using awk -F = '{print $3}'
returns
root@OpenWrt:/# blkid /dev/mmcblk1p3 | awk -F = '{print $3}'
"f2fs"
root@OpenWrt:/#
In the script, I'm trying to set it as a bash variable so I can use it later in the script.
CUR_FS=$(blkid /dev/mmcblk1p3 | awk '{print $3}');
However, in the debug message I'm sending to the kernel log, it's blank.
echo "[DEBUG] Shield is in ${SHIELD_MODE} Mode - Using /dev/${MNT_POINT} as ${CUR_FS}" > /dev/kmsg
Returns
[ 34.836024] [DEBUG] Shield is in Gateway Mode - Using /dev/mmcblk1p3 as
It's blank.
Before someone points out that OpenWrt does not have bash
(uses ash by default), I am doing a custom build and baked bash
in.
Can someone point me in the direction getting the end result of just f2fs
without the double-quotes?
Writing blkid
output to a file gives empty files.
blkid /dev/mmcblk1p3 2>&1 > /tmp/output
lsblk --noheadings -o FSTYPE /dev/mmcblk1p3 2>&1 > /tmp/output2
Edit Note: lsblk and blkid are separate on my system, so i tried it both ways. Still comes up blank. Could it be that I'm calling it too early? I've also attempted to put the full hard path to the commands, just in case $PATH
wasn't set yet - Still blank.
Edit 2: It was suggested that the init script was being called too early. I set the script to S99
for testing so that it's called almost last and it the filesystem call is still blank.
S99extroot is the script in question. Originally, I had it at S11
.
K10gpio_switch K99umount S19dropbear S94gpio_switch
K10snort S00sysfixtime S19firewall S95done
K50dropbear S10boot S20network S96led
K85odhcpd S10system S35odhcpd S98sysntpd
K89log S11sysctl S50cron S99extroot
K90network S12log S50uhttpd S99urandom_seed
K90sysfixtime S12rpcd S80ucitrack
K98boot S19dnsmasq S90snort
root@OpenWrt:/#
bash
in your commands. The most likely reason for your empty variable is thatblkid
doesn't output anything for some reason. Write the output and stderr ofblkid
to a file to see what it produces at that stage in the boot sequence.CUR_FS=$(blkid /dev/mmcblk1p3)
only in your script to see what the output is.man blkid
appears to be directing users atlsblk
, consider this alternative to reduce parsing:lsblk --noheadings -o FSTYPE /dev/mmcblk1p3
f2fs
. Still returns as blank in the script though> /dev/kmsg
and2>$1 > /tmp/output