Skip to content

Using ext4 in sd and unmounting it from Android at boot

Gazihan Alankus edited this page Dec 17, 2019 · 4 revisions

Here there is a great suggestion that lets you format an sd card with ext4 and install the whole Linux on that sd card.

However, this is not true in Android 7.1.2 that I'm using:

Android can't mount ext4 as now and this way you can be sure that your Linux is free of any harm of Android and it's in an isolated place out of reach for Android.

In my system, the first time you create and format the ext4 partition, Android can't mount it. However, once you reboot the phone, it magically is able to and does mount it. I could not find a way to tell Android not to mount this partition. Since it's mounted, Linuxdeploy can't use it. You need to manually unmount it in settings before you can start Linuxdeploy. This requires someone to do this manually everytime the phone reboots. This is a problem.

I overcame this problem by editing cli.sh of linuxdeploy as below:

    msg -n "Checking file system ... "
    fs_check
    is_ok "skip" "done"
    # BEGIN ADDED CODE

    umounter() {
        echo "Will umount $1"
        while df -h | grep $1; do
            umount $1 2>&1
            retVal=$?
            echo $retVal
            if [ $retVal -eq 0 ]; then
                echo "Unmounted"
                break
            fi
            echo "Could not unmount. Will try again in a second."
            sleep 1
        done
    }
    umounter "/storage/5be2aa01-4744-4d10-be5e-963bc5e4914d"
    umounter "/mnt/media_rw/5be2aa01-4744-4d10-be5e-963bc5e4914d"
    # END ADDED CODE

    msg "Mounting the container: "

You can find this cli.sh in the current directory when you telnet into Linuxdeploy. This is what's executed when you press start. You can edit it using vi.

The /storage/5be2aa01-4744-4d10-be5e-963bc5e4914d and /mnt/media_rw/5be2aa01-4744-4d10-be5e-963bc5e4914d are what I see next to my ext4 partition when I type df -h. When you first reboot, they stay busy for a while and can't be unmounted. That's why this script tries to unmount them until it actually can. I found that you have to umount the two separately sometimes, which is why I have the two of them here.

In my system this is a sure way to get it to start without manually unmounting the partition in Android storage settings. If you set Autostart in Linuxdeploy settings, your Linux installation will start by itself after the phone boots.

I hope this helps someone. I have a crappy old Android phone that will soon be powering my home automation needs thanks to this. If your Linux installation is nonresponsive to network requests, add a service that pings outside frequently.

http://your_computer:3142/XXXX where XXXX is one of armdebian, armubuntu, or armkali

Clone this wiki locally