Recommended way to install regular(cli) .deb packages on Ubuntu Phone?

Create a chroot inside the home directory:

mkdir -p vivid-chroot
cd vivid-chroot
wget http://cdimage.ubuntu.com/ubuntu-touch/vivid/daily-preinstalled/current/vivid-preinstalled-touch-armhf.tar.gz
sudo tar -zxvf vivid-preinstalled-touch-armhf.tar.gz

Then, use the chroot and install whatever CLI tools you need to use, within that chroot:

cd ~/vivid-chroot
sudo chroot .
apt-get update
apt-get install git

In order to perform certain things, it may be required to bind mount some directories. You will need to take extra care when doing so, if you wish to delete the chroot from your phone, or perform other destructive actions.

sudo mount --bind /proc /home/phablet/vivid-chroot/proc
sudo mount --bind /dev /home/phablet/vivid-chroot/dev
sudo mount --bind /sys /home/phablet/vivid-chroot/sys

This isn't an exhaustive list, but you can bind mount other directories as needed in similar fashion. You need not create the chroot in your home directory if you have an external storage device to create it on, such as an SD card. However, not all phones have SD card slots. If you wish to create the chroot on an SD card, simply replace the home directory in the commands above, with the path to a directory on your alternate storage media where you wish to create the chroot.


Warning: this is only an hack to get rid of the cross-device link problem on apt-get upgrade with powerd package. this is not a "UBUNTU" certified solution

Prerequisite: having made R/W the ubuntu installation with:

phablet-config writable-image

Copy the downloaded powerd*.deb file from the phone to a PC from the path:

/var/cache/apt/archives/

On the PC, unpack the .deb file, remove the file /usr/share/powerd/device_configs/config-default.xml (from my tests it results not foundamental):

su - root
mkdir tmp
dpkg-deb -R powerd_0.16+15.04.20150507-0ubuntu1_armhf.deb tmp
rm tmp/usr/share/powerd/device_configs/config-default.xml
mv powerd_0.16+15.04.20150507-0ubuntu1_armhf.deb old.deb
dpkg-deb -b tmp powerd_0.16+15.04.20150507-0ubuntu1_armhf.deb 

Everything must be done as root to keep the original permissions of the package files and dirs. Repack, copy back on the phone, then install with:

sudo dpkg -i powerd_0.16+15.04.20150507-0ubuntu1_armhf.deb

You will still get the error:

"/usr/share/powerd/device_configs/config-default.xml": Device or resource busy

But at the end the package is updated.

Now if you do: sudo apt-get upgrade the error disappeared.

My phone BQ Aquaris seems to work well and stable.


As has already been pointed out, you have to install an ARM-capable chroot on your device and install all the required packages in that chroot. However, doing so in your home directory wastes a lot of valuable space. Instead, it can be done on your SD-card using a computer running on an appropriate Linux OS (tested on Linux Mint 17 and Ubuntu Trusty). As I did not find any information about this anywhere else, I put it here as an answer to an old question.

The following instructions assume you want to install a debian jessie chroot in the directory jessie.

Creating and populating the image file on a desktop computer

Creating an empty image file

To create an 1GB image called IMAGE.img in the current working directory, do:

dd if=/dev/zero of=IMAGE.img bs=1G count=1

Note that the B in GB is left out. "if" stands for "input file", "of" for "output file" and "bs" for "block size".

There are more efficient commands out there, but those only work on certain types of file systems, as far as I know. This one also works on an SD-card or a tempfs. Please note the use of /dev/zero and not /dev/random or /dev/urandom as that would take a lot longer and make it take a lot longer to transfer the image between devices later on.

Creating a file system on the image

Without the file system, the phone would not be able to store any data on the image. Without a file system, you cannot yet mount the image to a directory, only to a block-device.

This bash-command will output the next empty loop device into the variable LOOP:

$LOOP=$(sudo losetup -f)

Next, assign the image to a block device:

sudo losetup $LOOP IMAGE.img

Next, create the ext4 file system on it:

sudo mkfs -t ext4 $LOOP

Next, detach the image from the loop device:

sudo losetup -d $LOOP

If you get command not found errors, just install the missing programmes.

Mount the image file on the computer to access it

Now, create a temporary directory in the working directory:

mkdir jessie

and mount the image file IMAGE.img to it:

sudo mount -o loop IMAGE.img $(pwd)/jessie

The command pwd will make sure you give mount an absolute path to your current working directory.

Populating the image with the new operating system with qemu-debootstrap

The next step will be to use qemu-debootstrap to download the necessary files. This is easy if qemu-debootstrap is available as is the case on Ubuntu and derived OSes. If you get command not found errors when executing qemu-debootstrap --help, try to install the appropriate package, which can be done on Ubuntu via:

sudo apt-get install qemu-user-static

To download all required files and ready the new OS, run the following command:

sudo qemu-debootstrap --arch=armhf jessie ./jessie http://http.debian.net/debian

Please note that the first jessie stands for the OS version whereas the second jessie stands for the directory where the files are to be installed.Now you can unmount the image as the rest of the work has to be done on the phone. Do so via:

sudo umount $(pwd)/jessie

If you cannot install qemu-debootstrap, see the next section.

Populating the image with the new operating system without qemu-debootstrap

Please skip this section if you have qemu-debootstrap available. You will still need a native debootstrap for you architecture, though. If this happens to be armhf, just use the above command line but replace qemu-debootstrap by debootstrap. If not, follow this section.

To download all required files for the new OS, run the following command:

sudo debootstrap --arch=armhf --foreign jessie ./jessie \
    http://http.debian.net/debian

Now you can unmount the image as the rest of the work has to be done on the phone. Do so via:

sudo umount $(pwd)/jessie

Transfer image to the phone

Now best create a tar archive from this which you then copy to your phone. It does not matter whether the archive is put on the SD-card or the internal storage. Create the archive on the desktop using:

tar -cvzf jessie.tar.gz IMAGE.img

Now, on your phone, turn on ssh support to copy the image over. You might also do that using a USB-cable instead. Since the ssh server is reset on every reboot, start the ssh service on the phone via: sudo service ssh start

Next, copy the image via:

scp jessie.tar.gz phablet@ubuntu-phablet:$COPYDIR

where the variable COPYDIR contains the directory where the image shall be stored. This command assumes that your username on the phone is phablet and the phone's hostname is ubuntu-phablet. You can find out both by issuing echo $USER and echo $HOSTNAME on the phone, respectively.

Now you only have to extract the archive wherever you want the image to reside. Assume the directory where you want the image to be located is stored in the variable IMAGEDIR. Extract the image there via the bash command:

( cd $IMAGEDIR; tar -xvzf $COPYDIR/jessie.tar.gz; )

You might now remove the archive:

rm $COPYDIR/jessie.tar.gz

Finalizing and using the image on the phone

If you did not turn on the ssh server on the phone, do so now via:

sudo service ssh start

Next, mount your image to a directory of your choice (in this case "jessie"):

sudo mount -o loop $IMAGEDIR/IMAGE.img $(pwd)/jessie

Now, enter your chroot for the first time via:

ssh localhost "sudo chroot $(pwd)/jessie /bin/bash"

If you had qemu-debootstrap available on your computer, you're all done. Use the above 2 commands to connect to your chroot. If not, you still have to execute the following command once you are inside your chroot, in order to properly setup the OS:

/debootstrap/debootstrap --second-stage

Summary of how to access the chroot

If you followed the above steps, you should be able to access your chroot using this simple script on the phone:

#!/bin/bash
sudo service ssh start
ssh localhost "sudo chroot jessie /bin/bash"

You have to first ssh into your own phone from the phone due to apparmor restrictions of the terminal app. The terminal app is only allowed to execute binaries in certain locations and neither your home directory nor the SD card are among those. The ssh service, however, does not have such restrictions.

Tags:

Ubuntu Touch