[HOWTO][exFAT][CM10.1] Working 64GB ext sdcard with fuse-exfat (1.0.1) + FIX broken - Verizon Samsung Galaxy S III

This post has largely been relegated obsolete by my Flashable Mod.
Please see my new post >>HERE<<
I am leaving this up for informational purposes, and for record-keeping.​
[HOWTO][exFAT][CM10.1] Working 64GB ext sdcard with fuse-exfat (1.0.1) + FIX broken
How to get a exFat formatted 64GB external sdcard working with CM10.1 using fuse-exfat & FIX broken card headers
Attribution credits:Original thanks go to originator of the method, smitna in the Galaxy S2 forum, for providing the method. Additional thanks go to shardul_seth (Post 23) for compiling the latest version of the fuse-exfat binaries for ARM, and of course Andrew Nayenko for his efforts in creating GPL'd exFat code (fuse-exfat on google code).[HOWTO][exFAT][WORK IN PROGRESS] Mount exFAT formatted drives and cards​TL;DR - READ THE POST FIRST!:
Download shardul_seth's binaries for fuse-exfat from (Post 23) or the bottom of this post.
Unzip the files into /data/ (requires root)
Open an ADB shell as root (requires USB-Debugging turned on, ADB utility, also at bottom)
Run the following commands: (change mmcblk1p1 to suit your sdcard's partitioning - it might be mmcblk1. DO NOT FSCK WITH blk0, that is your internal card!!!)
Code:
chmod 775 /data/*fat*
mount -o rw,remount /system
echo "/data/mount.exfat-fuse -o rw,dirsync,umask=0 /dev/block/mmcblk1p1 /storage/sdcard1" > /etc/init.d/10exfatsdmount
chown root:shell /etc/init.d/10exfatsdmount
chmod 755 /etc/init.d/10exfatsdmount
Done! Reboot and enjoy.
SHOULD YOU BORK YOUR CARD BY REINSERTING IT (or get "Card Damaged" icon)
Run the included filesystem header patcher script as root (warning: has minimal safety checks, is hardcoded for "mmcblk1p1") to fix the likely corruption: (easily modified)
Code:
/data/fixmyexfat.sh
Reboot. (or run "vold"?)
Proof / What to Expect:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Overview:
An open source project recently reverse-engineered the exFat specification via a fuse driver (ala fuse-ntfs-3g). The first stable reelase was in January, and I am astounded that it hasn't been implemented in CM yet -- aside from the moral and potential legal reasons. A user here at XDA compiled the binaries and posted instructions, I am taking on the lead for putting it all together for others. I am tired of seeing posts dated as late as February 11th saying it is "Impossible" and to give up, or flash another ROM -- you are spreading misinformation and it needs to be stopped. This implementation isn't fully vetted, but it works seamlessly enough for most users.
Even without the fuse driver, it's pretty well known CM10.1 (and CM10) mangle exFat cards -- and to fix them, you need to merely run "chkdsk /f" on the drive from Windows. However, as soon as you plug it back into the phone, it automounts and mangles it again before you can do anything. I found out what was getting mangled, why, and when, and tried to work around it. I found by mounting at boot-time, before vold has a chance to attempt an automount, you can get the system to fully recognize a card. (See screenshots.) Theoretically, this means you can have a SDcard with multiple partitions -- a "dummy" fat32 partition at the start to fool vold with the mount scripts, and the exfat one that you rebind over it. (System -> Storage dynamically updates as long as you don't "unmount" from the GUI.)
The hex dump on the left is the first 512 bytes of a healthy exFat partition, the second from a mangled one. By noting the offsets and exact mangling of (0x000 = "RRaA", 0x1E4 = "rrAa", 0x1FC = 00 00 55 AA), I found out that it was attempting to replicate the "FS Information Sector" Signature of FAT32 - so there is a problem with CM's code somewhere attempting a fsck.fat32 when it isn't appropriate.
CM 10.1 / Android 4.2.1 also completely redid how mountpoints are set up. There are summarized in the "Technical Details" section below. The gist of it is, /data/block/vold/179:96 is the device (e.g. /sda/) and /data/block/vold/179:97 is the first partition (/sda1/). And in CM10.1 (if you had a FAT32 card), the 97 one is mounted to /storage/sdcard1/ via FUSE. However, these block-special files are dynamically generated by vold so are inappropriate to use -- we need to use mmcblk1p1. Depending on how the card is formatted, your mounts may change slightly.
The final challenge is where to put the binaries. I could not chmod make files on the /storage/sdcard0/ mount executable for some reason - by looking at CM10.1's source code I found why. Android moved to using a "fake" vfat partition and MTP under a FUSE layer unify storage space and remove file corruption/mutex issues. Unfortunately, that means it blocks permissions --- hence my recommendation to put the binaries in /data/ which is exposed as ext4. If you absolutely must put the binaries on the internal SDcard, you need to run the chmod commands from /data/media/0/ folder and the permissions will mirror properly. (This is the ext4 original of /storage/sdcard0/ "vfake".)
Technical Details: (mounts, softlink chains)
Code:
[B]ALL-IMPORTANT "FIXER" HEX-PATCHING CODE[/B]
(Reminder: dd = Destroyer of Disks. I take no responsibility.)
echo -e "\xeb\x76\x90\x45"|dd of=/dev/block/mmcblk1p1 conv=notrunc bs=1 count=4 seek=0
echo -e "\xff\xff\xff\xff"|dd of=/dev/block/mmcblk1p1 conv=notrunc bs=1 count=4 seek=484
echo -e "\x1f\x2c\x55\xaa"|dd of=/dev/block/mmcblk1p1 conv=notrunc bs=1 count=4 seek=508
[B]FOR INTERNAL SD CARD, "USER #0"[/B]
/storage/[B]sdcard0[/B] -> /storage/emulated/legacy
/storage/emulated/[B]legacy[/B] -> [B]/mnt/shell/emulated/0[/B] (fuse-fake-fat!)
/data/media/0 (ext4)
/dev/fuse [B]/mnt/shell/emulated fuse[/B] rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
[B]FOR FAT32 EXTERNAL SD CARD[/B]
/dev/block/vold/179:96 /storage/[B]sdcard1[/B] vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
(Notice it is [I]179:96[/I] -- the whole disk is storage. If you had it on Partition1, it would be [I]179:97[/I])
[B]FOR exFAT EXTERNAL SD CARD[/B]
/dev/block/mmcblk1p1 /storage/sdcard1 fuseblk rw,dirsync,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096 0 0
(In this case, it is [I]mmcblk1[B]p1[/B][/I] -- since I partitioned it. However, I have fudged my card before so it was just [I]mmcblk1[/I].)
If you need/want to change between "Floppy" mode (single big disk) and "Hard Disk" mode (with a partition table), I highly recommend using a program called BOOTICE to do it. It supports a number of "quirks" like reordering visibility of NTFS partitions on a Flash Drive, etc. (I will add instructions if there is demand.)
Remaining issues:
Unmounting poses no problems, doesn't corrupt anything. However, upon remounting (eg: vold rescan, physically removing/reinserting the card -> autodetect, or clicking "Mount SD Card" in the GUI), vold will re-mangle the filesystem header. The notification of "Damaged SD Card" also gets displayed and cannot be removed, even if my hotfix script is applied live.There was a version of Vold-exfat floating around for ICS, but that likely isn't compatible for us.​MTP works. UMS however is not currently implemented in the Unofficial Mastamoon build of CM10.1 I use. I therefore cannot test how Windows handles it.Programs like XDA's own "SGS3 Easy UMS" do not work, or work behaves eratically. By a convoluted scheme (Unmounting card from Shell -> Plugging in usb -> clicking "UMS") I was able to see a Read-only CD-Rom drive of my SD card. This seems to be a common issue.
Manual methods like changing the build.prop do not work - you see an *empty* CD-rom drive.​(From what I can gather) Cyanogen 10.1 does not currently allow for plug-and-play fuse modules to allow you to pick your own filesystem just by adding a .ko. Similarly, the exfat-utils (exfatfsck, etc) fail to run (even on a "fixed" card) since DKIOCGETBLOCKSIZE in io.c cannot detect the block size -- you will notice "blkid" doesn't recognize the exfat device either. "Vold" gets confused and mangles the filesystem header.Cyanogenmod needs to be updated to support Fuse modules more gracefully -- and ABSOLUTELY NOT modify the filesystem at all unless prompted.​

Sorry, problem solved.

Flashable mod is up, created new thread in the right section. Check OP for link.

Related

Using dm-crypt to Encrypt the SD Card...?

Trying to setup a script to automatically encrypt/mount/dismount the SD card using dm-crypt (the same tool used in Froyo's app2sd).
Targets as below...
A wizard to setup disk/partition encryption.
The key can be randomized by the device itself, or manually configured by user, and stored on the phone's memory (the point is that the content on the SD card will NOT be readable once removed from the device.
Automatically mount and dismount during boot and shutdowns.
Compatibility with the native USB mount feature.
It's my understanding that the encryption/decryption will be done in the background and transparent to the user. I also understand that there will be a hit on the performance and battery life.
It seems that Android uses vold, and most dm-crypt guides out there involves editing /etc/fstab which is not used on Android at all.
Pardon my ignorance, and any pointer will be appreciated!
Anybody...?
Anybody knows how Froyo's A2SD system works? There's no cryptsetup whatsoever but somehow it can use dm-crypt to store the apps on SD card?
It seems that Android's vold has parameters hardcoded and compiled into the binary.
Furthermore, it's not necessary to to use vold to mount the sdcard, good ol' mount can be used (no auto-mount through), but there's no cryptsetup to setup the partition.
I would like to do some rough experiments but needs crypsetup, or setup a cross-compile platform for compiling a static cryptsetup first.
P.S. Someone had worked on encrypting /data but it wasn't finished before he's switched to N900... (my target is a bit difference through, to encrypt the sd card which is more easily stolen... if the phone itself is stolen, it wouldn't do much good anyway cause someone can use adb to access /data, assuming the key is stored on the device not entered manually during each boot)
http://androidvoid.wordpress.com/2009/09/30/android-encryption-using-cryptsetup-and-luks/
P.P.S. The DROID PRO is said to have both device and SD card encryption as well. I suspect dm-crypt is used. Look forward to see how it's being handled...
Any pointers...?
: ).......................
Sorry, that I am not able to help you - although I would in fact appreciate if you achieve the aim somehow!
I'm really surprised this hasn't gained more attention. I sincerely hope someone discovers a way to fully encrypt SD cards.
Damian works on a kernel (still alpha) which so far already has cryptsetup.
Section galaxy s
I think this could be more easy achieved with steam recovery than cwm.
So far full encryption of blackberries is THE killer argument why android still doesnt go professional and get more attention.
Lets change that!
Sent from my GT-I9000 using XDA App
Push for implementating it in Android, please *star* the issues.
Issue 11211 - android - Android too insecure - Encryption of the SDcard is crucial - Project Hosting on Google Code
Issue 3748 - android - Add support for partition/block device encryption - Project Hosting on Google Code
I was able to get encrypted file system to work within a chroot'd debian environment; the key was to get the right cipher to work with the android kernel (aes-cbc-essiv:md5). The only reason I couldn't get it to work directly in android was the lack of the cryptsetup command.
Here's a guide, where a 64M file "dummy" is created filled with random junk, turned into a device, LUKS formatted, and mkfs'd. The second section mounts it, the third dismounts and frees resources.
HTH
Paul
Code:
=== create ===
dd if=/dev/urandom of=cryptvol.raw bs=1024 count=65536
mknod /dev/loop21 b 7 21
losetup /dev/loop21 /home/cryptvol.raw
cryptsetup --cipher aes-cbc-essiv:md5 --key-size 256 luksFormat /dev/loop21
cryptsetup luksOpen /dev/loop21 cr_cryptvol
mkfs.ext3 /dev/mapper/cr_cryptvol
cryptsetup luksClose /dev/mapper/cr_cryptvol
losetup -d /dev/loop21
=== use ===
mknod /dev/loop21 b 7 21
losetup /dev/loop21 /home/cryptvol.raw
cryptsetup luksOpen /dev/loop21 cr_cryptvol
mount /dev/mapper/cr_cryptvol /data/local/cryptvol
mkdir /data/local/cryptvol
cd /data/local/cryptvol
echo "this is a file in encrypted file system" >> README
== close ==
umount /data/local/cryptvol
cryptsetup luksClose /dev/mapper/cr_cryptvol
losetup -d /dev/loop21
@speculatrix
Are you able to use the chroot Debian rmount in Android at all?

FIX: extsd2internalsd broken after Verizon 4.1.2 OTA

Loong time lurker, first time poster. I couldn't post a reply in the development forum, obviously. Maybe someone can link to this in relevant threads over in development.
This is a guide for those who are/were using the extsd2internal to swap storage which no longer works after the 4.1.2 OTA or want to do take advantage of this mod: http://forum.xda-developers.com/showthread.php?t=1849860 OR it MIGHT work for other ROMs which want to use this method for the Galaxy S3.
After the OTA, and getting back up and running, I could not get the script to work correctly with this error: "no such file or directory" and doing some sleuthing, it seems Verizon (in their infinite wisdom) changed the mounts, or maybe it did this because gremlins/gnomes, maybe because Vzw/Samsung knows about the swapping method, who knows. Anyways, here is the fix that worked for me:
PreReqs:
Stock ROM 4.1.2 OTA
Rooted (duh)
BusyBox
SManager ads
Terminal Emulator
Root Explorer in R/W mode
extsd2internalsd mod installed/script in the correct place!
BACKUPS!! Make a nandroid backup before you do ANY tinkering people, and copy it to a safe place like your computer.
Let me be clear, for the love of bits and bytes, do not just keep one copy on the sdcard in the phone!!
1) To find the /dev/block/vold for the external sd card, open Terminal Emulator and run this command. Grant it root access when prompted:
Code:
su ls /dev/block/vold
Write down or make a note of the numbers. (For me there were only 2, 179:32 and 179:33) Now run these commands:
Code:
adb shell
cat /proc/mounts
There will be a whole lot of text that shows up, you are looking for "/dev/block/vold/179:xx" and in the same line there is "/storage/extSDCard"
Alternate method, after you are in shell run command and look for mmcblk1p1:
Code:
cat /proc/partitions
The number in the "minor" column, that's the new number!
Double-check that the blocks are right for the sd card's partition size.
Note: I tried using mmcblk1 and it didn't work, then tried mmcblk1p1 and VIOLA! Yay, trial and error.
2) In SManager, edit the extsd2internal script, and replace the 179:97 to 179:*new number* (again, for me it was 179:33)
3) Reboot or just "run" the script in SManger and wait a few moments, then check Settings>Storage.
Here is what my script looks like:
Code:
#!/system/bin/sh
#extsd2internalsd is a modification that allows to switch internal sd to external sd and viceversa. With this you can use default internal sd only for app storage #and the external sd to store all apps resource and all others stuff. The resut is a very big increase of installable apps on gs3
#All credits to Mattiadj of xda forum for the idea and script and to mike1986 for the cmw zip.
#xda thread url at http://forum.xda-developers.com/showthread.php?t=1772234
#Script Modified for U.S. Galaxy S3s by Zedomax at GalaxyS3Root.com to be compatible when sdcard is not inserted.
busybox mount -o remount,rw /
busybox mount -t vfat -o umask=0000 /dev/block/vold/179:33 /mnt/sdcard
busybox mount -t exfat -o umask=0000 /dev/block/vold/179:33 /mnt/sdcard
if busybox mount | busybox grep vold/179:33; then
busybox mount -o bind /data/media /mnt/extSdCard
fi
If this didn't work for you, I am a complete n00b, so I will do my best, but don't expect much.
Things to double check:
Permissions on the extsd2interal script in Root Explorer should have all the boxes checked EXCEPT the last 3 at the bottom.
SManager script should be set to "Su" and "Boot"
OTA Headaches? Use this guide to keep root and boot unlocked worked PERFECTLY: http://forum.xda-developers.com/showthread.php?t=2186574#8 I did a nandroid restore to pre-OTA since it borked the first go-around, and then used this method.
Take home message: MAKE BACKUPS!
Credits / Current Build of this mod:
http://forum.xda-developers.com/showthread.php?t=1772234
This mod does work, and just replacing the old with the new (still have to add it in SManager) will get the job done. The new script is significantly different, and I am sure there are reasons, but without a changelog...
Forum Community: Created the thread here because I couldn't find another thread specific to this environment with all the relevant information in one place. If anyone has seen any errors of my ways, please, please reply with what's up.

[GUIDE] Creating and using filesystem images on Android

Hey all, This is my first post on the forum, so I thought I'd make it a guide.
I've run into a few roadblocks with installing some development tools like python and stuff, so I figured I'd try and make a filesystem image to hold all of it, what with Android preventing executables on your SD card from actually executing. You should NOT try and use this for freeing up space by moving apps to it. That just breaks things.
Things to know
A mount point is where you access the contents of a filesystem through.
A filesystem is basically a virtual disk.
I'm not responsible for your phone melting into a pool of acid or anything else you want to blame me for. You executed the commands, not me.
If there's been guides for this already, I didn't find them.
Playing with your system files is dangerous. Be careful
Playing with filesystems is even MORE dangerous. Don't do it unless you know what's going on.
Reversing and then combining two words in a sentence, then calling it a bit more dangerous is incredibly dangerous and can kill you. Don't do it.
As I said earlier: This is not intended to free up internal storage on your phone. It is intended to create extra space to put command-line executables.
This was created for those of us who have older phones that don't have a whole lot of internal storage. (Like the Milestone) This should also work on anything that meets the requirements listed below. I use it on a Motorola Milestone A853 running CyanogenMod 7.2.4f UMTS/SHOLES, and it took some tweaking, but it worked. Commands you put into your shell are marked with `bolded text and surrounded by back-ticks. Leave the back-ticks out. (`)`
Requirements! (obtained using `which <command name>` or a specified command)
Free space on your mSD
losetup (configuring loop devices)
mknod (creating loop devices)
mount (mounting filesystems)
mkdir (making directories)
su (root access)
umount (unmounting)
mke2fs (formatting)
Linux filesystem support (`cat /proc/filesystems | grep ext`)
Here we go!
This assumes you are going to use an ext4-formatted filesystem image mounted on /data/development/, with the image located at /mnt/sdcard/development.img. You WILL need to determine your phone's supported ext<num> filesystems using `cat /proc/filesystems | grep ext`. Choose the highest-numbered one.
Create the mountpoint, the image, and then format the image to ext4.
`mkdir /data/development/`​`dd if=/dev/zero of=/mnt/sdcard/development.img count=409600 bs=1024`​`mke2fs -l /mnt/sdcard/development.img -b 1024 -t ext4`​
Create the block device, set it to point at the image, then mount it.
`mknod /dev/block/loop250 b 7 250`​`losetup /dev/block/loop250 /mnt/sdcard/development.img`​`mount -t ext4 /dev/block/loop250 /data/development`​
Test it to see if it works.
`touch /data/development/testfile;ls /data/development/`​
Use it.
Unmounting (/!\ For connecting to a computer to avoid corruption /!\)
`umount /mnt/sdcard/development.img`​`losetup -d /dev/block/loop250`​
Well, that's all I've got. Suggestions and corrections, as well as good feedback are appreciated.
Some PAQs (Possibly Asked Questions)
Q: I'm getting some errors. Here they are: pastebin.com/some-errors
A: Great, I'll see what I did wrong, and if it's something on your end, I'll try and help you out.
Q: It dun werk
A: Tell me the errors instead of complaining about them. Just saying that does not help me and wastes my time and bandwidth.
Q: "No space left on device"; "Operation not permitted"; "No such file or directory"
A: SD card full; not root (or SD card is full, or something broke); Mount point doesn't exist or (if 'mount' returns that and the point exists) something not cool happened.
Usage guide on Non-Android devices
Some interesting bits of information for use on computers:
There's probably not an easy way to read/write/mount EXT2 filesystems on a Windows machine, so if you have a solution that's stable, go for it.
Linux computers definitely should support this, and I'm not sure about OSX computers, but in theory would work if you had the right things installed. iPhones ... well I have no idea what you'd do with it there.
Linux:
On the device:
THIS PART IS EXTREMELY IMPORTANT, NOT DOING THIS WILL RESULT IN BROKEN FILESYSTEMS!
`umount /mnt/sdcard/development.img`
`losetup -d /dev/block/loop250`​Plug your phone into your computer, making sure that the computer mounts it and reads it as removable media, and that the image is present.
On the computer: (Path of your user folder, and the mount point at which your device's SD is mounted can and very likely will vary from distribution to distribution. Check your paths.)
`mkdir /home/user/android-devtools/`
`mount -o loop /media/user/android-sd/development.img /home/user/android-devtools/`​Now, you can change things within the image as you normally would a file or folder. Be warned, sometimes doing this can create conflicts in the file permissions, so running the right commands on the phone to change the permissions as root (use `chmod` for the permissions) can save you boatloads of trouble getting things to work, or editing files.
Mac OSX might or might not be the same, but seeing as I haven't picked up an Apple computer since maybe 5 years ago, let alone attempted filesystem management, I just don't know.

[HOWTO] Install LinuxOnAndroid distros on your sdcard's second partition.

Hello friends! I'm a year long follower of the LinuxOnAndroid project. I have always wanted to install ubuntu on my sdcard instead of using image files. I waited a long time for an instruction to crop up somewhere on the internet about how to do this, and in the meantime, learnt a lot of things. Then I decided to experiment with the idea a few days ago and also managed to get satisfying results. There was a significant performance boost compared to using a linux image.
While writing this tutorial, I have assumed that you are already quite familiar with the LOA project and that you have already managed to run a linux distro on your android device.
Please note that while this tutorial aims to be applicable for all distros released under the LOA project, I have only run Ubuntu 12.04 small, Ubuntu 13.10 small and Debian small images. I have never had any experience with the other distros. But I'm pretty confident that the instructions can be applied to other distros without any problem. If you encounter any problem while applying the instructions for your device and distro, I'm willing to help you as much as I can.
Warning: I've never bricked my android devices while rooting, modding or hacking them and I hope you will be as lucky. But please remember that I will not be held responsible for any damage or losses suffered by you or your devices while following the instructions given in this tutorial. You will do so at your own risk.
Let's begin.
First of all, Things You'll Need:
Root access on your android device
Busybox
An sdcard of optimum storage capacity. You decide what's optimum for your case. I have a 16GB card with a 4GB partition for ubuntu small image.
Init.d script support for auto-mounting second sdcard partition on boot. You can skip this if you want to mount the second partition only when booting up linux.
Attached zip containing bootscript.sh and 03ubuntu files.
Step 1: Partitioning the sdcard
WARNING: This will erase all data on your sdcard!
Use MiniTool Partition Wizard for windows, gParted for linux or aParted for Android to create the two partitions on your sdcard. I reccomend that you do the partitioning on your PC. Note that you cannot partition your sdcard by connecting your device to your PC my USB. You need to use a card reader. If you have a USB modem with built in card reader, you can use that too.
The first partition will be used by your android device for mass storage. Make it FAT32 or exFAT or vFAT. Note that if you make the first partition exFAT, custom recoveries like CWM will not mount it. This can cause problems, for example, when you are trying to restore a nandroid backup from your sdcard.
As for the format for the second partition (let's call it the linux partition), it depends on what linux filesystems your device supports. You can't use (ex/v)FAT(32). You can only use linux filesystem for installing a linux OS.
If you are using aParted to partition the sdcard, not every format will work. My tablet supports mkfs.ext2 and make_ext4fs but
Code:
mke2fs -t ext3/4
doesn't work. So I used aParted to format the second partition as ext2 and ran
Code:
make_ext4fs /dev/block/mmcblk0p2
in terminal emulator. So my linux partition is ext4. You need to unmount your sdcard to use aParted.
NOTE: Before creating your second partition, make sure your device is able to mount the format that you want to use. Run the
Code:
cat /proc/filesystems
or
mount
command in terminal emulator to check for supported filesystems.
STEP 2: Mounting the sdcard partitions
WARNING: If you are using the Link2SD app or any other app2sd app, you might be prompted to create mount scripts for the second partition. DO NOT CREATE THE MOUNT SCRIPTS. Our linux partition is not meant for app2sd.
In this tutorial, we will be mounting the linux partition automatically on startup. For this, you'll need init.d script support on your device. You can use Uni-Init to check/enable init.d easily. If your device does not support init.d and you've failed to enabled it, you could go for more advanced methods like unpacking your boot image and editing init.rc to mount the linux partition. You could also try the Script Manager app. You can also choose to mount the linux partition only when you boot up linux. Let me know if you'd like instructions for this.
Assuming that you already have init.d support, let us proceed.
Download the attached 03ubuntu script and using a root explorer copy it to /system/etc/init.d/here. I use ES File Explorer. Set file permissions to rwx-rwx-rwx or 777(? I'm not very familiar with numerical permissions). rwx-r-xr-x might also work. You can also use terminal to copy, set file permissions, etc. It's up to you.
EDIT: WARNING! Depending on your device, your MicroSD card might me mmcblk1. You can check using the mount command or from the aParted app. It is mmcblk1 on one of my friends' phone. If this is the case you must edit the 03ubuntu script to replace mmcblk0p2 by mmcblk1p2
The 03ubuntu script mounts the linux partition as ext4 at /mnt/ubuntu. The mount options in the script are meant for the maximum performance but may reduce reliability. I haven't had any problems yet. If your linux partition is not ext4, edit the script accordingly. Some of the mount options used in the script are meant for ext4 filesystems only. Google "best/optimum ext(whatever your linux partition is) mount options" to learn more. My linux partition is mounted with noatime option but becomes relatime sometimes after shutting down linux. Somebody please tell me why this happens.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
After placing the script in the init.d directory, reboot your phone.
After rebooting, open the /mnt folder. If you see a folder named ubuntu, congratulations, the init.d script worked. But is the linux partition mounted? You can check by opening the /mnt/ubuntu folder. If you see a lost+found or LOST.DIR folder, the partition is very likely to be mounted. Confirm it by running
Code:
mount
in the terminal. Look for the line
Code:
/dev/block/mmcblk0p2 /mnt/ubuntu ext4 rw,noatime,user_xattr,barrier=0,data=writeback 0 0
If you see that line, we're ready to move to the next step.
STEP 3: Copying the files from linux image to linux partition
Now, we install your linux distro on the sdcard. Place the image (a fresh one or the one that you've been using) in your sdcard and run the following commands. Note: You might need to make changes to the commands according to your image location and format.
Code:
su
mkdir /data/local/mnt
mknod /dev/block/loop255 b 7 255
losetup /dev/block/loop255 /mnt/sdcard/ubuntu.img
mount -t ext2 /dev/block/loop255 /data/local/mnt
cp -dpR /data/local/mnt/* /mnt/ubuntu
## wait till copy is complete ##
umount /data/local/mnt
exit
So that was it. You have your favorite linux distro installed on your sdcard now.
But before you go ahead and press that BOOT LINUX button, we still have some things left to do to make it possible to boot from sdcard.
STEP 4: Editing the bootscript.sh and init.sh files
Actually, I did the bootscript editing part for you. I made all (and only) the changes that are required to boot from the sdcard. The modified bootscript is based on the latest (v8) version. Things like sdcard and external sdcard mounts and binds are unchanged. I added comments in the script with my name to mark places where I made the changes. You can look through it if you like.
So now copy the modified bootscript.sh file inside /data/data/com.zpwebsites.linuxonandroid/files/here and set file permissions to rw-------.
After that, comes init.sh. Although the bootscript is common for all distros, it may not be the case for init.sh. You'll find it in /mnt/ubuntu/root/init.sh.
Copy it to your sdcard and keep a copy somewhere safe. Open the script in a text editor (I use Jota+ text editor) and find the following lines and remove them.
Code:
if [ $# -ne 0 ]; then
cfgfile=/root/cfg/$1.config
if [ -f $cfgfile ]; then
echo "Using config file $cfgfile"
else
echo "Config file not found, using defaults!($cfgfile)"
fi
fi
The original permissions for the init.sh file are rwx-rwx-rx
After that, place the modified init.sh file back inside /mnt/ubuntu/root/here and don't forget to set correct file permissions.
STEP 5: Final steps and booting linux
Everything is in place and now you can boot up your linux, or can you? Nope. The Complete Linux Installer app won't let you boot if it does not find an image file.
For this, create an empty file inside /mnt/ubuntu/here and name it ubuntu.img.
In the app, enter the location of linux image as /mnt/ubuntu/ubuntu.img and tap on the awesome boot button.
Voila! You've now successfully installed linux to your sdcard and managed to boot it up too! Well done, my son.
Aaaand...Just a reminder: Don't Update Script if you want to continue booting from thee linux partition.
If you have been successful in achieving the goal of this tut, please leave a feedback with your device name and any modifications that you had to make, if any, to the whole process. That will be of great help to others.
EDIT: RISK OF DOUBLE BOOTING!
In case of booting from linux image, when you (accidentally) tap on the boot widget or the boot button while linux is already running, the app would display a confirmation dialog to chroot into the mounted image. This may not happen when you are booting from the second sdcard partition.
To prevent errors when you accidentally tap on the boot widget/button, add the following code into the bootscript right after the error_exit() function at the beginning of the script.
Code:
echo "Boot up Linux? Make sure it is safe to boot before proceeding!"
read answer
if [ $answer != muchfunny ]; then
error_exit "Aborted"
fi
Replace "muchfunny" with y or yes or any word of your choice.
When you try to boot, you'll have to enter this word to proceed. If you type in the wrong word, it won't boot. This way, you will have a chance to prevent errors when you accidentally tap on the boot widget while linux is already running.
Any user of LOA, not just those who are booting from linux partition, can benefit from this. You could replace "muchfunny" with a secret code to prevent anyone from messing with your linux installation. So it's like implementing password protection.
I'm using this on my tablet.
hello david,
Looks nice and clear, haven't had the chance to try yet but will post my results when i do.
Just wanted to say big thanks for the write up.
Sent from my Nexus 7 using Tapatalk 2
joesnose said:
Looks nice and clear, haven't had the chance to try yet but will post my results when i do.
Click to expand...
Click to collapse
When you do a factory reset in CWM (probably also in other recoveries), the second sdcard partition is wiped.
So it's best to store the backups in the internal sd and remove the sdcard before performing a reset.
If you don't already know, and if you have not run "apt-get clean", you can back up any packages that you downloaded on ubuntu (if you're using it) by keeping a copy of the contents of the archives folder in /var/cache/apt/. In case your linux installation gets corrupted or the partition gets wiped, you can restore the backed-up packages later. So you won't have to download them again.
I have used this thread to install Archlinux using LinuxonAndroid on a Samsung Epic 4G's SD card. I have some issues to sort out with using VNC to access the Archlinux installation but the commandline environment on the Epic 4G works fine.
If you're trying to use this with Ubuntu, there are several issues. First, the image hosted by the LoA project for Ubuntu 13.10 doesn't work for this application: you'll get errors when you try to mount the image for installation to the SD partition. Second, you might try the 13.04 image: it will mount and install but the repositories are all gone because 13.04 is no longer supported.
If you're trying to install this in order to use a specific program (in my case, I'm wanting to use this device as a Prosody server), it's probably best to see which available distro hosted by LoA has up-to-date packages for that program and use that to guide your decision. Based on this logic, I chose Archlinux.
If you aren't using Ubuntu, the bootscript.sh file included with this post becomes problematic as it is littered with Ubuntu-specific calls. It isn't overly difficult to edit: open it in Notepad+ (or similar) and read through it, changing $mnt and $ubuntu to whatever you've named your partition mount folder as. In my case, my mount folder is /archlinux/ and the fake image file (used to spoof the LoA app as detailed in OP's post) is /archlinux/archlinux.img, so this meant simply replacing $mnt and $ubuntu with $archlinux. There are a few instances of $ubuntu that I didn't mess with--in the comments, David has mentioned that they refer to the "usermounts feature" and that he left these alone because he didn't understand it. Are these the usermounts that are defined in the LoA app? I don't know and I haven't tried defining a mount yet (such as partition 1 on the SD card). In short, bootscript.sh will need to be edited to account for a non-Ubuntu installation.
(If you're using Archlinux, LoA hosts a modified bootscript.sh that contains a Archlinux-specific change to mounting /dev/pts, whatever that is. I used this as a base script to work with, then added and deleted the areas that David has edited in his bootscript.sh.)
Accounting for the differences, Archlinux works at the terminal on the device. However, if you try to connect to the automatically configured VNC server, things start to get weird for a Linux noob (which I am). For starters, there isn't a desktop environment defined so when you first connect, you're gonna see a blank gray screen and a cursor. Right-clicking brings up a menu. Almost none of the apps on the menu work, because they aren't installed. I think what you're looking at is the openbox window environment. What you need is a terminal to install something that works better but here's the catch: the terminal isn't installed/working, either (in VNC, not at the device). What I did here might have been a mistake compounding an error: I used the terminal on the device (which is logged in as root) to install a desktop environment using Archlinux's package manager, pacman. Then, I edited the (hidden by default) /home/$yourinstallhere/.vnc/xstartup.sh to boot the installed desktop environment; add a line with the command appropriate to your chosen DE: e.g. gnome-session; startxfce4; startlxde. You can comment out most anything else as those lines are loading the openbox environment and a terminal session. Alternatively, leave those in place as a backup environment and place your DE load command after those, so if your DE doesn't load, you still have the nearly useless gray screen to look at.
Okay, so that got a DE going (after the xstartup script was executed again and possibly the Linux install rebooted). Now what? Well, as mentioned before, terminal still doesn't work. It will open but there isn't a prompt and no keyboard input is shown. Without terminal, Linux is crippled, DE or no DE. This is where I am currently. I can still manage the Archlinux installation from the device's terminal as root but access from VNC is effectively unusable. I don't know why: is it because the DE packages (including a terminal emulator) were installed by root and therefore the VNC user doesn't have the permissions to access them?
In any event, I would like to thank David for posting this thread. The LoA project has little to no documentation or discussion so this has been very helpful to me. Please let me know if you have any ideas regarding VNC access of the installation.
Edit: Additional installation-specific information:
My Epic 4G is running the Cyanogenmod 10.1 stable release. The init.d mount script for the second partition will not automatically run at boot, despite CM supporting init.d and having installed the Universal init.d app. However, the script can be manually executed from within the Universal app and that will mount the partition. I tried adding a 50-second sleep to the script to see if it was just bogging down but that had no effect so I gave that idea up. The test script that the Universal app uses to test if the device has init.d support also doesn't work, which indicates that the Epic 4G CM port may be at fault here.
Using Archlinux's systemctl to manage services from the root terminal on the device is not working as expected. For instance, if I try to restart the vncserver service (systemctl restart vncserver) the terminal returns, "Running in chroot, ignoring request."
Edit #2:
Installed xterm from the device terminal and now I can access xterm from VNC /facepalm (why does the xstartup script call something that isn't installed by default?).
When my device's screen powers off, the VNC session drops because the server apparently kills itself. I have Android set to keep wifi on during sleep. How do I keep VNC active while the device's screen is off?
I seem to have succeeded with having my Epic 4G run an XMPP server (Prosody) within Archlinux on Android. I don't want to take this thread too far off-topic but there were some aspects to my project that would be useful to know for someone installing LoA.
http://sourceforge.net/p/linuxonand...do-users-and-groups-work-under-linuxonandroid
https://android.googlesource.com/pl...r/include/private/android_filesystem_config.h
This is pretty key knowledge to know if you're going to install anything that's going to need to gain control over the Android hardware (e.g., opening sockets). Root at the terminal is probably in all of these groups but the default user (ubuntu or whatever you named your installation) might not be; if your software installs its own user, it definitely won't have these group memberships so you'll have to add them. In my case, Prosody creates its own user and group and refuses to run as root, so I had to give the Prosody user membership in the 3003 group so it could open listening ports (I also had to modify all of the files that should have belonged to Prosody with chown because root took ownership by default). I figured this was something to keep in mind, if you're a fellow Linux noob.
http://forum.xda-developers.com/showthread.php?t=1585009&page=24
Speaking of the "everything as root" problem, I came across this that purports to make the default ubuntu user more typical of what you'd encounter in a Linux distro. I haven't tried it yet but I may need to in the future, if I expand the services offered by my Epic 4G. I still haven't figured out why the VNC server drops when the screen is turned off, though; I probably need to switch servers. The default is xVNC and I have been using Win7 x64 TightVNC Viewer to access it.
Hello there! Thanks for your posts! After encountering problems while trying to get LAMP to run on Ubuntu 12.04 and 13.10, I had given up LoA, until today. I've been using Linux Deploy instead for the past few months. Everything works fine on it. Have you tried it?
Anyway, I've decided to install LoA Debian as image from now. I think dedicating a 4 GB partition to a Linux installation is costly when you have just 14.7 GB of available storage.
Hello David,
I gave up on Linux on Android because I couldn't get it to stay connected to wifi with the screen off. I went back to using an XMPP server on my OpenWRT router instead.
Thank you for the suggestion regarding Linux Deploy. If I have some time, I will try it.
Does your LAMP stack manage to stay constantly connected with the screen off?
hammmy said:
Hello David,
I gave up on Linux on Android because I couldn't get it to stay connected to wifi with the screen off. I went back to using an XMPP server on my OpenWRT router instead.
Thank you for the suggestion regarding Linux Deploy. If I have some time, I will try it.
Does your LAMP stack manage to stay constantly connected with the screen off?
Click to expand...
Click to collapse
Linux Deploy has options to keep screen on and to keep wifi on while the app is running. I'm not sure if this will help with accessing LAMP when the screen is off. BTW, I found other problems with LoA Debian. So I'm back to Linux Deploy Debian. I'll test LAMP with screen off and let you know how it goes.
Instead of running the web servers through a linux installation, I suggest you try the various web server apps available for Android, if you haven't already, that is. I use Palapa Web Server which is free and has a nice interface.
Unfortunately I was unable to get Apache to work. Anyways, like I said, the Android web server apps might best serve your needs.
davidheis said:
Instead of running the web servers through a linux installation, I suggest you try the various web server apps available for Android, if you haven't already, that is. I use Palapa Web Server which is free and has a nice interface.
Click to expand...
Click to collapse
This is a good suggestion but unfortunately the XMPP server apps that I've tried didn't work out. I don't recall exactly why as it's been awhile since I tested them. They are bare-bones and lack configuration options.
hammmy said:
This is a good suggestion but unfortunately the XMPP server apps that I've tried didn't work out. I don't recall exactly why as it's been awhile since I tested them. They are bare-bones and lack configuration options.
Click to expand...
Click to collapse
Oh, okay. I highly recommend Linux Deploy as the distros are downloaded directly from the official sources. Installing to a second partition is very easy too. And it also allows running of custom scripts during startup of your distro. So if you manage to have XMPP working, you won't have to open a terminal to start the service (which is necessary for apache - have to run "service apache2 start").
Let me know if you have any success with Linux Deploy. I may be working with XMPP in the near future, so having a 'take anywhere' server might prove very useful.
Hello David can you make a brief guide on how to install Kali on sdcards second partition. I'm stuck I don't know how to install the linux.IMG on the ext2 partition, I partitioned my SD card using minitool the problem is when I hit install on Linux deploy the IMG will be installed on the SD card but on the fat32 partition not the ext2, which is the path to ext2 ? I can't find it using file explorer maybe you can help me
EDIT: i need to mount the new ext2 partition right? which is the easiest way to do it?
hi... can you provide me a method to access the filesystem (eg. var, etc....) because in the old ubuntu version is no longer supported. i got 404 not found when try to get update(apt-get update). only one solution is modify etc/resource.list file....but ubuntu cant access the filesystem via termimal
Cifs mount on start? I've added it to fstab and mount -a works fine, but it seems that fstab is not being run on start-up? I tried adding the same line I used in fstab to the custom mount points but it does not like it "skip"' it's probably simple syntax, the mount cmd seems to change dep. on where you run it, anyone know the right way to get a cifs mount on start in ld? thanks..
this is what works in fstab/mount -a
//192.168.1.65/media/Cifs /Public/Video cifs username=user,password=pw,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm 0 0
Well hello everyone.
I am going to try this now cause Linux deploy failed for me and it also messed up my external sd card (cause my xperia e3 doesn't have that Much internal).
Then i tried complete linux installer normal installation method but that also didn't worked so now i am going to try this.
I know this thread is very old but that's my only chance left for installing Ubuntu in phone
If anyone can provide any advice or any guidance i will be grateful to him
Thanks In Advance

Is it necessary to umount sdcard1 before running fsck_msdos

QSTN1: Is it necessary to umount sdcard1 before running fsck_msdos?
By doing so seems to break and remove some HomeScreen icons on some OS's where certain Apps have been 'Moved to SDcard'.
QSTN2: Does newer versions of Android OS (ie 5.0.2+) natively and automatically run fsck and fsck_msdos at boot-time on your FAT formatted plugin micro-SD card, or is it an add-on specific from various OEMs?
Most of you are probably very familiar with Windows ChkDsk.exe C: /f to repair damaged/corrupted SDcards.
You may have found that by removing your SDcard from your Android device and running ChkDsk under Windows, that you solved a lag problem with your Android device. By running ChkDsk on your SDcard, maybe prompted for you to 'Convert lost chains to files', and by fixing that, fixed my lag problem.
You may also have found that sometimes that's not enough, and you need to copy your whole SDcard over to a Windows folder, reformat your SDcard as FAT (same as it was before) and copied your data back. That certainly has been the case on one of my older and slower Android 10" tablets that some Apps like 'Screenshot Ultimate Pro' by 'Ice Cold Apps', as great as it is, sometimes corrupts my SDcard when I'm tapping around too fast.
Instead of having to take the SDcard out of my tablet each time I detected this problem, I needed to run fsck_msdos on the tablet itself, so I went through the motions and finally created a HomeScreen icon, where one single click will repair the SDcard and I could then get on with business.
TIP1: I've successfully created a HomeScreen icon using SManager by devwom by placing the following script under a 'scripts' folder I created under the default Home directory of SManager.
I also made sure that the script file had the appropriate (FULL) rights and that under Advanced, I made my 'Scripts' folder, SManager's Home-base.
My preferred location to place shell (.sh) scripts for SManager (Script Manager) by devwom:
/data/data/os.tools.scriptmanager/Scripts/
I used SMWidgets by devwom to create the HomeScreen icon for the script.
#!/system/bin/sh
# scr_FsCk_MsDos_on_MoXT1068_sdcard1.sh
# umount /dev/block/vold/179:65
fsck_msdos -y /dev/block/vold/179:65
echo .........
echo : Done! :
echo .........
NOTE: You can see in the script above, that I've commented out the umount command which seems to work whether or not the SDcard has been dismounted or not.
This is my main question I need answering, as around the traps, I see conflicting reports about dismounting first and I'd rather not have to do that if all works by leaving the SDcard mounted during fsck_msdos.
Thanks.
Hi, If I do this per adb shell as su I get the following error:
Code:
1|herolte:/ # fsck_msdos -y /dev/block/vold/public:179,1
fsck_msdos -y /dev/block/vold/public:179,1
stlog : disable(No such file or directory)
begin(dev:/dev/block/vold/public:179,1)
** fsck_msdos for samsung-mod version 1.1.1
** /dev/block/vold/public:179,1
exFAT signature in boot block: unsuported
end(ret:2, stderr:0, dev:/dev/block/vold/public:179,1), stat(dirs:(0/0), files:0)
Any advice please!

Categories

Resources