Transformer: Booting Debian experiment

This is Experimental stuff! and maybe under further modifications. (Normal Android system upgrade is not possible)

In the previous post, Transformer: Booting Android experiment, the system partition files are moved into the data partition.

I can now move the Debian rootfs into the system partition.

The only problem is that my Debian rootfs uses more than 2G of space, it cannot fit into the system partition.


Checking the partitions below, there are another 2 partitions that can be used potentially:

  1. CAC -> /dev/mmcblk0p5 (cache - used by Android)
  2. APD -> /dev/mmcblk0p6 (Asus product demo)
 1     ~$ cat /proc/partitions 
2 major minor #blocks name
3
4 179 0 30535680 mmcblk0
5 179 1 8192 mmcblk0p1
6 179 2 4096 mmcblk0p2
7 179 3 8192 mmcblk0p3
8 179 4 2097152 mmcblk0p4
9 179 5 897024 mmcblk0p5
10 179 6 512000 mmcblk0p6
11 179 7 8192 mmcblk0p7
12 179 8 4096 mmcblk0p8
13 179 9 16384 mmcblk0p9
14 179 10 8192 mmcblk0p10
15 179 11 8192 mmcblk0p11
16 179 12 4096 mmcblk0p12
17 179 13 4096 mmcblk0p13
18 179 14 26916864 mmcblk0p14
19 179 32 4096 mmcblk0boot1
20 179 16 4096 mmcblk0boot0
21

The demo partition is not used by Asus or Android. You can mount it and there is a demo video you can watch. It's weird to take up 1/2 G of space in a released device without any use.

side note: though you can also mount APD partition by enabling a property (check init.macallan.rc)

1     # ASUS Product Demo
2 on property:persist.sys.enableAPD=1
3 start mount_apd
4

I split the /var and copy it to the APD partition, removing all the demo data.

I stop most of the services first, then

1     # mount /dev/mmcblk0p6 /mnt1
2 # cd /mnt1
3 # rm -rf *
4 # cp -r --preserve=all /var/* .
5
6 # cd ..
7 # umount /mnt1
8

After excluding the /var data, the remaining rootfs still cannot fit into the system partition.

1     # cd /usr/share/
2 # du | sort -h
3 ..
4 118632./icons
5 156504./doc
6 247152./locale
7 1091332.
8

My /usr/share/ uses a lot of space, I move the 3 subdirs locale, doc, icons that use the most space, to the data partition /data/local/opt/share , and then link it from /usr/share

That eventually reduces the rootfs space, making it fit into the system partition.


Assuming the system partition is already mounted at /mnt/system , its original data can be removed and replaced by Debian rootfs:

1     # cd /mnt/system
2 # rm -rf *
3 # cp -r --preserve=all /bin /boot /etc /home /lib /lost+found /mnt1 /opt /root /sbin /selinux /srv /usr .
4
5 # mkdir dev media mnt proc run sys tmp var
6 # mkdir mnt/data
7 # chmod 777 tmp
8 # chmod o+t tmp
9

Edit /mnt/system/etc/fstab

1     # UNCONFIGURED FSTAB FOR BASE SYSTEM
2 # debian
3
4 # APP
5 /dev/mmcblk0p4 / ext4 noatime,discard,errors=remount-ro 0 1
6 # APD
7 /dev/mmcblk0p6 /var ext4 defaults,noatime,discard 0 2
8

Modify /mnt/system/etc/init.d/tf701 (below shows only the case statement)

 1     # Mounting android directories to 
2 case "$1" in
3 start)
4 /sbin/e2fsck -p /dev/mmcblk0p14
5 mount /dev/mmcblk0p14 /mnt/data
6
7 ln -s /mnt/data /data
8 ln -s /mnt/data/.system/vendor /vendor
9 ln -s /mnt/data/media/0 /storage
10 ;;
11 stop)
12 rm /data
13 rm /storage
14 rm /vendor
15 umount /dev/mmcblk0p14
16 ;;
17 *)
18 echo "Usage: /etc/init.d/test {start|stop}"
19 exit 1
20 ;;
21 esac
22

To extract the Debian image from the SOS partition,

1     # cd ~
2 # abootimg -x /dev/mmcblk0p1
3

To extract the ramdisk initrd.img in subdir rd ,

1     # mkdir rd
2 # cd rd
3 # gzip -dc ../initrd.img | cpio -imd
4

In init script, remove the /myinit line. Also, remove the myinit file.
Edit/modify ../bootimg.cfg to specify mounting the system partition as root:

1     cmdline = console=tty1  loglevel=3  root=/dev/mmcblk0p4 rw
2

To rebuild a new ramdisk newinitrd.img from the updated files, then update the SOS partition with the new image ,

1     # find . | cpio -o -H newc | gzip -9 > ../newinitrd.img
2 # cd ..
3 # abootimg -u /dev/mmcblk0p1 -f bootimg.cfg -k zImage -r newinitrd.img
4

After rebooting back into Debian, the system should now be using the system partition as rootfs.

As can be seen from mount,

1     $ mount | grep /dev/mmc
2 /dev/mmcblk0p4 on / type ext4 (rw,noatime,discard,data=ordered)
3 /dev/mmcblk0p6 on /var type ext4 (rw,noatime,discard,data=ordered)
4 /dev/mmcblk0p14 on /mnt/data type ext4 (rw,relatime,data=ordered)
5

The Debian loop file /data/media/debian-root can now be removed (or backup).

And for debian-kit, in /data/local/deb/bootdeb , modify the IMG variable:

1     #IMG=/data/media/debian-root
2 IMG=/dev/block/mmcblk0p4
3

And optionally, since I have used a custom boot.img , might as well run the /data/local/home/sdcard_deb as a separate service from sdcard:

in init.macallan.rc , add /data/local/home/sdcard_deb as debian service,

1     service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
2 class late_start
3
4 service debian /data/local/home/sdcard_deb
5 class late_start
6 oneshot
7

For ref, see Debian Android with no Root.

To restore the original sdcard in /system/bin ,

1     $ cd /data/.system/bin
2 $ sudo rm sdcard
3 $ sudo mv sdcard_o sdcard
4

And in /data/local/home/sdcard_deb , comment off:

1     function checkexit()
2 {
3 if [ ! -p $pipe ]; then
4 if [ ! -d /usr ]; then
5 #echo "wait for sdcard" >> $sdlog
6 #wait $pid
7 exit 0
8 fi
9

and at the bottom, no need to run the original sdcard_o

1     #/system/bin/sdcard_o "$@"  > /dev/null 2>&1 &
2 #pid=$(/usr/bin/pgrep sdcard_o)
3
4 checkexit
5

In /data/local/home/opt_mount , to mount the /var after bootdeb s,

 1     else
2 /system/bin/setenforce 0
3 /data/local/deb/bootdeb s >> $sdlog 2>&1
4 # mount var (android use /dev/block/.. )
5 varpart=$(grep /var /etc/fstab | /usr/bin/cut -f 1 | /bin/sed 's:/dev/:/dev/block/:')
6 if [ ! -z "$varpart" ] && [ -b $varpart ]; then
7 echo "mount $varpart" >> $sdlog
8 /bin/mount "$varpart" /var
9 fi
10 /bin/chgrp fuse /dev/fuse
11 /bin/chmod g+rw /dev/fuse
12 /bin/rm -f /data/local/tmp/stopdeb
13 fi
14

and in /data/local/home/sdcard_deb , add /bin/umount /var before bootdeb u .

After that, need to update the Android boot partition to test.

Comments

blog comments powered by Disqus