tl;dr: I'm looking for a "canonical" or "recommended" way to install (cli) .deb packages on Ubuntu touch

I've been using Ubuntu on my Desktop and Server for a year and I'm very satisfied. Now I bought the first Ubuntu phone, the BQ Aquaris e4.5 Ubuntu Edition. However, I found out that I can't install normal .deb packages or install things using apt-get. How can I "root" my phone so that I can install "normal" .deb packages?

I tried it myself. I know the first thing is to make your filesystem writable. I did the following steps but then I got stuck because of a dpkg error.

# Desktop:
sudo add-apt-repository ppa:phablet-team/tools
sudo apt-get update
sudo apt-get install phablet-tools

# Phone:
Security & Privacy: Lock phone: Lock when idle: Never
About this phone: Developer Mode: Developer Mode ON

# connect phone to PC via USB

# Desktop:
adb devices
# no device detected so I've manually added file
touch /home/username/.android/adb_usb.ini
# with content: 0x2a47
sudo adb kill-server
sudo adb start-server
adb devices # now my phone is on the list

# Phone:
sudo test -w filename && echo "Writable" || echo "Not Writable"
# verified it is writable
sudo add-apt-repository ppa:phablet-team/ppa
sudo apt-get update && sudo apt-get upgrade

And this is the place where error starts to block me:

dpkg: error processing archive /var/cache/apt/archives/powerd_0.16+15.04.20150430-0ubuntu1_armhf.deb (--unpack):
unable to make backup link of `./usr/share/powerd/device_configs/config-default.xml' before installing new version: Invalid cross-device link

So I tried

sudo apt-get install -f

But it got stuck on "Bluetooth main config". I restarted the phone, but it didn't want to turn on anymore. I tried the Recover boot option. That worked. I tried install -f again, and this time it worked. But after doing upgrade I still had the same error.

  • Making the system partition writable and using apt is not supported. If you really need to use some console apps for some reason, it is best to create a chroot inside the home directory, and then install what you need inside that chroot. – dobey May 7 '15 at 21:04
  • 1
    I can confirm that using apt-get upgrade will result in a broken system. Been there, done that. – Galgalesh May 11 '15 at 20:14
  • 1
    @Galgalesh thanks for the edit, not looks much better. As for now your answer is going to grab a bounty :) – jangorecki May 12 '15 at 8:38
  • 1
    Give it to @dobey, please. His answer is a lot better :) – Galgalesh May 13 '15 at 19:05
  • 1
    Please feel free to also click the "Accept this answer" next to the answer. :) – dobey Jun 30 '15 at 17:55
up vote 17 down vote accepted
+50

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.

  • Wow, thanks a lot for this guide! I'm glad that I don't have to mess with / anymore when I want to fiddle with my phone.... – Galgalesh May 13 '15 at 19:04
  • Also, sudo mount -o bind /run /home/phablet/vivid-chroot/run to get network inside chroot askubuntu.com/questions/469209/… – sdbbs May 3 '16 at 19:27
  • 1
    @sdbbs I don't think that's necessary. I don't bind mount anything in my chroot, and network access works fine. I use bzr and apt all the time within it. – dobey May 3 '16 at 20:20
  • I copied /etc/resolv.conf into vivid-chroot/etc to get dns resolution working. – popey Aug 5 '16 at 12:03

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.

  • Thanks for the solution! Will not accept for now as I still hope to get a more recommended (don't have to be supported) way to do so. BTW. what about future updates of powerd? does it require to hack it on every update? – jangorecki May 10 '15 at 21:19
  • Till someone will resolve this problem of using hardlinks in dpkg (an old story) on a cross device installation, at the moment I don't see alternative solution. – Ezio Somà May 11 '15 at 19:54
  • 1
    May be that should be possible to change some mount points in rder to avoid this cross device hardlink, but need some time to be analized. Only by looking to fstab file or mont output I was not able to figure out what to chance – Ezio Somà May 11 '15 at 20:02

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.

Make root filesystem on phone writable

To remount root filesystem as writable, execute the following command on your phone (download terminal app if you haven't already):

sudo mount -o remount,rw /

Please note that after rebooting your phone, / is read-only again. If you want this to be permanent, change /etc/fstab. However, Ubuntu touch on the BQ is not on the main Ubuntu arm repo's yet. Installing things like tree or libreoffice won't work yet. They might be in the latest devel version.

Running the latest devel version of Ubuntu

(has more goodies in the repo, like commandline tools and such)

How to run latest Ubuntu touch development release on bq phone?

Fixing stuff when you break everything

When you break thing completely, you can just reflash your device.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.