← Back to team overview

ubuntu-phone team mailing list archive

Re: Debian Chroot, was: Re: Bootloop after installing OTA4

 

Hi Julia,

I'm afraid not, at least not yet. I can put something like this (also
incorporating Oliver's comments) on a wiki page or something similar,
but I am not sure where to put it. Do you have any suggestions?

But thanks for reminding me! Life has become somewhat busy since this
was discussed so I completely forgot about the whole topic.

Cheers,
Torsten

On Fri, 28 Aug 2015, Julia Palandri wrote:

Hi Torsten,

do you have this published somewhere to link to?

Thanks,

On Tue, Jun 16, 2015 at 10:00 PM, Torsten Sachse <torsten.sachse@xxxxxxxxx>
wrote:

On Tue, 16 Jun 2015, Oliver Grawert wrote:

Am Dienstag, den 16.06.2015, 13:35 -0400 schrieb Rodney Dawes:

You may have problems running chroot from within the Terminal app
though, as it seems to be blocked from executing the shell in the chroot
for some reason. It works perfectly fine over phablet-shell though.


to work around this you can:

android-gadget-service enable ssh
ssh localhost
chroot ~/debian-chroot


Some time ago, I wrote a little guide for someone on this list but
apparently I forgot to send it to the entire list. Feel free to use it
according to the GPL, if you like. The guide [1] is below. I hope it can
be of help to people who are not yet perfectly familiar with the system.
Apologies to those who already know all of the below and to Oliver, to
whom I accidentally sent this twice.

Torsten

[1]:
This is a simple guide describing how to set up a chroot on a Ubuntu
touch device. It also explains how to set it up so that the chroot is
located on the SD-card to save internal storage space and goes into some
detail about why simply installing the chroot on an SD-card is not
possible.

The guide is structured as follows:
1) Comments on file systems and permissions
2) Using phone only
3) Using computer and phone (recommended)
4) Unsing an image file (recommended)

1) Comments on file systems and permissions
Only some file system types support file permissions in a way the chroot
needs them. An SD-card likely uses FAT32 which does not support any type
of permissions and, hence, the chroot can't run on it.  The permissions
reported by commands like "ls -l" do not have any significance on such
file systems. Some Android handsets for instance support EXT3 or ECT4 on
their SD-cards making installing a chroot a lot easier.

2) Using phone only (not recommended since it breaks over the air updates)
It is possible to install debootstrap on the phone by remounting the
system as read-write and executing the following commands. At least it
worked on my BQ on r22. Imagine you want to install your chroot into the
directory "jessie" which should reside in the current working directory:

sudo mount / -o remount,rw
sudo apt-get update
sudo apt-get install debootstrap
sudo debootstrap --arch=armhf jessie ./jessie
http://http.debian.net/debian

This only works on the internal storage without what's explained in
section 4).

3) Using computer and phone
The problem with this debootstrap-command failing your average computer
is that your computer cannot execute binaries compiled for the ARM
architechture. This is why you have to add the option --foreign to
debootstrap which tells it to only download all packages and leave
anything that needs executing of any of the installed binaries to
another system. So do (sudo might not be needed):

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

If you were to install an i386 architechture on a x86_64 system, you
would not have to specify the --foreign flag as both should be able to
run on an ordinary 64-bit processor although they're different
architechrures.

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. The second command is needed to turn on ssh
support, which is reset upon every reboot.

tar -cvzf jessie.tar.gz jessie
sudo service ssh start
scp jessie.tar.gz phablet@ubuntu-phablet:DIRECTORY_OF_YOUR_CHOICE

Now you only have to extract the archive wherever you want the new
directory "jessie" to reside. Without what's expained in section 4),
this will only work on your internal storage.  Then, you only have to go
into your chroot and finish the installation process. So do on the phone
(the first command is needed since the terminal app is somehow
restricted to execute binaries):

ssh localhost
tar -xvzf jessie.tar.gz
sudo chroot jessie /bin/bash
/debootstrap/debootstrap --second-stage
exit

Now, you should be able to chroot into your new system using the third
of the above commands.

4) Using an image file
First, create an image file on the system on which you execute the first
debootstrap command. To create an 1GB image, 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, AFAIK. 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.

Mount the image file to a loop-device and create a file system on it.
Without a file system, you cannot yet mount the image to a directory,
only to a block-device. So do

sudo losetup -f

and remember the output. Replace every "LOOP" in the following commands
by the output of the above command. First, assign the image to a block
device:

sudo losetup LOOP IMAGE.img

Next, create the 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. Now, create the directory and mount the image file to it:

mkdir jessie
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. Now, use the directory "jessie" with
debootstrap as explained above (the command including the --foreign
flag). After you're finished, umount the image via

sudo umount $(pwd)/jessie

and create an archive of the image file (will compress all the zeroes in
the archive to almost nothing) and transfer that to your phone. Both
SD-card and internal storage are fine. On your phone, create the
directory "jessie" somewhere on the internal storage, mount the image to
it and perform the second stage.

You should now have a nice chroot on your phone that does not waste
internal storage space.


--
Mailing list: https://launchpad.net/~ubuntu-phone
Post to     : ubuntu-phone@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~ubuntu-phone
More help   : https://help.launchpad.net/ListHelp




--

Julia



Follow ups

References