Saturday, 4 August 2018

Introduction to Crostini - Part 3: Using Ubuntu by default


When starting the default Crostini container Debian 9 (stretch) is run. Whilst you can add containers of other distros it is also possible to change to default container to Ubuntu or even potentially other distros. This is because all the Crostini/Chrome integration packages are publicly available as '.deb' packages.

The process for creating an Ubuntu default container is quite detailed but essentially consists of creating an Ubuntu container, preparing and then adding the Crostini packages, setting the hostname and user account, optionally installing additional packages. Then if the Ubuntu container has been built on a different Linux machine export the container as a compressed tarball, copy to the Chrome device and import the tarball as an image. Finally move the current default container sideways and replace it with the new Ubuntu container. The Crostini packages need a preparatory step as although they install without issue on Debian, with Ubuntu there is an installation issue with the 'cros-ui-config' package that needs resolving first. The following commands detail the actual steps required.

Start by entering the Chrome shell by pressing CTRL+ALT+T then enter the VM:

vsh termina

and clone a new Ubuntu container (e.g. eskimo):

lxc image copy ubuntu:18.04 local: --alias bionic
lxc launch bionic eskimo

Next enter the new container and prepare for installing the Crostini packages:

lxc exec eskimo -- bash

apt update
apt upgrade
echo "deb https://storage.googleapis.com/cros-packages stretch main" > /etc/apt/sources.list.d/cros.list
if [ -f /dev/.cros_milestone ]; then sudo sed -i "s?packages?packages/$(cat /dev/.cros_milestone)?" /etc/apt/sources.list.d/cros.list; fi
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551
apt update
apt install binutils
apt download cros-ui-config # ignore any warning messages
ar x cros-ui-config_0.12_all.deb data.tar.gz
gunzip data.tar.gz
tar f data.tar --delete ./etc/gtk-3.0/settings.ini
gzip data.tar
ar r cros-ui-config_0.12_all.deb data.tar.gz
rm -rf data.tar.gz

If the container is being prepared externally on a Linux machine I've found it is necessary set up some additional dependencies first:

mkdir -p /opt/google/cros-containers/bin/sommelier
mkdir -p /opt/google/cros-containers/lib/
apt install libgl1-mesa-dri
cp /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so /opt/google/cros-containers/lib/

Now install the Crostini packages:

apt install cros-adapta cros-apt-config cros-garcon cros-guest-tools cros-sftp cros-sommelier cros-sommelier-config cros-sudo-config cros-systemd-overrides ./cros-ui-config_0.12_all.deb cros-unattended-upgrades cros-wayland # ignore any warning messages
apt install cros-guest-tools ./cros-ui-config_0.12_all.deb # ignore any warning messages
rm -rf cros-ui-config_0.12_all.deb
sed -i 's/Ambiance/CrosAdapta/' /etc/gtk-3.0/settings.ini
sed -i 's/ubuntu-mono-dark/CrosAdapta/' /etc/gtk-3.0/settings.ini
sed -i 's/gtk-sound-theme-name = ubuntu/gtk-font-name = Roboto 11/' /etc/gtk-3.0/settings.ini
sed -i '5d' /etc/gtk-3.0/settings.ini
sed -i -n '2{h;n;G};p' /etc/gtk-3.0/settings.ini

Set the hostname:

sed -i '1cpenguin' /etc/hostname

and set the user account ('linuxiumcomau' in this example):

killall -u ubuntu
groupmod -n linuxiumcomau ubuntu
usermod -md /home/linuxiumcomau -l linuxiumcomau ubuntu
usermod -aG users linuxiumcomau
loginctl enable-linger linuxiumcomau
sed -i 's/ubuntu/linuxiumcomau/' /etc/sudoers.d/90-cloud-init-users

For full cursor support install the 'adwaita-icon-theme-full' package:

apt install adwaita-icon-theme-full

Optionally install additional packages (e.g. a full desktop and a VNC server together with access):

apt install ubuntu-desktop^ lxde lxde-common tightvncserver

Finally shutdown the new container:

shutdown -h now

If the container is being built on on a different machine:

lxc publish eskimo --alias eskimo
lxc image export eskimo eskimo

then copy the file 'eskimo.tar.gz' by USB to the Chrome device into the default penguin container using the 'Files' app and then pull the file from the container to the VM:

lxc file pull penguin/home/linuxiumcomau/eskimo.tar.gz $LXD_CONF


Now on the Chrome device:

lxc stop --force penguin
lxc rename penguin google

and finally either:

lxc rename eskimo penguin

or for the remotely prepared container:

lxc image import $LXD_CONF/eskimo.tar.gz --alias eskimo
lxc init eskimo penguin



Now reboot and try running the terminal to start the 'penguin' container.

If Linux fails to start check container status with 'lxc list'. If it is stopped then start the container with 'lxc start penguin'. Then login as 'linuxiumcomau' with the command 'lxc exec penguin -- /bin/login -f linuxiumcomau' and this should startthe terminal. Thereafter is should function as normal.


The Crostini packages enable Chrome OS to become the desktop environment for the Linux container:


Currently the icons for Linux apps are jumbled in with the Chrome applications however this will change in the next release (see below). Also the Crostini integration relies on Chrome APIs (most likely OAuth 2.0 client IDs) which means that the integration on Chromium OS will fail if they are not included (e.g. the build I provide in Part 2 or the current CloudReady image from Neverware).

So for testing I recompiled the latest Chromium OS source together with my personal API keys and imported the 'eskimo' image previously created. After installing the new Chromium OS image this is what my applicaitions menu looked like:


and after importing and replacing the default container with Ubuntu an additional icon appeared:


As the Chrome menu is now the UI (or desktop) to the Linux container it has changed moving forward to now grouping all the Linux apps in a Linux folder:




and application icons are displayed when Linux apps are run:


One point to note is that if the Linux container is accessed remotely using VNC for example then remotely run applications get displayed locally on the Chrome device:


because this is a feature of using the Crostini/Chrome integration.


Please donate if you find this guide useful using the following link http://goo.gl/nXWSGf.







48 comments:

  1. Thanks to azumafuji for the following comment on r/Crostini:

    After you set the user account with your username run the following command:

    # loginctl enable-linger USERNAME

    Where USERNAME is your username you set in the previous step. Behind the scenes this start garcon and sommelier as your user when the container boots so they are already running. You won't need to login via crosh and lxc and you should just be able to launch apps as you did with the Debian container.

    ReplyDelete
  2. I followed your instructions for setting up Ubuntu. Launcher icons and browser redirects work. But Files integration gets this error - any idea how to fix it? Thanks!

    https://imgur.com/a/cTu4w6Q

    ReplyDelete
  3. Nevermind, I used my normal username when setting this up, instead of my test one. Sorry!

    ReplyDelete
  4. I noticed that /usr/bin/run_container.sh adds the user to the "users" group. You might want to add the instruction:

    usermod -aG users username

    ReplyDelete
  5. I've noticed an issue where the mouse pointer and the cursor in VS Code are very small. This doesn't happen in the default Debian container. Any ideas?

    And thanks for this great post BTW!

    ReplyDelete
  6. The small cursor issue is seen in Firefox too... any ideas how to fix it? I tested Debian and there was a regular-sized cursor.

    ReplyDelete
    Replies
    1. I've had a look and I can't see any difference between the official Google Crostini container and one built based on Debian stretch and the concepts in the post above (i.e. the Crostini packages all install without any modification required).

      I also don't experience a small cursor either in the self-built Debian container, the official Crostini Debian container or the above built Ubuntu container (with desktop packages added) so maybe VS Code alters a default somewhere?

      Delete
    2. VS Code's cursor is normal-sized in the official container. My Ubuntu container is relatively new (built since 69 went to beta on the Pixelbook about a week ago). I have a backup of an Ubuntu container I created some time ago, I'll try that and report back.

      Delete
    3. Having the same issue with graphical (X) apps in both my Ubuntu containers (but not in Debian). My Pixelbook has a fairly high-res screen, could that be the cause?

      Delete
    4. Does this help: https://www.reddit.com/r/Crostini/comments/9g1ovl/scale_and_dpi_in_sommelierrc/
      or this:
      https://chromium.googlesource.com/chromiumos/docs/+/master/containers_and_vms.md#Why-are-windows-sometimes-tiny_fuzzy

      Delete
    5. I've tried those things, and they affect text sharpness and resolution, but not the mouse pointer size. It's odd, when the pointer is in the graphical program (Firefox, code, Chrome, etc) it is tiny, as soon as the pointer moves to the title bar or otherwise outside the program window, it reverts to a normal ChromeOS pointer.

      Delete
    6. I found a fix for this. There are cursors that are missing by default in Ubuntu. To fix it, do:

      $ sudo apt install adwaita-icon-theme-full

      Delete
    7. Would you add installation of adwaita-icon-theme-full to your instructions please?

      Delete
  7. fyi... https://bugs.chromium.org/p/chromium/issues/detail?id=883616

    ReplyDelete
    Replies
    1. Fixed! I've added the line:

      if [ -f /dev/.cros_milestone ]; then sudo sed -i "s?packages?packages/$(cat /dev/.cros_milestone)?" /etc/apt/sources.list.d/cros.list; fi

      before the key import to ensure the matching cros binaries are selected.

      If you have a previously build container and are now on a later version of Chrome OS (i.e. 70 or later) you can update simply by running the line as a command and then running 'sudo apt update' followed if required by 'sudo apt upgrade'.

      However judging from the thread this may break again in the future if 'cros.list' is indeed removed.

      Delete
    2. We need a way to update it to the latest package, removing the previous one, eg 70 -> 71, that way it can be added to the .profile

      Delete
    3. I've looked at this and at this stage it may be better to manually update from 70 -> 71 etc. as things are rather fluid with development. I'll keep and eye on it in the interim.

      Note with release 71 there is a new 'cros' binary that gets installed: cros-notificationsd. I'll update the instructions when release 71 hits the dev channel.

      Delete
    4. Cool thanks. Did you see my fix above for small cursors?

      Delete
    5. Yes. Is it because you are not installing the full 'ubuntu-desktop^' package that you get this issue?

      Delete
    6. Possibly.

      adwaita-icon-theme-full is actually installed in Google's Debian distro, although you can't see it with apt under Debian.

      Delete
  8. Hi, thanks for the guide! Now if I want to make some space and delete what I created, what should I do?

    ReplyDelete
    Replies
    1. Sorry, found the command already. Lazy me!

      Delete
  9. This is a little out of date now, cros-unattended-upgrades has been replaced by cros-garcon

    ReplyDelete
  10. Is breakage expected when Google updates Crostini?

    ReplyDelete
  11. To answer my own question, I reviewed the list of packages that Google installs in the Debian container: ` dpkg -l 'cros-*'` Then for each package, I used `dpkg -L packageName` to review the list of files in each package.

    Would I found is that Google installs surprising little in the containers to accomplish the integration. If this trend continues, it seems likely Ubuntu-compatibility will continue to hold.

    ReplyDelete
    Replies
    1. There is also another package that is new: adapta-gtk-theme_3.93.0.174-cros1_all.deb if you look at https://storage.googleapis.com/cros-packages

      Delete
    2. That doesn't seem to get installed even under Debian, correct?

      Delete
    3. Not according to https://chromium.googlesource.com/chromiumos/containers/cros-container-guest-tools/+/master

      Delete
    4. I don't see that package listed though:

      $ apt list|grep adapta
      cros-adapta/stable,now 0.2 all [installed,automatic]

      So how does it get installed?

      Delete
    5. I don't think it does get installed. I think it can be ignored for the time being.

      Delete
  12. I've gone through the guide and I have the folder of linux apps but none of them actually load they just act like they are loading perpetually. Where did i go wrong?

    ReplyDelete
    Replies
    1. Try rebooting your device. Sometimes the VM seems to hang.

      Delete
  13. Chrome 72 also adds a package named "cros-tast-tests". It seems to contain just tests that I'm not sure that end-users need to install or run: https://chromium.googlesource.com/chromiumos/platform/tast-tests/

    ReplyDelete
    Replies
    1. I looked into this when it first appeared and I agree that users don't need to install or run them.

      Delete
  14. FYI... haven't tried to update to CrOS 73 yet, but saw this:
    https://www.reddit.com/r/Crostini/comments/aqce3b/trouble_starting_arch_container_in_version/egf909n/

    ReplyDelete
  15. Since the Crostini packages change over time, this can be used to install all packages that start with `cros-` instead of using a hardcoded list:

    apt install $(apt-cache search --names-only 'cros-' | cut -d ' ' -f 1 | grep -v cros-ui-config)

    You still need to `apt install` your repackaged cros-ui-config package.

    ReplyDelete
    Replies
    1. The package 'cros-guest-tools' is a metapackage so really all that is now needed is:

      apt install cros-guest-tools ./cros-ui-config_0.12_all.deb

      Delete
    2. I've updated the post above accordingly.

      Delete
  16. Another awesome guide, thanx. ��
    I love getting a full desktop thru vnc but I can't seem to get any other desktops working besides LXDE. I've tried editing ~/.vnc/xstartup with gnome-session, unity, etc. to no avail.
    I hope I'm just missing something simple.

    ReplyDelete
    Replies
    1. I've also never got Gnome or Unity to work and always use LXDE.

      Delete
  17. Why did you take this stuff out?

    sed -i 's/Ambiance/CrosAdapta/' /etc/gtk-3.0/settings.ini
    sed -i 's/ubuntu-mono-dark/CrosAdapta/' /etc/gtk-3.0/settings.ini
    sed -i 's/gtk-sound-theme-name = ubuntu/gtk-font-name = Roboto 11/' /etc/gtk-3.0/settings.ini
    sed -i '5d' /etc/gtk-3.0/settings.ini
    sed -i -n '2{h;n;G};p' /etc/gtk-3.0/settings.ini

    ReplyDelete
    Replies
    1. It had become outdated to the point of being wrong and I found that everything worked without the modification. So rather than update to the correct sed commands I deleted it.

      Delete
  18. Would it work to simply copy the GTK3 version over the Google version, rather than use sed?

    ReplyDelete
    Replies
    1. By not using 'sed' you end up using the Ubuntu version rather than the Google version which seems to work fine.

      Delete
  19. This is the closest I've gotten to getting Ubuntu running straight up. I can do the exec and log into the ubuntu container but if I try to click the "Terminal" icon, first time ( when the container is stopped ) the status arrow swirls, then quits. After that, it never seems to do anything but I can exec bash in Termina and connect though.

    What am I missing?

    ReplyDelete