Home | History | Annotate | Download | only in storage
      1 page.title=Adoptable Storage
      2 @jd:body
      3 <!--
      4     Copyright 2015 The Android Open Source Project
      5     Licensed under the Apache License, Version 2.0 (the "License");
      6     you may not use this file except in compliance with the License.
      7     You may obtain a copy of the License at
      8         http://www.apache.org/licenses/LICENSE-2.0
      9     Unless required by applicable law or agreed to in writing, software
     10     distributed under the License is distributed on an "AS IS" BASIS,
     11     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12     See the License for the specific language governing permissions and
     13     limitations under the License.
     14 -->
     15 <div id="qv-wrapper">
     16   <div id="qv">
     17     <h2>In this document</h2>
     18     <ol id="auto-toc">
     19     </ol>
     20   </div>
     21 </div>
     22 
     23 
     24 <p>Android has always supported external storage accessories (such as SD cards), but
     25 these accessories were historically limited to simple file storage, due to
     26 their expected impermanence and the minimal data protection offered to
     27 <a href="{@docRoot}devices/storage/traditional.html">traditional external storage</a>.
     28 Android 6.0 introduces the ability to
     29 <a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#adoptable-storage">adopt</a>
     30 external storage media to act like internal storage.</p>
     31 
     32 <p>When external storage media is adopted, its formatted and encrypted to only
     33 work with a single Android device at a time. Because the media is strongly tied
     34 to the Android device that adopted it, it can safely store both apps and
     35 private data for all users.</p>
     36 
     37 <p>When users insert new storage media (such as an SD card) in an adoptable
     38 location, Android asks them how they want to use the media. They can choose to
     39 adopt the media, which formats and encrypts it, or they can continue using it
     40 as-is for simple file storage. If they choose to adopt, the platform offers to
     41 migrate the primary shared storage contents (typically mounted at <code>/sdcard</code>)
     42 to the newly adopted media, freeing up valuable space on internal storage.
     43 Unlike traditional storage, which is limited to 2TB due to its use of
     44 <a href="https://en.wikipedia.org/wiki/Master_boot_record">MBR</a>, adoptable
     45 storage uses <a href="https://en.wikipedia.org/wiki/GUID_Partition_Table">GPT</a>
     46 and therefore has file storage limit of ~9ZB.</p>
     47 
     48 <p>Apps can be placed on adopted storage media only when the developer has
     49 indicated support through the <code>android:installLocation</code> attribute.
     50 New installs of supported apps are automatically placed on the
     51 storage device with the most free space, and users can move supported apps
     52 between storage devices in the <em>Settings</em> app. Apps moved to adopted
     53 media are remembered while the media is ejected,
     54 and return when the media is reinserted.</p>
     55 
     56 <h2 id=security>Security</h2>
     57 
     58 
     59 <p>The platform randomly generates an encryption key for each adopted device,
     60 and that key is stored on the internal storage of the Android device. This
     61 effectively makes the adopted media as secure as internal storage. Keys are
     62 associated with adopted devices based on the adopted partition GUID. The
     63 adopted device is encrypted using <code>dm-crypt</code> configured with the
     64 <code>aes-cbc-essiv:sha256</code> algorithm and a 128-bit key size.</p>
     65 
     66 <p>The on-disk layout of the adopted device closely mirrors the internal data
     67 partition, including SELinux labels, etc. When multi-user is supported on the
     68 Android device, the adopted storage device also supports multi-user with the
     69 same level of isolation as internal storage.</p>
     70 
     71 <p>Because the contents of an adopted storage device are strongly tied to the
     72 Android device that adopted it, the encryption keys should not be extractable
     73 from the parent device, and therefore the storage device can't be mounted elsewhere.</p>
     74 
     75 <h2 id=performance_and_stability>Performance and stability</h2>
     76 
     77 
     78 <p>Only external storage media in stable locations, such as a slot inside a
     79 battery compartment or behind a protective cover, should be considered for
     80 adoption to help avoid accidental data loss or corruption. In particular, USB
     81 devices connected to a phone or tablet should never be considered for adoption.
     82 One common exception would be an external USB drive connected to a TV-style
     83 device, because the entire TV is typically installed in a stable location.</p>
     84 
     85 <p>When a user adopts a new storage device, the platform runs a benchmark and
     86 compares its performance against internal storage. If the adopted device is
     87 significantly slower than internal storage, the platform warns the user about a
     88 possibly degraded experience. This benchmark was derived from the actual I/O
     89 behavior of popular Android apps. Currently, the AOSP implementation will only
     90 warn users beyond a single threshold, but device manufacturers may adapt this
     91 further, such as rejecting adoption completely if the card is extremely slow.</p>
     92 
     93 <p>Adopted devices must be formatted with a filesystem that supports POSIX
     94 permissions and extended attributes, such as <code>ext4</code> or <code>f2fs</code>.
     95 For optimal performance, the <code>f2fs</code> filesystem is recommended for
     96 flash-based storage devices.</p>
     97 
     98 <p>When performing periodic idle maintenance, the platform issues <code>FI_TRIM</code>
     99 to adopted media just like it does for internal storage. The current SD card
    100 specification does not support the <code>DISCARD</code> command; but the kernel
    101 instead falls back to the <code>ERASE</code> command, which SD card firmware
    102 may choose to use for optimization purposes.</p>
    103