1

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:/# 
  • I didn't notice anything that needs bash in your commands. The most likely reason for your empty variable is that blkid doesn't output anything for some reason. Write the output and stderr of blkid to a file to see what it produces at that stage in the boot sequence. – RalfFriedl May 26 at 8:40
  • Try to use CUR_FS=$(blkid /dev/mmcblk1p3) only in your script to see what the output is. – Thomas May 26 at 9:55
  • Since man blkid appears to be directing users at lsblk, consider this alternative to reduce parsing: lsblk --noheadings -o FSTYPE /dev/mmcblk1p3 – Jeff Schaller May 26 at 13:41
  • @JeffSchaller lsblk is different from blkid command-wise on my system, but I'd rather use your syntax if I can since it returns un-double quoted f2fs. Still returns as blank in the script though – Grommish May 26 at 18:45
  • @Thomas Still shows as blank in the > /dev/kmsg and 2>$1 > /tmp/output – Grommish May 26 at 18:46
1

I had to delay init until the blk device was available. Put in a while true loop to keep checking for it so I could mknod it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.