Vold (Volume Daemon) Architecture
The Volume Daemon (vold) is a critical native C++ service in Android responsible for managing all storage devices. It acts as the bridge between the Linux kernel (which detects block devices) and the higher-level Java framework (specifically StorageManagerService).
Vold Responsibilities
Vold handles the physical and cryptographic lifecycle of storage volumes:
- Mounting and Unmounting: Mounting SD cards, USB OTG drives, and internal emulated storage.
- Formatting: Formatting newly inserted or adoptable storage devices.
- Encryption: Managing File-Based Encryption (FBE) and Full-Disk Encryption (FDE) keys, communicating with the kernel's
fscryptand the Keymaster/KeyMint HAL. - Namespaces: Setting up mount namespaces so that different apps see different views of the storage (Scoped Storage).
The IVold AIDL Interface
Historically, communication between the system server and vold happened via a socket using a text-based protocol (vdc). In modern Android versions, this has been migrated to Binder using the IVold.aidl interface.
// Simplified snippet of IVold.aidl
interface IVold {
void mount(in @utf8InCpp String volId, int mountFlags, int mountUserId);
void unmount(in @utf8InCpp String volId);
void format(in @utf8InCpp String volId, in @utf8InCpp String fsType);
void partition(in @utf8InCpp String diskId, int partitionType, int ratio);
// Encryption specific methods
void fbeEnable(int ext4, int f2fs);
}
The StorageManagerService binds to vold and calls these methods directly, providing a robust, typed IPC mechanism.
SD Card Mounting Flow
When a user inserts an SD card, the following sequence occurs:
- Kernel Detection: The kernel detects the hardware interrupt, enumerates the block device, and emits a
ueventvia netlink. - Vold Netlink Listener:
voldlistens on the netlink socket, parses theuevent, and identifies the new block device. - Volume Creation:
voldcreates aVolumeBaseobject (e.g.,PublicVolumefor a portable SD card) representing the disk. - Notification:
voldnotifiesStorageManagerServicevia an asynchronous callback (IVoldListener) that a new volume is "unmounted" but available. - Mount Request:
StorageManagerServiceevaluates policies and sends amount()command back tovoldviaIVold. - Filesystem Checks:
voldrunsfsck(e.g.,fsck.exfatorfsck.vfat) to ensure the filesystem is clean. - Mounting:
voldmounts the filesystem (typically usingsdcardfsor FUSE, depending on the Android version) to a path like/mnt/media_rw/UUID.
USB Storage Handling
USB On-The-Go (OTG) drives follow a similar path. The primary difference is the transport layer in the kernel. vold parses the sysfs paths to determine that the block device originates from the USB subsystem and labels it accordingly as a USB drive in the framework, triggering appropriate UI notifications.
Debugging Vold
The vdc (Volume Daemon Client) command-line tool can be used to interact with vold directly.
Dump internal vold state:
adb shell dumpsys vold
Manually list volumes:
adb shell vdc volume list