mount loopback crashing phone - General Questions and Answers

Not sure which section to post this question but I've been trying to create & mount a local file for a project idea. Failing right a the start I've been looking for information but struggling to find any logs to explain whats happening.
Phone Galaxy S5, flashed with LineageOS 15.1 (upto date)
Basically I've been trying to create a file with dd, making a filesystem then mounting.
Creating a file with dd on phone or external also running mkfs (tried exfat ext4 2fs) works fine.
The problem comes when mounting using adb or local shell app the command doesn't complete while phone reboots.
Sample shell commands used to help with understanding my issue
Code:
su -
cd /storage/(sdcard)
dd if=/dev/zero of=virtualfs bs=1024 count=10240
mkfs.exfat virtualfs
mkdir vir
mount -o loop ./virtualfs ./vir
Phone freezes, 5 seconds later reboots
I've tried running from a couple of terminals over adb with one running logcat but nothing is seen between command and reboot.
At this point I'm lost where to look for errors or what to attempt next.
Could anyone suggest how this could be done. Or how to get more information whats causing the reboot.
Thanks

Related

[Q] Simple adb question (or perhaps not?) Permission Denied

Hi all--in need of some help here--have been crusing the forums for three days and still hitting a brick wall...
Have a rooted (and minimally modded) Atrix 4g in serious need of a hard reset and all the pain that comes with as nearly every app force closes on startup.
Hoping to backup some of my data (contacts, SMS, etc), but unable to do so my usual way (an app, root explorer, or the like), so I'm attempting to use ADB pull to grab the .db files. I'm relatively comfortable with linux, but running into a problem with ro/rw permissions (I think).
have tried the following:
adb pull /data/...../mmssms.db (yields Permission Denied)
# cp /data/....mmssms.db (appears to copy, but no file in destination, and can't copy out of shell)
have been able to remount /system as rw, but not /data where the files are located.
Anybody have suggestions? I'd be most apprecative!
Copy the the files as superuser to your sdcard first and adb pull them from there.
Unfortunately, the whole reason I'm needing to reset is that every app (incl superuser accesses) force closes on start--no chance to move through the phone itself. Since the .db files are not in the usb-accessible file structure I'm thinking that ADB is the only way to access.
Does that make sense?
Hi, OP here--anybody else have a suggestion? Getting a little desperate here... Any thoughts would really be appreciated!
im assuming your accessing ADB via recovery?
You should be able to use su without superuser.apk's permission in that case - however, theoretically, you should not need to use su in recovery anyway.
you can try running
Code:
adb shell ls -l /data/data/*tele*/databases/mmssms.db
and see what you get permissions wise, maybe a chmod could fix it?
Otherwise you could try
Code:
adb shell mount -o remount,rw /data
Another alternative to cp and adb pull is cat
Code:
adb shell cat /path/to/mmssms.db > /path/to/destination-file.db
might copy remote mmssms.db to a local file, while
Code:
adb shell
cat /path/to/mmssms.db > /path/to/destination-file.db
exit
would copy remote to remote
Is /data mounted at all?
This is strange, you should have read access to everything, especially in recovery.
What phone and what recovery?
Its not something as simple as geting the URIs the wrong war round ('cmd local remote' vs 'cmd remote local')?
So, still tinkering... Will give it one last try before I call it quits and just wipe the bloody thing. So, your thoughts were spot on--its probably me missing something.
Quick data dump on progress to data:
Phone: Rooted Motorola Atrix running 2.2
no trouble accessing shell or via ADB
/data is mounted, though only in Read Only mode--can't seem to change, have tried several ways in various modes (shell, su, etc)
Permissions for mmssms.db are: -rw-rw---- radio radio
chmod 777 of the file yields: "Read-only file system," which makes sense since I can't seem to change /data... to rw
Tried to remount rw:
adb shell mount -o remount,rw /data
and
mount -o remount,rw -t yaffs2 /dev/block/mmcblk0p11 /system (for systeem
but get "Operation not permitted" in both cases.... UGH!
Hadn't thought of cat--great idea. Still no real joy however.
I seem to have managed a copy to /system, but can't seem to get it off the device or onto the SD card.
Thanks much for your help so far. Any final thoughts?
SO CLOSE!!!! (and yet...)
crags said:
Hadn't thought of cat--great idea. Still no real joy however.
I seem to have managed a copy to /system, but can't seem to get it off the device or onto the SD card.
Click to expand...
Click to collapse
SO FRUSTRATING!!!! so close, but not quite there--HELP!!!
As noted at the end above, have been able to copy the mmssms.db file to /system/ after remounting as RW
Can't seem to copy or pull off the device--still getting "Permission Denied" no matter which course I try!?!?!
It sounds as if your doing this while booted into the ROM, and (maybe) without su (root)?
su-ing might help, just type su and hit return to enter a root shell
alternatively, going in through recovery ('adb shell reboot recovery') might help as most recoveries ignore permission rules - make sure to mount the partitions your using though.
It almost sounds like the sdcard has no write permissions - you can get the NAND partitions to mount rw, but cant copy to the sdcard.
On my Desire, there is (at least) two mount points: /sdcard and /mnt/sdcard - maybe on your phone only one of your mount points has write permissions?
Otherwise i suggest going in via recovery. You can still use adb (will have to manually mount - 'mount /system' 'mount /date' and 'mount /sdcard' usually work, otherwise use the menu item in recovery )
When in recovery, and after mounting partitions/card, try adb pull, cp /sdcard and cat > sdcard (and if possible cat > computer) plus anything else i forgot (quite tired )
if these dont work something is messed up somewhere in the ROM, or likely kernel and so without ideas a reflash would be the only real solution :/
I did have a bare-minimum+apps recovery script (attached) which might be worth a read to see if your forgetting something obvious - it works on my desire

[Q] Send files to a mounted windows share using adb

Kind of a one-off question... I'm working on a project that will automatically dd image an android phone to an off-phone location (the host computers d: drive for example) using a script executed through adb. It has to be automatic and the resulting dd image absolutely cannot be written to the phones memory.
Maybe something like:
Code:
$ su
# mount -o rw,remount -t vfat /dev/block/mmcblk0p4 /dd
# dd if=/dev/block/mmcblk0p1 of=/dd/system.dd
I've tried the cifs route but sadly, it appears the cifs.ko and slow-work.ko modules haven't been done for my handset (or I may be so stupid I can't even follow directions. It's a real possibility).
I thought I'd use the time-tested netcat method but again, I can't locate the nc binary for netcat that will run on my handset.
Any alternatives? Anyone know where the G2X specific kernel modules can be had? Someone maybe have an android nc binary?

[GUIDE] How to mount ext4 formatted MicroSD card on Android 4.2.2 Phone/Tablet.

Why?
MicroSD cards are traditionally formatted using ExFAT filesystem. The trouble is that while universally compatible, ExFAT is rather primitive filesystem prone to data loss, and poor speed. Linux ext4 on the contrary is highly reliable and very fast.
Trouble is that, and I quote, "Android supports devices with external storage, which is defined to be a case-insensitive and permissionless filesystem." (see http://source.android.com/devices/tech/storage/)
Well that pretty much narrows it down to dumb stuff like ExFAT.
Note: As of JB (Android 4.1) default umask is 077, which means that files created by apps on the ext4 formatted SD card will only be readable by the same apps, unless you manually update permissions. See this thread for more: http://forum.xda-developers.com/showthread.php?t=889471&page=5​
The good news is that Android has Linux at its core, which naturally supports ext4, and actually all of the internal storage is (or will be in near future) formatted this way. The design limitation mentioned above is somewhat artificial and is enforced by
restricted functionality of funky little daemon, called vold. The sole purpose of vold is not monitor external storage,
detect filesystem on it, mount it as specified in /etc/vold.fstab (or vold.xxx in Android 4.3), and then report to the Volume Manager.Volume Manager in turn notifies the MTP application, and all other apps, displays icons and handles rest of user-visible stuff.
Stock Android vold only supports ExFAT/vfat filesystem. It has been improved in Cyanogenmod to support ext4 and NTFS filesystems, but for those of us stuck with OEM Android this goodness in unavailable. In my experience simply re-building vold from CM as part of AOSP,
while yields an executable, this executable results in a boot loop for an unclear reason.
All hope lost seemingly, yet there is a silver lining.
Silver Lining?
If MicroSD card is mounted manually in the way that vold can see it, re-running vold will properly report it to the Volume Manager and it will be recognized and utilized by apps.
In theory this is easy to accomplish on any rooted device, in practice there are a number of obstacles:
On a locked device, it is not possible to update init script to run the commands at system bootup.
Since Android 4.2, mount propagation no longer work (as described here http://forum.xda-developers.com/showthread.php?p=36889027),
so if sdcard is mounted in terminal, vold will still not see it. Hence the mount operation has to be done in adb.
Furthermore in Android 4.2.2, running adb on localhost is broken as a result of it loosing its private key.
See here https://code.google.com/p/android/issues/detail?id=48126 for more.
The solution?
Pre-requisites:
Rooted device (don't have to be unlocked) with USB debugging enabled.
MicroSD card formatted as ext4 (inserted)
Terminal app, such as Android Terminal Emulator https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en
Familiarity with adb.
Step 1 - Fix adb localhost.
Open terminal and type the commands:
Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
start adbd
HOME=/sdcard adb start-server
adb connect localhost
adb -s localhost:5555 shell
exit
stop adbd
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
Step 2 - Install scripts.
Please note that the script msd2.sh has to be modified if your device uses different partition names.
To get list of partition names available run command:
Code:
adb shell cat /proc/partitions
There are 3 (very simple) scripts:
sd.sh is just a convenience so that you don't have to type su everytime.
It calls msd1.sh which takes care of starting localhost adb in a reliable way.
It then executes msd2.sh in adb shell, which actually does the mounting trickery.
To install scripts, download the zip file below, open terminal, unzip the archive and change into msd directory.
Then connect your phone to your PC and run the following commands:
Code:
adb push sd.sh /sdcard/sd.sh
adb push msd1.sh /sdcard/msd1.sh
adb push msd2.sh /sdcard/msd2.sh
adb shell
su
mount -o rw,remount /system
cp sd.sh /system/xbin/
cp msd1.sh /system/xbin/
cp msd2.sh /system/xbin/
chmod 755 /system/xbin/*.sh
mount -o ro,remount /system
exit
exit
Step 3 - Profit.
In terminal app run command:
Code:
sd.sh
There will be some messages in notifications bar and then you will be asked if it is ok to restart MTP application. Click Ok.
That should be it.
Note that this last command will have to be executed every time device reboots (see obstacle #1).
You can automate it using Script Manager app from marketplace. In this case, ask Script Manager to run msd1.sh instead, marking it as Root script.
Disclaimers
I've developed and tested this procedure on Samsung Galaxy S4 Active phone from ATT.
Should work for any other Android 4.2 device.
The steps outlined are non-destructive if done properly and should not affect any other functionality, yet obviously I do not assume any responsibility for you damaging your device in the process.
It is a good idea to read the linked articles before performing the procedure, to get a better understanding of what is actually going on.
Motorola Droid 4 (xt894)
Hello!
if you have a Motorola Droid 4 you need to change the third row in "msd2.sh" from
"mount -t ext4 /dev/block/mmcblk1p1 /storage/extSdCard && sleep 5 && /system/bin/vold" to
"mount -t ext4 /dev/block/mmcblk0p1 /storage/sdcard1 && sleep 5 && /system/bin/vold"
in order to get it to work, thanks for the guide!
Best Regards
/ Rasmus
It works well on TW based MIUI
It works well on TW based MIUI, so many many thanks!!!
But I still have the permission problems mentioned.
AOSP based MIUI is ext4 compatibile out of the box, and without permission problems.
This trick is amazing, but the permission issue make it useless ...
I can not shot a picture and than have to manually change the permission of tehf ile in order to view it on the gallery ...
Is there a definititive solution?
My lg l3 e400..sd card not mounted
to sashavasco:
sir, pls help configuring my phone...the codes u've given at the top part seems to work accordingly..but after when i entered the command
"cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys"
it says: "no such file or directory"
can you point out the problem of the device plss...
i appriciate your response..
my phone s LG L3 E400..CYANOGENMOD 9..external sd wont mount on my device
sashavasko said:
Why?
Step 1 - Fix adb localhost.
Open terminal and type the commands:
Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
start adbd
HOME=/sdcard adb start-server
adb connect localhost
adb -s localhost:5555 shell
exit
stop adbd
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
Click to expand...
Click to collapse
I am getting an error here: adb -s localhost:5555 shell stating device offline. I've done this 6 times now, and it's always the same error
Galaxy S4 i337 NC1 Rooted
kevp75 said:
I am getting an error here: adb -s localhost:5555 shell stating device offline. I've done this 6 times now, and it's always the same error
Galaxy S4 i337 NC1 Rooted
Click to expand...
Click to collapse
the same for me...
same error "unable to connect to local host:5555"
rooted Asus memo-7 build ME173X_US_user_4.2.404152_20140714 release-keys. But thanks for the heads up on Cyanogenmod.
>>If MicroSD card is mounted manually in the way that vold can see it, re-running vold will properly report it to the Volume Manager and it will be recognized and utilized by apps.
Re-running vold crashes it ("Segmentation fault") if sdcard is already mounted in ext4. If not, it restarts gracefully.
Stock android 4.4.2. AFAIK, vold must inform userspace stuff that sdcard is available, without it, android do not see any sdcard at all...
What can be done here?
p.s. Is there anywhere patched or recompiled vold which supports ext4?
Gigionaytor said:
the same for me...
Click to expand...
Click to collapse
same here too. Please help.
ZeroBubble said:
same here too. Please help.
Click to expand...
Click to collapse
Same error!
I had to modify terminal commands a bit to allow me to connect properly. Only moving the "start adbd" command down because the key needed to be appended to "adb_keys" before starting the service back up.
Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
HOME=/sdcard adb start-server
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
adb connect localhost
adb -s localhost:5555 shell
exit
I'm also still dealing with the "msd1.sh" script execution consistently asking about my fingerprint and not remembering it. If I don't press "continue" quick enough it claims the resource is busy, which prompted me to also change the msd1.sh script sleep from 2 to 5. I have gotten the notification that msd2.sh has been elevated, which seems like it ran, but my partition still doesn't get mounted, even though I've got the right one from the /proc/partitions output.
Another note, because I had BusyBox installed, I needed to prepend "busybox" (no quotes) to the mount command in the msd2.sh or else that wouldn't work either.
Anyone have thoughts?
I followed DemisesAngel suggestion. There was no error this time but nothing happens when running any of the 3 scripts. I tried mmcblk1 and mmcblk1p1, also changed microsd path to match, /MicroSD, but nothing works. Even with manual ext4 mount command ...
Clicking mount in settings still results in incompatible storage and file explorer shows no sdcard.
Edit: Set permissions, script will run but nothing mounts unsupported file system ...
Error directory already exist
I folllow the steps but i.think I meaaes up.
When u run through DemiseAngel scripts
At:
car /sdcard/.android/adbkey.pub >> /
Error:tmp-mkish:cant create /:Is a directory
To I attempt to find and rm it, or would that mess something up
Rca RCT677W22
I dont know if this thread is closed but I have one simple question, can I somehow partition sdcard and have a little space for music and other stuff, and to use ext4 partition alongside with this, lets say "visible" partition ( I mean on windows).
WrathBand said:
I dont know if this thread is closed but I have one simple question, can I somehow partition sdcard and have a little space for music and other stuff, and to use ext4 partition alongside with this, lets say "visible" partition ( I mean on windows).
Click to expand...
Click to collapse
First, I have been able to create a formatted partition of less than the full size of an SD card. I did this because my Android seems to have issues with anything larger than 16GB and all I had lying around was a 64GB. I did not try to do anything with the remaining space. Maybe it could work, maybe not. I would have my doubts.
Second, thanks for this discussion. Here is what "kind of" works on my Android 5.1 TV computer:
su -mm -c mount -t ext4 -o noatime /dev/block/mmcblk0p1 /storage/sdcard1 && sleep 5 && /system/bin/vold
chown -R root:sdcard_r /storage/sdcard1
chmod 771 /storage/sdcard1
I say "kind of" because this is still not seen as a true, external storage card by Android or file manager apps (and the like). However, all apps can read/write/traverse the folder tree and do what they need to. You do NOT have to be root except to do this. As things stand for me now, I have to re-issue this upon every re-start of Android. But using Tasker makes this pretty easy to accomplish.
long as a problem remains so do this thread ! . Well i am on 7.x and wonder if the op would post a method or even approach for getting a
Code:
ext4
partitioned sdcard so that vold is well aware of that and will mount sdcardfs on that giving all apps access to the partitions. I have 3 of these on my card .
Is there a method to auto mount ext4 partition on external SD that works on lineageOS 17.1 on S4 i9506?

[Q] Mounting userdata partition on PC

Hello all,
Last night I ran the following command (with the phone in recovery and everything unmounted) to back up my Nexus 5's userdata partition to my computer:
Code:
adb pull /dev/block/platform/msm_sdcc.1/by-name/userdata
My phone is encrypted, so I use "cryptsetup --type=plain open" to obtain a plaintext version on /dev/mapper/my-nexus-backup. But I cannot mount the mapped device using "mount"! It complains that iit can't find the filesystem.
So, how would I mount such an image? Or, even better, what's the best way to dd it back to the userdata partition on the device?
And yes, next time I will just use a Nandroid, even if it means having to erase things to make room.
See if @rootSU or @bitdomo can help. They're gurus at this type of stuff
Sent from my Nexus 5 using XDA Free mobile app
Sorry, where are you mounting exactly? Are you trying to mount an image on a Linux box after the pull?
If not can you please share the full step of commands and what you expect to happen please?
Sent from my Nexus 5 using Tapatalk
rootSU said:
Sorry, where are you mounting exactly? Are you trying to mount an image on a Linux box after the pull?
If not can you please share the full step of commands and what you expect to happen please?
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Hey rootSU. I pulled the image from my phone, decrypted it, and tried to mount it:
Code:
$ adb pull /dev/block/platform/msm_sdcc.1/by-name/userdata
$ su
# losetup /dev/loop1 userdata
# cryptsetup open --type plain /dev/loop1 nexus
Enter passphrase:
# mount /dev/mapper/nexus /mnt/tmp
mount: wrong fs type, bad option, bad superblock on /dev/mapper/nexus,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
I'm not sure why that doesn't work. It's just ext4, right? I'd still find it instructive to figure out how to mount it; hopefully you can shed some light?
As far as getting the image back on the device's partition, I was a bit stuck, because there's obviously no room on the device to copy it to. I finally figured out a method involving netcat. Essentially I forwarded a local TCP port to my device (in recovery) using adb, then used netcat to feed dd the image.
Code:
$ adb forward tcp:4444 tcp:4444
$ adb shell
# nc -l -p 4444 -e dd of=/dev/block/platform/msm_sdcc.1/by-name/userdata
This will hang as it waits for an inbound connection. From a second shell:
Code:
$ dd if=userdata | nc localhost 4444
My 28GiB image took around 6 hours (!) to complete. Nandroid is probably the way to go.
Nandroid won't backup sdcard but you can use foldersync to back that up.
Yes it is just ext4
I've never done anything like this before with an encrypted device but my assumption was if you adb pull a file, it would decrypt it on the fly.. Does it not?? If it does, I'd just dd it to an img.
Sent from my Nexus 5 using Tapatalk
rootSU said:
Nandroid won't backup sdcard but you can use foldersync to back that up.
Yes it is just ext4
I've never done anything like this before with an encrypted device but my assumption was if you adb pull a file, it would decrypt it on the fly.. Does it not?? If it does, I'd just dd it to an img.
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Nope, in this case, userdata is the encrypted *device*; in any case TWRP knows nothing about the encryption. The pull was identical to using dd to copy the file. Of course, if you wanted to decrypt your device without wiping data, you could probably have TWRP decrypt the data partition, then dd or pull the resulting /dev/block/dm-0 file (which is equivalent to my /dev/mapper/nexus file I created). Haven't tried it though; ain't nobody got time for that.
I wonder why it wouldn't mount. Oh well. I'm just happy that my device is the way it was yesterday.
I'd love to have a play with this but I just don't have the time to start encrypting and decrypting stuff
Out of interest what about adb whilst in android?
Sent from my Nexus 5 using Tapatalk
rootSU said:
I'd love to have a play with this but I just don't have the time to start encrypting and decrypting stuff
Out of interest what about adb whilst in android?
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
You would have the exact same results, as the /dev/* files are the physical disks represented as a file. The crypto drivers read/write this block device file to present a decrypted /dev/block/dm-0 device. Then the kernel mounts dm-0 as an ext4 filesystem on /data. All the files I mentioned are pullable with adb, assuming you have sufficient privileges. You don't need fancy tools to read/write them, which is why the netcat hack worked. Thus is the power of Unix!
You can screw around with it if you want in regular desktop Linux with a "device" you make from a bunch of 0s. Do:
Code:
# dd if=/dev/zero of=disk.image count=100000
# losetup /dev/loop0 disk.image
Now you can do "mkfs.ext4 /dev/loop0" and "mount ..." or whatever, and the data will be written to the "device" disk.image.
some time ago I backed up /dev/block/sda from my android 12 phone.
I forgot it was encrypted..
and that it had 34 partitions.
userdata partition WAS sda34.
how can I momentarily mount the backup in android?
losetup is present...

Running "dd" using "busybox nc" stops w.o errors, random size every time

Phone: Nexus 5 running Lineage 18.1 and rooted with Magisk v25.2 (and BusyBox 1.32.0)
OS: Windows 11 Version 22H2 (OS Build: 22621.819)
Autopsy: 4.19.3
Hello,
Trying to dump my "/data"-partition from my Android-phone and analyze it in Autopsy.
If I run a `mount` command on my phone I can see the following information for my "/data"-partition:
Code:
/dev/block/mmcblk0p29 on /data type ext4 (rw,seclabel,nosuid,nodev,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic,data=ordered)
I then proceed to image that partition by running:
Code:
dd if=/dev/block/mmcblk0p29 of=/sdcard/mmcblk0p29.img
it fails because my device runs out of diskspace which is kind of logical.
If I try:
[Console 1 (Windows)]
Code:
adb forward tcp:9191 tcp:9191
Code:
ncat 127.0.0.1 9191 > android_data.dd
[Console 2 (Phone)]
Code:
dd if=/dev/block/mmcblk0p29 | busybox nc -l -p 9191
I can see that it writes "android_data.dd" but that file always "stops" growing after a random size even though neither "Console 1" or "Console 2" outputs any errors.
Whats weird is that I need to install BusyBox after every reboot of my phone, perhaps that is normal?
Q1) I am dumping the right partition?
I have multiple partitions that are named something like /dev/D8RN3/.magisk/block/system_root on /system/bin/debuggerd` thinking that I might dump the "/data"-partition which isn't mounted as "root" and that might cause the issue below?
Q2) How can I get past the "error" that the file ("android_data.dd") stops growing?
I was able to get the entire file once (~ 27GB) but now the file stops growing after a random amount of size (which always differs).
There are no errors in either adb ("phone"-side) or PowerShell ("computer"-side).
Thanks for any suggestion - TheSwede86

Categories

Resources