Advanced AOSP Subsystems
3 min read

Vold (Volume Daemon)

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 fscrypt and 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:

  1. Kernel Detection: The kernel detects the hardware interrupt, enumerates the block device, and emits a uevent via netlink.
  2. Vold Netlink Listener: vold listens on the netlink socket, parses the uevent, and identifies the new block device.
  3. Volume Creation: vold creates a VolumeBase object (e.g., PublicVolume for a portable SD card) representing the disk.
  4. Notification: vold notifies StorageManagerService via an asynchronous callback (IVoldListener) that a new volume is "unmounted" but available.
  5. Mount Request: StorageManagerService evaluates policies and sends a mount() command back to vold via IVold.
  6. Filesystem Checks: vold runs fsck (e.g., fsck.exfat or fsck.vfat) to ensure the filesystem is clean.
  7. Mounting: vold mounts the filesystem (typically using sdcardfs or 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