{"id":18127,"date":"2016-12-28T11:19:24","date_gmt":"2016-12-28T19:19:24","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=18127"},"modified":"2021-06-11T10:58:15","modified_gmt":"2021-06-11T17:58:15","slug":"using-the-chroot-ssh-trick","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/using-the-chroot-ssh-trick\/","title":{"rendered":"Using the Chroot SSH trick"},"content":{"rendered":"<p>Recently\u00a0I created a LabVIEW graphical interface for my <a href=\"http:\/\/www.lirc.org\">LIRC<\/a> <a href=\"https:\/\/digilent.com\/shop\/raspberry-pi-2\/\">Raspberry PI<\/a> <a href=\"https:\/\/digilent.com\/blog\/using-a-raspberry-pi-as-a-universal-remote\/\">Universal remote<\/a>. The first step in this process was getting LIRC to work in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chroot\">chroot <\/a>that runs on the Raspberry Pi. You can think of the chroot as a super lightweight virtual machine that\u00a0<a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\">LabVIEW<\/a> runs in. Many folders have been mapped so they are shared between the host OS and the chroot, but LV cannot run a command (i.e. invoke an executable) that is outside the chroot. There is, however, one cheat though that would allow me to interact with LIRC when it is outside the chroot.\u00a0This cheat involves downloading an ssh client to your chroot and then using a System Exec VI to run commands outside of the chroot. This is potentially very powerful because it allows <a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:tutorials:libraries:linx:start\">LINX<\/a> users to run programs that aren\u2019t compatible with the chroot.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-18290\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26235457396_85418641f9_b-600x491.jpg\" alt=\"\" width=\"600\" height=\"491\" \/><\/p>\n<p>First, let\u2019s talk about what a chroot is exactly. A\u00a0<a class=\"urlextern\" title=\"https:\/\/en.wikipedia.org\/wiki\/Chroot\" href=\"https:\/\/en.wikipedia.org\/wiki\/Chroot\" rel=\"nofollow\">chroot<\/a>\u00a0is a Linux construct that allows a process (like the LabVIEW run-time engine) set to run as if an arbitrary directory is the root directory. The way that we use a chroot with the LabVIEW run-time engine is to act as if LV was running within a very lightweight virtual machine. There are 2 reasons that LabVIEW runs within a chroot on the BeagleBone Black or Raspberry Pi 2:<\/p>\n<ol>\n<li>Using a chroot we can make one installer which will run on several different Linux distributions and devices since the chroot contains its own set of system libraries and other operating system files.<\/li>\n<li>The LabVIEW run-time engine is compiled with options that make it incompatible with the system libraries that are included in the default operating system images used with the BBB and RPi2\/3, so the chroot allows us to include a set of system libraries for LabVIEW to use that are compiled with options that are compatible.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-18288\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/makerhub_large_logo_medium-600x338.png\" alt=\"\" width=\"600\" height=\"338\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/makerhub_large_logo_medium-600x338.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/makerhub_large_logo_medium.png 640w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Since the LIRC wasn&#8217;t\u00a0compatible with the chroot yet I spent some time on <a href=\"https:\/\/www.labviewmakerhub.com\">LabVIEW MakerHub<\/a>, and I found a technique\u00a0referred\u00a0to as the &#8220;<a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:libraries:linx:misc:chroot-ssh-trick\">Chroot SSH Trick<\/a>&#8221;\u00a0This technique allows LabVIEW to run commands outside of its chroot on a LINX 3.0 (BBB or RPi2) target. This can be useful for interacting with commands that are unavailable inside the chroot, I have detailed the steps below.<\/p>\n<ol>\n<li class=\"level1 node\">\n<div class=\"li\">Install an SSH client to your chroot:<\/div>\n<ul>\n<li class=\"level2\">\n<div class=\"li\">sudo schroot -r -c lv<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">opkg update<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">opkg install openssh-ssh<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">exit<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li class=\"level1 node\">\n<div class=\"li\">Configure pub key authentication so you don&#8217;t have to type in a password interactively (Hint: This let&#8217;s you use the SSH client from LabVIEW System Exec VI).<\/div>\n<ul>\n<li class=\"level2 node\">\n<div class=\"li\">ssh-keygen -t rsa<\/div>\n<\/li>\n<li class=\"level2 node\">\n<div class=\"li\">stick with the defaults when it prompts you, especially when it asks for the passphrase; we want an empty passphrase<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">cat ~\/.ssh\/id_rsa.pub &gt;&gt; ~\/.ssh\/authorized_keys<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">sudo mkdir \/srv\/chroot\/labview\/root\/.ssh<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">sudo cp ~\/.ssh\/id_rsa* \/srv\/chroot\/labview\/root\/.ssh\/.<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li class=\"level1 node\">\n<div class=\"li\">Now log back into the chroot and run the SSH command once so that you can add localhost to the list of known hosts<\/div>\n<ul>\n<li class=\"level2\">\n<div class=\"li\">sudo schroot -r -c lv<\/div>\n<\/li>\n<li class=\"level2 node\">\n<div class=\"li\">ssh root@localhost ls<\/div>\n<\/li>\n<li class=\"level2 node\">\n<div class=\"li\">When prompted to add localhost to the list of known hosts, say yes<\/div>\n<\/li>\n<li class=\"level2\">\n<div class=\"li\">exit<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">At this point, you can run commands from within the LV chroot in the system outside the chroot by running a command of the form\u00a0ssh &lt;root_user&gt;@localhost &lt;command&gt;. For instance, if I wanted to check the version of the Debian operation system on a Raspberry Pi I would run\u00a0ssh pi@localhost cat \/etc\/debian_version. These commands can be run in a LabVIEW VI by using the System Exec VI, so now you have a way to execute commands outside of the LV chroot.<\/div>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-18291\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26195144241_694fb7b61c_b-577x600.jpg\" alt=\"\" width=\"577\" height=\"600\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26195144241_694fb7b61c_b-577x600.jpg 577w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26195144241_694fb7b61c_b-768x798.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26195144241_694fb7b61c_b.jpg 985w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26195144241_694fb7b61c_b-800x832.jpg 800w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/p>\n<p>Thank you for reading my blog post, If you are interested in making a project but don&#8217;t have the right supplies, you can purchase the LabVIEW computing kit for the <a href=\"https:\/\/digilent.com\/shop\/raspberry-pi-2\/\">Raspberry Pi 2<\/a>. This kit includes a copy of\u00a0<a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\">LabVIEW 2014 Home Edition<\/a>\u00a0and everything you will need to run\u00a0<a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:tutorials:libraries:linx:3-0:beaglebone-black-setup\">LINX 3.0<\/a>\u00a0and start working on projects. Please comment with any questions or comments you may have.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-18127 jlk' data-task='like' data-post_id='18127' data-nonce='5286a1c13f' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-18127 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-18127 jlk' data-task='unlike' data-post_id='18127' data-nonce='5286a1c13f' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-18127 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-18127 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Austin explains a trick for getting LIRC to work in the chroot that runs on the Raspberry Pi. <\/p>\n","protected":false},"author":42,"featured_media":18290,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4327,1561],"tags":[],"ppma_author":[4493],"class_list":["post-18127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","category-applications"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/12\/26235457396_85418641f9_b-e1482953374810.jpg","jetpack_sharing_enabled":true,"authors":[{"term_id":4493,"user_id":42,"is_guest":0,"slug":"astanton","display_name":"Austin Stanton","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/0cc9db2caf6344c8f78ea46c21570f33a954c45596addf479125043e52431de0?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/18127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=18127"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/18127\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/18290"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=18127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=18127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=18127"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=18127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}