Pages

13 March 2013

Chromebook X-Windows Setup Using Crouton

The popular Crouton script, which enables you to run Ubuntu Linux alongside Chrome OS can be used simply to run secure shell (SSH) and X Windows and this can all be done without the virtual display switching keystrokes CTRL-ALT-F3.  I tried the script and really didn't want a second environment to switch to and from.  Considering that Chrome OS uses Linux and X Windows, I should be able to display X Windows on the same display as the Chrome browser.  This is possible and easy to do but you will find issues along the way.  Getting an X Window application displayed alongside the Chrome browser is possible as seen below.

xterm displayed with Chrome browser
Chrome OS Running Xterm and Twm

Follow the instructions to install Crouton on your Chromebook.  I am using Hexxeh's build in a virtual machine.  Add Tom's Window Manager (twm) window manager since the Chrome OS window manager won't manage X Window applications other than the Chrome browser itself.  Then you'll need to set the PATH and LD_LIBRARY_PATH variables to point to the libraries needed for twm and xterm.  You can view my bash_profile changes here.  Note that I named my chroot crouton not precise, so you will have to use the right name for you in the variables and also note that the chroot environment is not encrypted.

This setup is only so I can use SSH and X Windows to remote machines.  Many other applications are expecting config files in /etc which would use the Chrome OS /etc which doesn't support them.  It is possible to compile the binaries so they use /usr/local, like other operating systems do, but I just needed those two functions without switching windows to a whole new environment. It is possible that someone might make a project to use the native non-chroot environment, but that would require making packages just for native usage and why bother when you can piggy back off of the work done for Ubuntu?

Xterm Window without X Window Manager
Unmanged xterm on Chrome OS

The picture above show the xterm session isn't attached to a window manager.  I ran 'twm &' so the X Windows applications could be managed. They can be minimized, maximized, and moved around with ease.  Note that with two window managers running, I don't get twm menus but that is okay since I only want basic X window and SSH functionality.

Remote X Window Application In ChromeOS
Firewall Builder Displayed in Chrome OS

You can also run ssh remotely and bring up windows from other servers, which is what I was hoping to do.  To do that, note that there are no magic cookies (i.e. no .Xauthority file) so SSH will refuse to work.  I just cheated and issued an "xhost +" to enable access.  You can see Firewall Builder up and running from the remote server but it is not possible to tell that it is was started remotely so you'll have to take my word for it.

Here are some important in-between steps captioned to explain what they are for.
Example bash profile settings for PATH and Library PATH
PATH and LD_LIBRARY_PATH settings for Chrome OS

Running twm alongside another window manager
Start twm and xterm in Chrome OS

What isn't depicted, is the "sudo apt-get install twm" command done while in the chroot environment.  Twm is made available in /usr/bin from the apt instaalation.  So, you must have entered the chroot before running the install command for twm.

Acquiring a cheap Chromebook to run Linux on is a popular idea.  But I already have three other physical machines with Ubuntu, so I don't need another one.  I wanted a lightweight device to do remote work into my other Ubuntu machines and enabling X Windows applications to display on Chrome OS was enough for me but your mileage and needs may vary.


20 comments:

  1. Hi David,

    I'm really interested in this so thank you.

    I'm trying to generate python plots without having to log into unity and this seems like the best method I've seen so far. However, when I try to run xterm I get the following error:

    chronos@localhost / $ xterm
    xterm: error while loading shared libraries: libXaw.so.7: cannot open shared object file: No such file or directory

    Did you run into this problem? The 'twm &' command isn't working either (see below) but I assume I need to figure out this xterm issue first.

    chronos@localhost / $ twm: another window manager is already running. on screen 0?
    twm: unable to find any unmanaged video screens.

    Thanks again,

    Ben

    ReplyDelete
    Replies
    1. This post is old compared to the speed of updates:

      1) Ensure LD_LIBRARY_PATH is set correctly. To be sure use find / -name libXaw.so.* -print. It might be a different version. You might need to link or copy libXaw.so. to libXaw.so.7 in that directory.
      2) twm issue: Sadly, this took advantage of the fact that the Chrome window manager didn't report to X applications that it is a window manager. See how xterm works without twm. It may no longer be an issue.

      Delete
    2. David,

      You're right. I am using the 64 bit version but my path was still pointing to the i386. The libXaw.so.7 file was in the 64bit directory like this:

      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/chroots/precise/lib/x86_64-linux-gnu/:/usr/local/chroots/precise/usr/lib/x86_64-linux-gnu/:/usr/local/chroots/precise/lib:/usr/local/chroots/precise/usr/lib/
      export PATH=$PATH:/usr/local/chroots/precise/usr/bin

      Once I corrected and logged back in it works! It doesn't like dual monitors (continually resets display) but seems to work fine with just one.

      Thanks! Ben

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi David. Great post, thank you.
    I was thinking about getting a Toshiba Cromebook 2 (2015) to connect to my linux server with.
    Have you tried using xdmcp? In the past, I've connected low-grade boxes to high-end servers by attaching the local xserver to a remote xserver. My desktop on the low-grade box was the same as if I had been on the console of the high-end server.
    Do you know if I can do this Crouton?

    ReplyDelete
    Replies
    1. You might be able to, but I haven't tried it. Try something like X :1 -query remote_hostname_or_ip_address_1. You may need to use :2.

      You really want alternate X sessions and CTRL keys mapped as described in http://unix.stackexchange.com/questions/85383/how-to-start-a-second-x-session

      XDMCP is not secure (https://wiki.ubuntu.com/xdmcp) so I only use it in LAB settings.

      Delete
    2. Thank you for the link, I'll be sure and check it out.

      And I only plan to use XDMCP inside my home network so I should be ok (unless my kids decide to hack me! ;)

      Again, great article and thanks.

      Delete
  5. I followed your instructions and when i try to run xterm it keeps saying
    bash: /usr/local/chroots/precise/usr/bin/xterm: Permission denied
    and then if i use sudo xterm I get
    sudo: xterm: command not found
    Do you have any clue what I am doing wrong?

    ReplyDelete
    Replies
    1. Maybe nothing. Paths might have changed since I wrote this. I see you have "precise" instead of "crouton," so I am not sure what is new. To be sure, run the following three commands paste their output.

      ls -l /usr/local/chroots/precise/usr/bin/xterm
      file /usr/local/chroots/precise/usr/bin/xterm
      find / -name xterm -ls 2> /dev/null

      Delete
    2. chronos@localhost / $ ls -l /usr/local/chroots/precise/usr/bin/xterm
      -rwxr-xr-x 1 root root 433408 Oct 1 2012 /usr/local/chroots/precise/usr/bin/xterm
      chronos@localhost / $ find / -name xterm -ls 2> /dev/null
      394399 4 drwxr-xr-x 2 root root 4096 Jan 14 10:40 /mnt/stateful_partition/crouton/chroots/precise/usr/share/doc/xterm
      144951 4 -rw-r--r-- 1 root root 440 Oct 1 2012 /mnt/stateful_partition/crouton/chroots/precise/usr/share/menu/xterm
      525131 4 -rw-r--r-- 1 root root 1604 Mar 21 2012 /mnt/stateful_partition/crouton/chroots/precise/usr/share/vte/termcap-0.0/xterm
      394667 16 -rw-r--r-- 1 root root 15776 Oct 15 2010 /mnt/stateful_partition/crouton/chroots/precise/usr/share/icons/DMZ-Black/cursors/xterm
      394613 16 -rw-r--r-- 1 root root 15776 Oct 15 2010 /mnt/stateful_partition/crouton/chroots/precise/usr/share/icons/DMZ-White/cursors/xterm
      144948 424 -rwxr-xr-x 1 root root 433408 Oct 1 2012 /mnt/stateful_partition/crouton/chroots/precise/usr/bin/xterm
      132844 4 -rw-r--r-- 1 root root 3213 Nov 18 2011 /mnt/stateful_partition/crouton/chroots/precise/lib/terminfo/x/xterm
      17047 4 -rw-r--r-- 1 root root 2564 Jan 6 23:41 /usr/share/cursors/xorg-x11/chromeos/cursors/xterm
      55600 4 -rw-r--r-- 1 root root 3270 Jan 6 23:19 /etc/terminfo/x/xterm
      chronos@localhost / $ file /usr/local/chroots/precise/usr/bin/xterm
      bash: /usr/local/chroots/precise/usr/bin/file: Permission denied

      Delete
    3. Well, the execute bit is set but you have no permission. Check to see if the volume is mounted with noexec.

      http://superuser.com/questions/728127/what-does-noexec-flag-mean-when-mounting-directories-on-rhel

      Type "mount" and look for noexec in the options column.

      Delete
    4. Alright so after some tweaking, I got all the libraries for xterm and twm. However when I run xterm, it gives me:
      xterm Xt error: Can't open display:
      xterm: DISPLAY is not set
      and for twm:
      twm: unable to open display ""

      I tried manually exporting the display with DISPLAY=:0
      but all it says is Can't open display: :0

      Thanks

      Delete
    5. Try

      export DISPLAY=127.0.0.1:0 # sometimes omitting localhost breaks X

      Delete
  6. Hi David,

    Thank you for a very useful post.

    While trying to get xterm up on Version 60.0.3112.114 (Official Build) (64-bit) and chroot xenial, I had to add the following to LD_LIBRARY_PATH:
    /usr/local/chroots/xenial/lib/x86_64-linux-gnu
    /usr/local/chroots/xenial/usr/lib/x86_64-linux-gnu

    Like you said, the partition had to be remounted with exec permissions:
    sudo mount -o remount,exec /mnt/stateful_partition

    Subsequently, added export DISPLAY=127.0.0.1:0 as well, but I get the following error while trying to open xterm:

    chronos@localhost ~ $ xterm
    xterm: Xt error: Can't open display: 127.0.0.1:0.0

    chronos@localhost ~ $ xhost +
    xhost: unable to open display "127.0.0.1:0"

    Do you have any idea what is missed out?

    Thanks

    ReplyDelete
    Replies
    1. When you set your DISPLAY like that, you are telling it to connect to a listener bound to localhost at port 6000. In your case, nothing is listening on 6000. For X Windows, port 6000 is :0, 6001 is :1, and so on. Check with 'netstat -an | more' to see if you have anything on port 6000. The problem with X is that is doesn't have to use a TCP socket. It might have been switched to a named socket like the Mac. A Mac might have a DISPLAY=/private/tmp/com.apple.launchd.46CQvk1KcX/org.macosforge.xquartz which is a named socket on the filesystem.

      Try 'export DISPLAY=:0' and see if that works. If not, look for a socket.

      See the discussions -> https://ubuntuforums.org/showthread.php?t=1310771
      and https://www.linuxquestions.org/questions/linux-newbie-8/display%3D-0-0-vs-display%3Dlocalhost-0-0-a-933940/

      Delete
    2. Thanks for your reply.

      My understanding about X / ChromeOS is limited, but this is what I could figure out while browsing through Internet.

      Looks like Chrome OS has moved away from X server to Freon. From a few discussions I saw, migration seems to have started around 2015. (https://www.phoronix.com/scan.php?page=news_item&px=Chrome-OS-X11-Free)

      So, possibly Chromebook no longer runs X server. Hence, there isn't anybody any longer listening to ports 6000. and hence I am unable to open display from chrome shell.

      To open the display, one would have to start X server using chroot environment and then connect to the same. That is what xiwi seems to be doing. (https://github.com/dnschneid/crouton/wiki/crouton-in-a-Chromium-OS-window-(xiwi))

      Do you think it makes sense?

      Thanks again.

      Delete
    3. That makes sense. I didn't think X windows would last forever. Perhaps I I should remove this blog.

      Delete
    4. I found blog useful and learnt a few things. No harm in keeping it IMO.

      Delete