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


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.

Best Answer

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.

Related Question