Monday, July 18, 2016

Running X Apps on Ubuntu Devices

Running X Apps on Ubuntu Devices You can install, launch, and use traditional debian-packaged X apps on Ubuntu devices. This may be unexpected given that Ubuntu devices do not seem to support user-installed debian packages, nor do they run the X Display Server. But it does work, courtesy of Mir/XMir and Libertine.

So here’s a bit of background to get started.

But first, please note that at this time, display and use of X apps on an external monitor is only available on the Pro5/M10 and on future devices. (BQ 4.5/E5 and Meizu MX4 do not support this feature.)

Hello Mir (Goodbye X)

Traditionally, and still on the Ubuntu Classic desktop with Unity 7, Ubuntu runs an X Display Server. Apps are debian packaged. And, they are written for X:

Due in part to X’s inherent security shortcomings, the Mir display server is now used on Ubuntu Devices under Unity 8 (although not yet by default on the desktop). XMir bridges traditional X apps to Mir. That is, apps written for X can run fine in a Mir/XMir environment:

Packages and the root file system

Ubuntu Classic has a root file system (rootfs) that is populated through installation of a carefully curated set of debian packages. At run time, users can install debian packages to add apps or modify their system.

This approach raises security concerns because debian packages execute installation scripts with root level privileges and because debian packages can alter what the rootfs provides by modifying or replacing core system components.

Ubuntu devices are designed for security and reliability. Ubuntu devices have a read-only rootfs that is small and tight, providing just what is needed and simplifying system updates. The rootfs is not modifiable by the user. Indeed it is mounted as a read-only partition. Users install apps through click packages that do not modify the rootfs.

Given all of this: how do users install debian packaged apps that use X on Ubuntu Devices? The answer is LIbertine with XMir.

Hello Libertine

Libertine is a system to manage app containers. It is specifically designed to support the many traditional X apps that are debian packaged. Each container is a separate Ubuntu rootfs populated through debian package installations. (Currently these containers are chroots: later, LXD contains will be supported. Also, currently the containers must be of the same Ubuntu series as the device: Vivid.)

So, you can install or create a libertine container, install debian packaged X apps into it, and launch them using the XApps scope. The apps access to the user’s key directories: Documents, Downloads, Music, Pictures, and Videos. So data files created and saved by an app in one container are available to apps in any other container, and indeed outside of the containers.

Let’s take a quick look at the XApps scope.

XApps Scope

This scope simply lists the containers and, for each container, it displays its apps. Here’s a look at a device with two containers. This system has two containers (Puritine and My Container). And each has a few apps:

  • Tap an app to launch it.
  • long press an app to hide it.
  • If you have any hidden apps, see them from the search icon (magnifying glass) and tap Hidden X Apps. Long press a hidden app to unhide it.
  • Note that a container with no apps does not display in the scope.
So how does one create and delete containers, and add or remove apps from them?

Libertine Container Manager

libertine-container-manager is a command line tool you use on the device to create and manage containers. This includes installing debian packaged apps into them. (These containers are created in the phablet user’s home directory and are not a part of the read-only rootfs.)

Note: libertine-container-manager currently cannot be run in the Terminal App. Instead please connect to your device from an Ubuntu system using phablet-shell.
Listing Containers
phablet@ubuntu-phablet:~$ libertine-container-manager list
puritine
my-container

The “puritine” container is pre-installed on many devices through the com.ubuntu.puritine click package (“Desktop Applications”):

phablet@ubuntu-phablet:~$ click list | grep puritine
com.ubuntu.puritine 0.11

The second container (“my-container”) was created on the device with libertine-container-manager.

Note: It is possible to pre-install customized containers through bespoke channels.
Creating a Libertine Container
You can create a new container on a device. The container needs a unique ID and (optionally) a name.

Note: The container must be the same Ubuntu series as the device, currently: vivid.

phablet@ubuntu-phablet:~$ libertine-container-manager create --id my-container --name "My Container" --distro vivid --type chroot

I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
I: Valid Release signature (key id 790BC7277767219C42C86F933B4FE6ACC0B21F32)
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
[...]
Listing Apps in a Container
It’s easy to list the apps in a container. You just use the container’s id, as follows:

Note: We add the optional --json argument here and show only lines with “name” for display convenience.

phablet@ubuntu-phablet:~$ libertine-container-manager list-apps --id my-container --json | grep "\"name\""
"name": "Panel Manager",
"name": "Python (v3.4)",
"name": "Python (v2.7)",
"name": "gedit",
"name": "Help",
"name": "Notification Daemon",
"name": "Terminal",
Also note that all apps that install a .desktop file are listed by this command, although many of them are not displayed in the XApps scope since they are not appropriate.
Installing an app in a container
To install a debian package in a container, you just use install-package with the container id and the debian binary package name, as follows:

phablet@ubuntu-phablet:~$ libertine-container-manager install-package --id my-container --package terminator

The package and all of its dependencies are installed in the container. After this, assuming the package installs a .desktop file, it displays in the XApps scope and is launchable with a tap as expected.
Installing an app from a specific Launchpad PPA
By default, available debian packages are installed from the standard Ubuntu archive the chroot’s apt configuration points to. You can add a launchpad PPA, as follows:

phablet@ubuntu-phablet:~$ libertine-container-manager configure --id my-container --archive ppa:USER/PPA-NAME

(Currently, private PPAs are scheduled for an upcoming release.)

After this, you can install packages into the container as usual, including from the PPA.
Removing apps from a container
Remove a debian package from a container with:

phablet@ubuntu-phablet:~$ libertine-container-manager remove-package --id my-container --package PACKAGE_NAME
Libertine-container-manager help
Use the --help for top level help.

You can see details on each subcommand, for example remove-package, as follows:

phablet@ubuntu-phablet:~$ libertine-container-manager remove-package --help
usage: libertine-container-manager remove-package [-h] -p PACKAGE [-i ID] [-r]


optional arguments:
-h, --help show this help message and exit
-p PACKAGE, --package PACKAGE
Name of package to remove. Required. -i ID, --id ID Container identifier. Default container is used if
omitted.
-r, --readline Readline mode. Use text-based frontend during debconf
Interactions.
Updating a container
Want the debian packages in a container updated? Easy:

phablet@ubuntu-phablet:~/.cache/libertine-container/my-container$ libertine-container-manager update --id my-container
Executing a Command in a Container
phablet@ubuntu-phablet:~/.cache/libertine-container/my-container$ libertine-container-manager exec --command "apt-get update" --id my-container
Atteint http://ppa.launchpad.net vivid InRelease
Atteint http://ports.ubuntu.com vivid InRelease
Atteint http://ports.ubuntu.com vivid-updates InRelease
Atteint http://ppa.launchpad.net vivid/main armhf Packages
Atteint http://ppa.launchpad.net vivid/main Translation-en
Atteint http://ports.ubuntu.com vivid/main armhf Packages [...]

Note: Running the apt-get update command in a container may be useful to update the container’s knowledge of newly available packages without installing/updating them all. You can then see whether a package is available, with:

phablet@ubuntu-phablet:~/.cache/libertine-container/my-container$ libertine-container-manager exec --command "apt-cache policy firefox" --id my-container
firefox:
Installé : (aucun)
Candidat : 44.0+build3-0ubuntu0.15.04.1
Table de version :
44.0+build3-0ubuntu0.15.04.1 0
500 http://ports.ubuntu.com/ubuntu-ports/ vivid-updates/main armhf Packages
37.0+build2-0ubuntu1 0
500 http://ports.ubuntu.com/ubuntu-ports/ vivid/main armhf Packages

More about the Libertine Containers

As noted, the container is a directory containing an Ubuntu rootfs. Container directories are here:

phablet@ubuntu-phablet:~/.cache/libertine-container$ pwd
/home/phablet/.cache/libertine-container
phablet@ubuntu-phablet:~/.cache/libertine-container$ ls
my-container puritine
phablet@ubuntu-phablet:~/.cache/libertine-container$ cd my-container/
phablet@ubuntu-phablet:~/.cache/libertine-container/my-container$ ls
rootfs

You can get a bash shell into the container as follows:

phablet@ubuntu-phablet:~/.cache/libertine-container/my-container$ libertine-container-manager exec --command "/bin/bash" --id my-container
groups: cannot find name for group ID 1001
[...]
root@ubuntu-phablet:/#

23 comments:

  1. This is really great. The ability to install Xapps was feature that I have been waiting ever since I bought my M10. Thank you for all the hard work.

    ReplyDelete
  2. Are there any plans to support X-apps already in a container in the Unity8 store in the future, so that average joe can enjoy them as well? If so how long to expect till this feature arrives? Thnaks for any insight you can give.

    ReplyDelete
    Replies
    1. Hi Sid, This may happen but one issue is the size of the container. It's typically ~600MB+ so installing it from the store is a bit awkward. Also, if you use such a pre-made container and modify it, your modifications might be overwritten on next update from the store. So there are a couple issues still to sort.

      Delete
  3. any time a gui for manage this feature?

    ReplyDelete
    Replies
    1. Hi Jacopo: I have heard around that an app is in the works but I don't have anything definitive.

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

    ReplyDelete
  5. They're planning direct store integration eventually.

    ReplyDelete
  6. They're planning direct store integration eventually.

    ReplyDelete
    Replies
    1. http://insights.ubuntu.com/2016/08/04/use-any-app-from-your-ubuntu-phone-or-desktop/

      Delete
  7. Is it possible to run an X app on the BQ tablet without an external monitor and keyboard? All the news stories say that desktop apps are only enabled by attaching an external monitor and keyboard.

    ReplyDelete
    Replies
    1. Yes it is possible, but since some of the buttons are small it might be a bit tricky to hit them correctly.

      Delete
  8. I can't make it work, I don't even see my container. When I run the container list I it shows it and I can find my installed packages (leafpad, vlc and Rhythmbox), but nothing is displayed. I restarted the system, just in case. Any suggestions?

    Thanks

    ReplyDelete
    Replies
    1. You need to ensure you have the "Desktop Apps" scope installed from the store to have applications surfaced on the system.

      Delete
    2. I have the M10, luckily it is already installed. And it is visible and works perfect.

      Delete
  9. Ok, I am one step further. When I use the filemanager to open a file, I can choose vlc for avi and mp4 and Rhythmbox and vlc for mp3, but instead of opening the file it returns back to the filemanager. But when I want to open a txt-file, I neither can choose gedit nor leafpad.

    ReplyDelete
  10. I can run vlc just fine on my M10, but when I start musescore or audacity my device starts rebooting spontaneously. Is this a known issue ?

    ReplyDelete
  11. I get the error:-

    dpkg: dependency problems prevent configuration of matchbox-keyboard:
    matchbox-keyboard depends on libfakekey0 (>=0.1); however:
    Package libfakekey0:armhf is not configured yet.

    I'm not sure if this is an issue with OTA-13, or what I should do about it... but I'm worried that there didn't seem to be any cleanup, so can someone advise what I'm doing wrong, and/or if I need to manually clean up some folders to avoid filling up my device?

    ReplyDelete
  12. I am huge fan of Libertine myself, but I would like to let you know that there is also a way for running x11 apps on the phone without it, also via Xmir. I wrote an article about it: http://kriscode.blogspot.tw/2016/09/x-applications-on-ubuntu-phone.html

    ReplyDelete
  13. I, personally think that Libertine is a "game changer" for "Linux" in terms of "selling a laptop or tower" to the "new to computers" or "considering leaving Windows or Mac". When the sales person says, "tap / click here" and twenty apps appear to install then the sale is made.....IF ...and only IF.... the system is AS... failsafe as can be possible. and updates in the background and unobtrusively. The only thing would be to add.... when the computer is turned on, that somehow the "system" "figures out if everything is ok. If not it somehow, sends a message and says: "I'm going to sleep now for a few minutes, all of your documents etc. are safe and I will see you in a few minutes." It does it, comes back up and....Windows is history.

    ReplyDelete
  14. Hi on the xapps is it possible in the container to add new ppas so that you can add other packages then whats in vivid?
    Hide Apps

    ReplyDelete
  15. Nice to Read, Cresol is the best Mobile Application Development Company who serve best quality Android & iOS applications. People may not always have access to a computer but always have their smartphone.

    ReplyDelete
  16. Hi - Thanks for the HowTo!

    I've got the Libertine container working, and verified it by downloading Terminator!

    But I'm struggling to get the apps I'd like: e.g. Remarkable, Symphytum & MuseScore. Do I have to do something other than --package PACKAGE_NAME?

    Any light you can shed would be much appreciated.

    ReplyDelete