What is the format of Android M1 Initial Preview system.img?


Question

I download Android Emulator M1 Initial Preview from https://github.com/google/android-emulator-m1-preview/releases


Inside the .app file I found api30-gphone-arm64-v8a/system.img which isn't a yaffs2 nor sparse file:


./unyaffs2 /tmp/android-wip/system.img /tmp/android-wip/system-img/
unyaffs2-0.2.8: image extracting tool for YAFFS2
image size (3232759808) is NOT a mutiple of 2048 + 64

operation incomplete
files contents may be broken

simg2img system.img.ext4 system.img
Invalid sparse file format at header magic
Failed to read sparse file

So what is the format of such file?


Updates:
Based on the direction from @Robert, I can see that the file is an fdisk image:


$ fdisk -lu system.img
Disk system.img: 3,1 GiB, 3232759808 bytes, 6313984 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 41F73643-DBCB-41A1-A27E-9FDB53578618

Device Start End Sectors Size Type
system.img1 2048 4095 2048 1M Linux filesystem
system.img2 4096 6311935 6307840 3G Linux filesystem

Now, it's unclear what format of the partition inside, because mount it as a regular linux partition fails:


$ sudo mount -o loop,offset=1048576 system.img /mnt/android-1
mount: /mnt/android-1: wrong fs type, bad option, bad superblock on /dev/loop17, missing codepage or helper program, or other error.

gparted also doesn't understand the partition:


enter image description here


Answer

wrong offset, partition start at sector 4096. you can use kpartx instead


newer android running dynamic partitions. the super partition can be unpacked with Dynamic Partition Tools


furthermore partitions are flagged as read-only, therefore mount -r flag is required


sudo -i

git clone https://github.com/AndroidDumps/Firmware_extractor.git
PATH=$PATH:$(realpath Firmware_extractor/tools/Linux/bin)

mkdir -p /mnt/android-1/system_root ../extracted
kpartx -av system.img
lpunpack -p system /dev/mapper/loop2p2 ../extracted

mount -t ext4 -o loop,ro,noexec,noload,noatime ../extracted/system.img /mnt/android-1/system_root
thunar /mnt/android-1/system_root

(or whatever kpartx tell you 2nd partition is mapped)




in case you need to make ext4-dedup/logical partition writeable, increase partition first, then duplicate shared blocks


cd ../extracted
dd if=/dev/zero bs=1G seek=1 count=0 of=system.img
resize2fs system.img 1G
e2fsck -E unshare_blocks system.img

you should be able to mount -w afterwards




re-packing requires new vbmeta signature with avbtool.py stored in first partition system.img1 start at sector 2048 (which goes too far here)


superrepack third-party cross-platform tool for easy unpack/repack system.img2 is recommended to automatize the whole re-packing process


you can however do it manually with lpmake (requires all partitions to be unpacked into ../extracted see above step lpunpack)

source


resize2fs -M system.img
e2fsck -yf system.img
lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:3229614080 --group main:2369171456 --partition system:readonly:787050496:main --image system=system.img --partition vendor:readonly:83619840:main --image vendor=vendor.img --partition product:readonly:1366814720:main --image product=product.img --partition system_ext:readonly:131686400:main --image system=system_ext.img --sparse --output super.img

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes