Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run fsck.vfat for USB-stick during cRIO-9030 boot?

Solved!
Go to solution

Hi all,

 

we have a cRIO-9030 with a USB-stick. Sometimes after power loss the USB-stick filesystem (FAT32) gets corrupted and has to be checked/fixed. How can I configure cRIO LinuxRT to do that?

 

I've checked /etc/fstab, but it looks that the USB-stick is mounted somewhere else. I run mount - here is the line:

/dev/sdc1 on /media/sdc1 type vfat (ro,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,quiet,errors=remount-ro)

 

It would be nice if I can run fsck.vfat /dev/sdc1 every boot or when an error is detected.

 

 

Thanks in advance,

Nikolai

0 Kudos
Message 1 of 6
(6,151 Views)

Hi NickViz,

 

My name is Ed form National Instruments Technical Support, I have researched into the topic and found that it is possible to use the 'System Exec.vi' to complete the command during the initialization of your RT application.

 

You simply need to input your commands as a string just as you would to command prompt/terminal (depending on OS), you can also execute commands via SSH however this is one way communication between the RT application and the command shell.

 

I have included some links below to articles which describe the methodology as well as give some further explanation into the NI Linux Real-Time OS.

 

http://digital.ni.com/public.nsf/allkb/AFCAC25164CDBD4C86257C6A00545CD5?OpenDocument

http://digital.ni.com/public.nsf/allkb/9822A3A39B1D0CBB86257C55006B962A

http://www.ni.com/white-paper/14626/en/

 

I hope this is helpful and you achieve what it is you need, do note you will need to enable SSH scripting as described in the article on using PuTTY for your Real Time device.

 

Kind Regards,

 

Ed

0 Kudos
Message 2 of 6
(6,066 Views)
Solution
Accepted by NickViz

Hello,

 

well actually it's not what I needed, so I had to discover everything myself. Anyway here is the solution, as it might be useful for somebody:

 

Here is the check script:

cat /etc/init.d/usb-check.sh

 

#!/bin/bash

umount /media/sdc1

fsck.vfat -a -f -w /dev/sdc1 >> /var/log/boot

mount /dev/sdc1 /media/sdc1

#mount -o remount,sync /media/sdc1

 

Installation:

  1. Check that your cRIO has vfat.fsck. Run vfat.fsck and if you get: -bash: vfat.fsck: command not found, run the following commands: opkg update    and then    opkg install --nodeps dosfstools
  2. Check what device is your USB stick (usually /dev/sdc1): mount | grep vfat    You will see /dev/sdc1 and /media/sdc1 in the beginning of line (or /dev/sda1 or whatever).
  3. Create /etc/init.d/usb-check.sh script with commands above. Use device location taken from step2. Note that script should use Linux new line convention (LF).
  4. Make it executable: chmod 755 /etc/init.d/usb-check.sh
  5. Run it once to check if it works. Check if it did something: cat /var/log/boot you should see something like dosfsck 2.11, 12 Mar 2005, FAT32, LFN
  6. Register script in runlevel 5: update-rc.d usb-check.sh start 23 5 . Note that point at the end of the command is mandatory.
  7. Reboot AMCP and check /var/log/boot – you should see dosfsck traces there.
  8. To delete this script use the following command: update-rc.d usb-check.sh remove

 

The only one drawback I see in this solution is that for the heavily loaded USB stick with thousands of files the check might take noticeable time and slow down unit boot…

Message 3 of 6
(5,890 Views)

Hi NickViz,

 

Apologies that this was not the solution you were searching for, thank you for your response providing your solution. What I'll do is replicate the methodology and then create an article so that in future when this question is asked, the answer can be found in the public resources.

 

Once again thank you for your solution and I hope you are successful in your application.

 

Best Regards,

 

Ed

0 Kudos
Message 4 of 6
(5,853 Views)

Thanks for this great guide NickViz. One note, in step one of the installation, I had to run the command fsck.vfat instead of vfat.fsck .

 

@edjones93 does NI have any official documentation on this process yet? I couldn't find it with a cursory googling.

0 Kudos
Message 5 of 6
(2,659 Views)

I ran into additional difficulty with this solution, and I thought I would post my solution here for the benefit of others. I was unable to write to the usb stick after boot from within a labview program. I was able to work around this by giving the lvuser read/write permissions while mounting the usb stick.

 

My script looks like the following:

 

#!/bin/bash
umount /media/sdb1 > /home/lvuser/usb_repair.log
fsck.vfat -a -f -w /dev/sdb1 >> /home/lvuser/usb_repair.log
# get UID and GID for the lvuser from the password file
LVUSER_UID=$(grep -oP "lvuser:\w:\K\d+" /etc/passwd)
LVUSER_GID=$(grep -oP "lvuser:\w:\d+:\K\d+" /etc/passwd)
mount /dev/sdb1 /media/sdb1 -o rw,uid=$LVUSER_UID,gid=$LVUSER_GID >> /home/lvuser/usb_repair.log
#mount -o remount,sync /media/sdb1

 

 

0 Kudos
Message 6 of 6
(2,580 Views)