NI Linux Real-Time Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Useful SSH Commands for configuring Linux RT on myRIO or cRIO-9068

All commands and their outputs below are copied directly from the Terminal window on OS X; the commands are bolded monospace font, with output shown below for convenience.

Begin a new SSH session

This example uses "admin" as the username and the IPv4 address of the device on my local area network. Your IP address will be different.

Jacks-27-iMac:~ jackdunaway$ ssh admin@192.168.0.20

NI Linux Real-Time (run mode)

Log in with your NI-Auth credentials.

Password:

admin@Wirebird-Labs-myRIO:~#

Exiting the SSH session

admin@Wirebird-Labs-myRIO:~# exit

logout

Connection to 192.168.0.20 closed.

Jacks-27-iMac:~ jackdunaway$

Set a new NI-Auth password

Nominally, the initial username will be admin and the password will be blank, so when prompted for the current NIAuth password, press the "Return" key.

Jacks-27-iMac:~ jackdunaway$ ssh -t admin@192.168.0.20 passwd

NI Linux Real-Time (run mode)

Log in with your NI-Auth credentials.

Password:

Enter current NIAuth password: [Return], since original password was blank

Enter new NIAuth password: new password entered here followed by [Return]

Re-enter new NIAuth password: new password repeated followed by [Return]

passwd: password updated successfully

Connection to 192.168.0.20 closed.

Jacks-27-iMac:~ jackdunaway$

Set a new Hostname (the name of the device)

Note that this command requires a reboot to take effect.

admin@myRIO:~# /usr/local/natinst/bin/nirtcfg --get section="SYSTEMSETTINGS",token="host_name"

myRIO

admin@myRIO:~# /usr/local/natinst/bin/nirtcfg --set section="SYSTEMSETTINGS",token="host_name",value="myRIO-Wirebird-Labs"

admin@myRIO:~# /usr/local/natinst/bin/nirtcfg --get section="SYSTEMSETTINGS",token="host_name"

myRIO-Wirebird-Labs

Determine Linux RTOS version

This is nominally the same information as Operating System as reported by Measurement and Automation Explorer:

admin@Wirebird-Labs-myRIO:~# uname -r

3.2.35-rt52-1.0.0f1

Determine the RIO DNS name

This is nominally the same information as DNS Name as reported by Measurement and Automation Explorer:

admin@Wirebird-Labs-myRIO:~# uname -n

Wirebird-Labs-myRIO

Find recently modified files

This helps in situations where "you're pretty sure you just changed something somewhere", but don't know where "somewhere" is on the Linux filesystem.

In the example below, we allow the RIO to sit "idle" for over 1minute, then execute the first command. This yields no results since "-mmin -1" means filter and return only files that have been modified in the past minute.

The same command is executed once more, but just before execution, we set Safe Mode to True from the Startup Settings section in Measurement and Automation Explorer (MAX). The following command would find all files within the /etc directory, enabling us to find where MAX persisted this setting:

(safemode) admin@NI-myRIO-1900-0303b79c:~# find / -not -path "/proc*" -not -path "/dev*" -not -type d -mmin -1

(safemode) admin@NI-myRIO-1900-0303b79c:~# find / -not -path "/proc*" -not -path "/dev*" -not -type d -mmin -1

/etc/natinst/share/ni-rt.ini

/mnt/userfs/etc/natinst/share/ni-rt.ini

(safemode) admin@NI-myRIO-1900-0303b79c:~#

Additional filters on this command will exclude any changes made under the /proc and /dev directories, and it will also exclude all matches that are of type "directory".

Modify contents of a file

From the above example, we determined how and where MAX programmatically persists the "Safe Mode" setting to the device. Now, let's write this setting programmatically through SSH. Reading aloud the command below: we use the stream editor (sed) with options for in-place replacements and extended regex turned on, performing a substition operation, matching the entire line that begins with SafeMode.enabled= (i.e., regardless its value), replacing that match with the value SafeMode.enabled=False, on the file located at /etc/natinst/share/ni-rt.ini

admin@Wirebird-Labs-myRIO:~# sed -ir 's/SafeMode\.enabled=.*$/SafeMode\.enabled="False"/' /etc/natinst/share/ni-rt.ini

Printing file contents to command line

Considering the above command of modifying a file, we can print the contents of the file for verification:

admin@Wirebird-Labs-myRIO:~# cat /etc/natinst/share/ni-rt.ini

[ETH0]

dhcpipaddr="192.168.1.180"

[SYSTEMSETTINGS]

SafeMode.enabled="False"

ConsoleOut.enabled=False

NoApp.enabled=False

NoFPGAApp.enabled=False

sshd.enabled=True

ubifs_writeback_centisecs="300"

ubifs_expire_centisecs="300"

host_name="Wirebird-Labs-myRIO"

... truncated for brevity ...

[RTLINUXMEMRESERVE]

Base=24

admin@Wirebird-Labs-myRIO:~#

Determining current runlevel

To determine the current runlevel, which would indicate which initialization scripts were run when the session began, use the following command:

(safemode) admin@NI-myRIO-1900-0303b79c:~# runlevel

N 5

(safemode) admin@NI-myRIO-1900-0303b79c:~#

This output indicates the current runlevel is 5, and the "N" means the runlevel has not changed this session.

Programmatically Rebooting

The following command reboots immediately, which will also eventually terminate the SSH session. You must re-establish the SSH connection once the device has rebooted. Also, on the myRIO, assuming the above command was executed to enable Safe Mode, on power up the Status LED on the myRIO will flash 3 times every few seconds indicating Safe Mode.

admin@Wirebird-Labs-myRIO:~# reboot                         

The system is going down for reboot NOW!bs-myRIO (pts/0) (Sun May  4 01:17:04

The system is going down for reboot NOW!bs-myRIO (pts/0) (Sun May  4 01:17:04

[here is where Terminal goes unresponsive for a while, and then loses the SSH connection]

admin@Wirebird-Labs-myRIO:~# Write failed: Broken pipe

Jacks-27-iMac:~ jackdunaway$

Installing a package

There's a more detailed tutorial over here, but you can use opkg to install a package by specifying the hosted URL of the package. Anecdotally, I've found better success doing this in Safe Mode; your mileage may vary:

(safemode) admin@Wirebird-Labs-myRIO:~# opkg install http://feeds.angstrom-distribution.org/feeds/v2013.12/ipk/eglibc/armv6-vfp/base/libc6_2.18-r2013.10....

Downloading http://feeds.angstrom-distribution.org/feeds/v2013.12/ipk/eglibc/armv6-vfp/base/libc6_2.18-r2013.10.....

Multiple packages (libc6 and libc6) providing same name marked HOLD or PREFER. Using latest.

Upgrading libc6 on root from 2.11.1-r7 to 2.18-r2013.10.1...

Removing obsolete file /lib/libutil-2.11.1.so.

Removing obsolete file /lib/libnsl-2.11.1.so.

Removing obsolete file /usr/libexec/getconf/XBS5_ILP32_OFFBIG.

Removing obsolete file /usr/libexec/getconf/XBS5_ILP32_OFF32.

Removing obsolete file /lib/libnss_dns-2.11.1.so.

... truncated for brevity ...

Removing obsolete file /lib/libdl-2.11.1.so.

Configuring libc6.

Chaining commands to execute conditionally

Here's a useful example of two commands chained to turn off Safe Mode and then reboot, but only reboot if the first command succeeded with the && chaining operator:

(safemode) admin@Wirebird-Labs-myRIO:~# sed -ir 's/SafeMode\.enabled=.*$/SafeMode\.enabled="False"/' /etc/natinst/share/ni-rt.ini && reboot   

The system is going down for reboot NOW!s-myRIO (pts/0) (Sun May  4 01:35:35

Deleting Files

As an example, the myRIO ships with some README files for legacy migrations, and we can safely delete these:

admin@Wirebird-Labs-myRIO:~# rm /README_File_Paths.txt && rm /README_File_Transfer.txt && rm -r /c && rm -r /C

Placeholder for you: got any tips?

This document is open for editing and comments!

Comments
BradM
Active Participant
Active Participant
on

A couple of tips that I use often:

Transfering a lot of files to a target easily (requires a unix-like OS or setup, e.g. cywin installed with ssh support)

tar czvf - (directory that has the files you want, or specifically call out the files) | ssh username@target "tar xzvf - (optionally, provide a -C /path/to/where/you/want/things/)

Breakdown of command: tar (concatinate archive) the following files (create), compress (using zlib compression), be verbose and list the files going into the archive, and create the archive on the shell's stdout (output to the console unless piped to an additional command for processing. This is the -). Pipe the results of this operation (the compressed tar file) to the ssh command. The ssh command will execute the following command on the remote target, using the stdout of the tar command as the stdin of the following command: "tar xzvf -". You could probably figure that this is just extracting the compressed tar file that is on stdin. It's a bit complex but it encapsulates some important, UNIX-y concepts and is useful at the same time.

A slight modification of the previous:

Backing up files from the target:

ssh user@target "tar czf - /file/you/want/to/backup /directory/that/you/want/to/back/up /only/certain/files/that/match/*.txt" | dd of=backup.tar.gz

Breakdown: Here, the flow of data is reversed (compressing on the target and sending to the host). Also shown is multiple types of listings for file locations and filters for files to be included in the archive. Finally, we use the super-handy "dd" to dump stdin (stdout from the tar command run on the target) to the file backup.tar.gz. You can use something like 7zip to open this file.

Accessing a Windows Share from the target

opkg install cifs

(the next step depends on how you have the share configured, I'll give two examples)

mount.cifs -o guest //windowsmachine/share /local/mountpoint

mount.cifs -o user=windowsuser //windowsmachine/share /local/mountpoint (it will prompt you for the password)

/local/mountpoint refers to a folder on the target where you'd like the contents of the windows share to show up.


Zach J
NI Employee (retired)
on

@BradM,

CIFS can get confusing for some people, especially when they do not know a good set of methods for finding shared directories on network resources they have not configured themselves.  Smbclient can be a really useful tool in listing all directories that are shared on a specific network resource.  As an example:

smbclient -L \\\\windowsmachine -U username -W workgroup(or domain)

will list all shares on the network resource that the specified user can access.  If the user has a password, smbclient will prompt for a password, then list the aforementioned information.  It is a neat trick to ensure you have the correct path to a shared directory.  To gain access to smbclient, the user would need to install samba:

opkg install samba

which may or may not run into the libc6 issue, but that can be ignored with --nodeps if all other samba requirements are installed first. 

| Zach J. | Systems Engineer, HIL and Test Cells | National Instruments |
wirebirdlabs
Member
Member
on

Aha, these tips about transferring files to/fro are precipitously close to the next set of SSH command tips I've been wanting to add to the doc. But I've not yet found a reliable solution worth sharing yet.

It deals with two topics -- system deployment/replication, and also using the device as a dev environment for compiling libraries (rather than cross-compiling) -- and both these topics need the ability to reliably transfer (and persist!) lots of files to and fro.

Perhaps let's just open a dialog in the discussion forum, and then merge findings back into this document? I need to ask a few questions and get some better understanding

Staab_Engineering
Member
Member
on

JackDunaway wrote:


Perhaps let's just open a dialog in the discussion forum, and then merge findings back into this document? I need to ask a few questions and get some better understanding                    

Good discussion there! Did you ever merge those commands back in?

andre.buurman@carya
Active Participant
Active Participant
on

You could use a scp (secure copy) client like winscp for Windows that provides a  ftp like experience. It uses ssh as basis.

Regards,
André (CLA, CLED)
Simorgh
Member
Member
on

Hello,

Thank you for this useful list!

Are there commands to retrieve the Device Name, Serial Number, Product Code?

Other Information about the device?

ScotSalmon
Active Participant
Active Participant
on

fw_printenv has that data.

Simorgh
Member
Member
on

Thank you Scott.

How do you know that? Do you have a source about Linux RT SSH / Terminal Commands?

Is there a manual form NI about their Linux RT?

Simorgh
Member
Member
on

I edited the SafeMode.enabled entry in the ni-rt.ini on my cRIO 9035 Linux RT device in the way it was described above.

I double checked and the cat command printed the value I set. But after the reboot, the device was not in SafeMode if I set SafeMode.enabled="True" or if the device was in SafeMode i couldn't get it back to normal mode by SafeMode.enabled="False".

What is wrong here?

ScotSalmon
Active Participant
Active Participant
on

As far as where I learn about NI Linux RT commands, generally they are the same as on other Linux distributions and I learn about them online, for example in this case http://elinux.org/U-boot_environment_variables_in_linux

In cases where NI Linux RT is different from other distributions, you're in the right place to find out those details -- this forum.

Regarding SafeMode.enabled -- why do you need to set that? Generally there should be no reason to enter safe mode except if (a) something is wrong and you can't boot to run mode or (b) you need to install software from MAX. In both of those cases the system will enter and exit safe mode automatically and you don't need to tell it to do so. In some subset of case (a), the target doesn't enter safe mode automatically, but if it's not booting to run mode, you won't be able to programatically modify that setting anyway -- that case is when you enter safe mode by holding down the reset button for 5+ seconds as described in the device's manual.

As to why it didn't take effect, if I remember right that setting is cleared on reboot. In other words you set it once, and the next boot is the requested mode, and then it returns to the default (run mode) setting. Could that explain what you observed? But again, normally you don't actually need to use it. It's probably not a great example in the original document without a use case explaining why.

BradM
Active Participant
Active Participant
on

ScotSalmon wrote:


                       

...

As to why [editing the ini] didn't take effect, if I remember right that setting is cleared on reboot. In other words you set it once, and the next boot is the requested mode, and then it returns to the default (run mode) setting. Could that explain what you observed? But again, normally you don't actually need to use it. It's probably not a great example in the original document without a use case explaining why.


                   

This is the reason that we don't recommend editing the file directly: it does work on Zynq-based targets (906x, myRIO, etc.) but not x64-based targets (903x, etc.) The disconnect is in the different boot flows due to different bootloaders.

Basically, don't edit the ni-rt.ini file directly and expect that it does anything, except when it leaves your controller in a bad state. So, don't edit it directly.

artyom.kazaryan.2013@mail.ru
Member
Member
on

How to change locale settings for Russian language?

BradM
Active Participant
Active Participant
on

Currently, the base Linux image does not have traditional locale support built in as most distributions do, you would need to rebuild the image to support traditional locales, however this has not been tested as far as I know.

Further, only certain applications actually have localization support (e.g. use something like pango or libintl for localized resource files), so be sure to do a little research before expecting things to suddenly all be in Russian by just enabling a locale.

artyom.kazaryan.2013@mail.ru
Member
Member
on

Thank you for answer BradM,

I try to add UTF-8, but in NI Linux RT  locale command not work (not instelled)

artyom.kazaryan.2013@mail.ru
Member
Member
on

How to install and configure new locale (Russian) settings in NI Real time Linux?

BradM
Active Participant
Active Participant
on

One approach would be to do what I'd posted above: rebuild the image to have UTF-8 support and to install Russian locales. Also, as I stated, that won't make all UIs (graphical or console) localized, only certain programs have localized resource packages (that needs to be installed separately).

Let's take a step back, what is your overall goal? What aspects of the OS do you want localization support for? LabVIEW? Other programs? Console-based programs or desktop/GUI programs?

artyom.kazaryan.2013@mail.ru
Member
Member
on

I have Labview app which send Russian string from NI Linux RT to web GUI (by web socket), but in web GUI the Russian string displays not correct symbols.

BradM
Active Participant
Active Participant
on

OK, that makes more sense. You should start another discussion since this is not really related to the original topic and deserves its own thread.

Active Participant
Active Participant
on

That's not helpful, Brad. Artyom, this is probably what you need: https://decibel.ni.com/content/docs/DOC-10153

timtamslam
Active Participant
Active Participant
on

Keep in mind that that document only applies to LabVIEW on Windows and Unicode is not officially supported.

Tim A.
BradM
Active Participant
Active Participant
on

David Staab, my comment was not intended to be helpful regarding coming to a solution to the problem that Artyom mentioned, rather it was directed towards keeping discussion threads clean and focused. Something you've derailed further with a suggestion that would fit wonderfully in a topic that focuses on solving the actual issue that Artyom is seeing. A problem that has nothing to do with "Useful SSH commands", what this topic should be about.

artyom.kazaryan.2013@mail.ru
Member
Member
on

I think it's similar to  "Set a new Hostname (the name of the device)" section

Contributors