How do I get all the mount point information for an Android device programmatically?
See mount points using findmnt: The command findmnt lists all mount points. To do this the findmnt reads files /etc/fstab, /etc/fstab. d, /etc/mtab or /proc/self/mountinfo.
You can use df command to list mount points. You can use -t followed by filesystem type (say ext3, ext4, nfs) to display respective mount points. For examples below df command display all NFS mount points.
They are located in the /proc/mounts "file", which you can read and parse. Since it in /proc directory, looks like it is not persistent in disk. So how it get stored when power is off?
Using the mount Command One way we can determine if a directory is mounted is by running the mount command and filtering the output. The above line will exit with 0 (success) if /mnt/backup is a mount point. Otherwise, it'll return -1 (error).
You can see the partitions known to the system by examining /proc/partitions
. From my HTC Desire:
major minor #blocks name
31 0 640 mtdblock0
31 1 4608 mtdblock1
31 2 3072 mtdblock2
31 3 256000 mtdblock3
31 4 40960 mtdblock4
31 5 151168 mtdblock5
179 0 3872256 mmcblk0
179 1 2872070 mmcblk0p1
179 2 1000185 mmcblk0p2
The mtdblock
devices are the phone's internal flash storage. mmcblk0
is the phone's SD card.
The best way to see what is mounted where is to examine /proc/self/mountinfo
. This is better than /proc/mounts
because the latter misses certain information. Again, on my HTC Desire (I added column headings and ran the output through column -s
for good measure):
ID PARENT BLOCK ROOT MOUNTPOINT OPTIONS - TYPE SOURCE SUPEROPTS
1 1 0:1 / / ro,relatime - rootfs rootfs ro
11 1 0:11 / /dev rw,relatime - tmpfs tmpfs rw,mode=755
12 11 0:9 / /dev/pts rw,relatime - devpts devpts rw,mode=600
13 1 0:3 / /proc rw,relatime - proc proc rw
14 1 0:12 / /sys rw,relatime - sysfs sysfs rw
15 1 0:13 / /acct rw,relatime - cgroup none rw,cpuacct
16 1 0:14 / /mnt/asec rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
17 1 0:15 / /mnt/obb rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
18 11 0:16 / /dev/cpuctl rw,relatime - cgroup none rw,cpu
19 1 31:3 / /system ro,relatime - yaffs2 /dev/block/mtdblock3 ro
20 1 31:5 / /data rw,nosuid,nodev,relatime - yaffs2 /dev/block/mtdblock5 rw
21 1 31:4 / /cache rw,nosuid,nodev,relatime - yaffs2 /dev/block/mtdblock4 rw
22 21 31:5 /local/download /cache/download rw,nosuid,nodev,relatime - yaffs2 /dev/block/mtdblock5 rw
23 1 179:2 / /sd-ext rw,nosuid,nodev,noatime,nodiratime - ext4 /dev/block/mmcblk0p2 rw,commit=19,barrier=0,data=writeback
24 20 179:2 /app /data/app rw,nosuid,nodev,noatime,nodiratime - ext4 /dev/block/mmcblk0p2 rw,commit=19,barrier=0,data=writeback
25 20 179:2 /data /data/data rw,nosuid,nodev,noatime,nodiratime - ext4 /dev/block/mmcblk0p2 rw,commit=19,barrier=0,data=writeback
26 14 0:6 / /sys/kernel/debug rw,relatime - debugfs /sys/kernel/debug rw
27 1 179:1 / /mnt/sdcard rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1 rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro
28 1 179:1 /.android_secure /mnt/secure/asec rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1 rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro
29 27 0:17 / /mnt/sdcard/.android_secure ro,relatime - tmpfs tmpfs ro,size=0k,mode=000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With