toybox icon indicating copy to clipboard operation
toybox copied to clipboard

toybox blkid requires root (and still misses things)

Open MuntashirAkon opened this issue 5 years ago • 5 comments

The toybox blkid command doesn't seem to work on Android. I've tried the Android's default toybox binary and the prebuilt binaries from your website both of which have produced the same output. But the blkid binary (which is a separate binary since it's not symlinked to toybox) that comes with Android works. Is there any particular reason for this?

toybox blkid

device:/ $ su -c toybox blkid                                                                                                                                
blkid: /dev/ram0: No such file or directory
blkid: /dev/ram1: No such file or directory
blkid: /dev/ram2: No such file or directory
blkid: /dev/ram3: No such file or directory
blkid: /dev/ram4: No such file or directory
blkid: /dev/ram5: No such file or directory
blkid: /dev/ram6: No such file or directory
blkid: /dev/ram7: No such file or directory
blkid: /dev/ram8: No such file or directory
blkid: /dev/ram9: No such file or directory
blkid: /dev/ram10: No such file or directory
blkid: /dev/ram11: No such file or directory
blkid: /dev/ram12: No such file or directory
blkid: /dev/ram13: No such file or directory
blkid: /dev/ram14: No such file or directory
blkid: /dev/ram15: No such file or directory
blkid: /dev/loop0: No such file or directory
blkid: /dev/loop1: No such file or directory
blkid: /dev/loop2: No such file or directory
blkid: /dev/loop3: No such file or directory
blkid: /dev/loop4: No such file or directory
blkid: /dev/loop5: No such file or directory
blkid: /dev/loop6: No such file or directory
blkid: /dev/loop7: No such file or directory
blkid: /dev/zram0: No such file or directory
blkid: /dev/mmcblk0: No such file or directory
blkid: /dev/mmcblk0p1: No such file or directory
blkid: /dev/mmcblk0p2: No such file or directory
blkid: /dev/mmcblk0p3: No such file or directory
blkid: /dev/mmcblk0p4: No such file or directory
blkid: /dev/mmcblk0p5: No such file or directory
blkid: /dev/mmcblk0p6: No such file or directory
blkid: /dev/mmcblk0p7: No such file or directory
blkid: /dev/mmcblk0p8: No such file or directory
blkid: /dev/mmcblk0p9: No such file or directory
blkid: /dev/mmcblk0p10: No such file or directory
blkid: /dev/mmcblk0p11: No such file or directory
blkid: /dev/mmcblk0p12: No such file or directory
blkid: /dev/mmcblk0p13: No such file or directory
blkid: /dev/mmcblk0p14: No such file or directory
blkid: /dev/mmcblk0p15: No such file or directory
blkid: /dev/mmcblk0p16: No such file or directory
blkid: /dev/mmcblk0p17: No such file or directory
blkid: /dev/mmcblk0p18: No such file or directory
blkid: /dev/mmcblk0p19: No such file or directory
blkid: /dev/mmcblk0p20: No such file or directory
blkid: /dev/mmcblk0p21: No such file or directory
blkid: /dev/mmcblk0p22: No such file or directory
blkid: /dev/mmcblk0p23: No such file or directory
blkid: /dev/mmcblk0p24: No such file or directory
blkid: /dev/mmcblk0p25: No such file or directory
blkid: /dev/mmcblk0p26: No such file or directory
blkid: /dev/mmcblk0p27: No such file or directory
blkid: /dev/mmcblk0p28: No such file or directory
blkid: /dev/mmcblk0p29: No such file or directory
blkid: /dev/mmcblk0p30: No such file or directory
blkid: /dev/mmcblk0p31: No such file or directory
blkid: /dev/mmcblk0p32: No such file or directory
blkid: /dev/mmcblk0p33: No such file or directory
blkid: /dev/mmcblk0p34: No such file or directory
blkid: /dev/mmcblk0p35: No such file or directory
blkid: /dev/mmcblk0p36: No such file or directory
blkid: /dev/mmcblk0p37: No such file or directory
blkid: /dev/mmcblk0p38: No such file or directory
blkid: /dev/mmcblk0p39: No such file or directory
blkid: /dev/mmcblk0p40: No such file or directory
blkid: /dev/mmcblk0p41: No such file or directory
blkid: /dev/mmcblk0p42: No such file or directory
blkid: /dev/mmcblk0p43: No such file or directory
blkid: /dev/mmcblk0p44: No such file or directory
blkid: /dev/mmcblk0p45: No such file or directory
blkid: /dev/mmcblk0p46: No such file or directory
blkid: /dev/mmcblk0p47: No such file or directory
blkid: /dev/mmcblk0p48: No such file or directory
blkid: /dev/mmcblk0p49: No such file or directory
blkid: /dev/mmcblk0p50: No such file or directory
blkid: /dev/mmcblk0p51: No such file or directory
blkid: /dev/mmcblk0p52: No such file or directory
blkid: /dev/mmcblk0p53: No such file or directory
blkid: /dev/mmcblk0p54: No such file or directory
blkid: /dev/mmcblk0p55: No such file or directory
blkid: /dev/mmcblk0p56: No such file or directory
blkid: /dev/mmcblk0p57: No such file or directory
blkid: /dev/mmcblk0p58: No such file or directory
blkid: /dev/mmcblk0p59: No such file or directory
blkid: /dev/mmcblk0p60: No such file or directory
blkid: /dev/mmcblk0p61: No such file or directory
blkid: /dev/mmcblk0p62: No such file or directory
blkid: /dev/mmcblk0p63: No such file or directory
blkid: /dev/mmcblk0p64: No such file or directory
blkid: /dev/mmcblk0rpmb: No such file or directory
blkid: /dev/loop8: No such file or directory

Android built-in blkid

device:/ # blkid                                                                                                                                                                       
/dev/block/loop0: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop1: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop2: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop3: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop4: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop5: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop6: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/loop7: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 
/dev/block/zram0: UUID="4bf5d0dc-e044-42f3-83cf-a20a69a9da55" TYPE="swap" 
/dev/block/mmcblk0p38: SEC_TYPE="msdos" UUID="00BC-614E" TYPE="vfat" 
/dev/block/mmcblk0p48: LABEL="dsp" UUID="af32c008-2a39-7e5b-a5dc-201456d93103" TYPE="ext4" 
/dev/block/mmcblk0p53: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4" 
/dev/block/mmcblk0p54: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4" 
/dev/block/mmcblk0p56: SEC_TYPE="msdos" UUID="00BC-614E" TYPE="vfat" 
/dev/block/mmcblk0p60: UUID="007d4694-19f9-4e95-be68-70ee249b5d6f" TYPE="ext4" 
/dev/block/mmcblk0p61: LABEL="/" UUID="1c30a926-d896-5c34-b7bb-46927dd0c4e6" TYPE="ext4" 
/dev/block/mmcblk0p62: LABEL="vendor" UUID="39f8fbaa-7982-58a6-8cc5-199791a1ab75" TYPE="ext4" 
/dev/block/mmcblk0p63: LABEL="cust" UUID="f00b9a3b-4d08-c450-8c71-e78719096954" TYPE="ext4" 
/dev/block/mmcblk0p64: UUID="ed07d829-0b54-409b-adf4-aaede5a9ea1e" TYPE="ext4" 
/dev/block/loop8: UUID="7d1522e1-9dfa-5edb-a43e-98e3a4d20250" TYPE="ext4" 

MuntashirAkon avatar Sep 09 '20 06:09 MuntashirAkon

The error message is saying it can't open the /dev nodes.

This is really an Elliott question, but Android is covered with selinux, so binaries can require selinux annotations (extended attributes in the filesystem) to have permission to access a lot of stuff stuff. And unless you've rooted your device, the only way to add some of those annotations is at system image build time (I.E. by running AOSP or similar and installing a new image on your phone). When selinux is running, it won't let you add some of these attributes to new files, they have to be grandfathered in at install time.

landley avatar Sep 09 '20 07:09 landley

Android is covered with selinux, so binaries can require selinux annotations (extended attributes in the filesystem) to have permission to access a lot of stuff stuff.

Does it mean that I've to build toybox using my Android device?

MuntashirAkon avatar Sep 09 '20 08:09 MuntashirAkon

it looks like the util-linux blkid works completely differently from toybox. it's not opening "/dev/" + name listed in /proc/partitions. it looks like it's opening "/sys/dev/block/" + device major/minor listed in /proc/partitions, and then getting the uuid from dm/uuid off that, and using /dev/mapper (though i don't know how it knows what to ask /dev/mapper for without also reading the dm/name file?).

i see this on my desktop --- toybox blkid is just a list of "Permission denied"s, but util-linux blkid works as non-root.

enh-google avatar Sep 09 '20 19:09 enh-google

it looks like even if i run toybox blkid as non-root on my desktop, i still see less than i would with util-linux blkid. specifically: one device from /proc/partitions is missing completely, and util-linux additionally includes BLOCK_SIZE, PARTLABEL, and PARTUUID information.

enh-google avatar Sep 09 '20 19:09 enh-google

Hmmm. Design difference. Toybox is treating image files and block devices the same, that one's asking the kernel "what you have you identified" and passing on what the kernel tells it.

https://en.wikipedia.org/wiki/Device_mapper

And of course they buried the "how it actually works" part inside a magic shared library.

https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/index.html

Yup, rather than documenting the kernel api they documented the userspace tool's config file format IN THE KERNEL DOCUMENTATION.

This looks like one of those "the power of strace compels you" and "read the kernel source" things. I'll throw it on the todo heap.

landley avatar Sep 10 '20 04:09 landley