[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Adoptable storage\n\nAndroid has always supported external storage accessories (such as SD cards), but\nthese accessories were historically limited to simple file storage, due to\ntheir expected impermanence and the minimal data protection offered to\n[traditional external storage](/docs/core/storage/traditional).\nAndroid 6.0 introduced the ability to\n[adopt](http://developer.android.com/about/versions/marshmallow/android-6.0.html#adoptable-storage) external storage media to act like internal\nstorage.\n| **Caution** : On devices running Android 7.0-8.1,\n| [file-based encryption](/docs/security/features/encryption/file-based)\n| (FBE) can't be used together with adoptable storage. On devices\n| using FBE, new storage media (such as an SD card) must be used as\n| [traditional storage](/docs/core/storage/traditional).\n|\n| Devices running Android 9 and higher can use adoptable storage and FBE.\n\nWhen external storage media is adopted, it's formatted and encrypted to only\nwork with a single Android device at a time. Because the media is strongly tied\nto the Android device that adopted it, it can safely store both apps and\nprivate data for all users.\n\nWhen users insert new storage media (such as an SD card) in an adoptable\nlocation, Android asks them how they want to use the media. They can choose to\nadopt the media, which formats and encrypts it, or they can continue using it\nas-is for simple file storage. If they choose to adopt, the platform offers to\nmigrate the primary shared storage contents (typically mounted at\n`/sdcard`) to the newly adopted media, freeing up valuable space on\ninternal storage. Unlike traditional storage, which is limited to 2TB due to its\nuse of\n[MBR](https://en.wikipedia.org/wiki/Master_boot_record),\nadoptable storage uses\n[GPT](https://en.wikipedia.org/wiki/GUID_Partition_Table)\nand therefore has file storage limit of \\~9ZB.\n\nApps can be placed on adopted storage media only when the developer has\nindicated support through the `android:installLocation` attribute.\nNew installs of supported apps are automatically placed on the\nstorage device with the most free space, and users can move supported apps\nbetween storage devices in the *Settings* app. Apps moved to adopted\nmedia are remembered while the media is ejected,\nand return when the media is reinserted.\n\nSecurity\n--------\n\nThe platform randomly generates encryption keys for each adopted device\nand stores them on the internal storage of the Android device. This\neffectively makes the adopted media as secure as internal storage. Keys are\nassociated with adopted devices based on the adopted partition GUID.\n\nIf the device is configured to use [file-based encryption](/docs/security/features/encryption/file-based) (FBE) on its\ninternal storage, then adoptable storage uses both FBE and [metadata encryption](/docs/security/features/encryption/metadata). Otherwise,\nadoptable storage uses [full-disk\nencryption](/docs/security/features/encryption/full-disk) (FDE).\n\nThe on-disk layout of the adopted device closely mirrors the internal data\npartition, including SELinux labels, etc. When multi-user is supported on the\nAndroid device, the adopted storage device also supports multi-user with the\nsame level of isolation as internal storage.\n\nBecause the contents of an adopted storage device are strongly tied to the\nAndroid device that adopted it, the encryption keys should not be extractable\nfrom the parent device, and therefore the storage device can't be mounted\nelsewhere.\n\nIf your device uses FBE, see the [FBE\ndocumentation](/docs/security/features/encryption/file-based#enabling-fbe-on-adoptable-storage) and the [metadata\nencryption documentation](/docs/security/features/encryption/metadata#configuration-on-adoptable-storage) for how to configure FBE and metadata encryption on\nadoptable storage.\n\nPerformance and stability\n-------------------------\n\nOnly external storage media in stable locations, such as a slot inside a\nbattery compartment or behind a protective cover, should be considered for\nadoption to help avoid accidental data loss or corruption. In particular, USB\ndevices connected to a phone or tablet should never be considered for adoption.\nOne common exception would be an external USB drive connected to a TV-style\ndevice, because the entire TV is typically installed in a stable location.\n\nWhen a user adopts a new storage device, the platform runs a benchmark and\ncompares its performance against internal storage. If the adopted device is\nsignificantly slower than internal storage, the platform warns the user about a\npossibly degraded experience. This benchmark was derived from the actual I/O\nbehavior of popular Android apps. Currently, the AOSP implementation will only\nwarn users beyond a single threshold, but device manufacturers may adapt this\nfurther, such as rejecting adoption completely if the card is extremely slow.\n\nAdopted devices must be formatted with a filesystem that supports POSIX\npermissions and extended attributes, such as `ext4` or\n`f2fs`. For optimal performance, the `f2fs` filesystem is\nrecommended for flash-based storage devices.\n\nWhen performing periodic idle maintenance, the platform issues\n`FI_TRIM` to adopted media just like it does for internal storage.\nThe current SD card specification does not support the `DISCARD`\ncommand; but the kernel instead falls back to the `ERASE` command,\nwhich SD card firmware may choose to use for optimization purposes.\n\nTesting\n-------\n\n\nTo test that adoptable storage is working, run this CTS test: \n\n```\ncts-tradefed run commandAndExit cts-dev \\\n -m CtsAppSecurityHostTestCases \\\n -t android.appsecurity.cts.AdoptableHostTest\n```\n\n\nTo verify behavior of USB drives and SD cards when a device doesn't have a\nbuilt-in slot or when the USB connector is being used for an active adb\nconnection, use: \n\n```text\nadb shell sm set-virtual-disk true\n```"]]