Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets, create disk images of them, and resize them at any time.
When you first create a new volume, you need to format it. Formatting a volume creates a filesystem on the volume, erasing any existing data. You only need to format a volume once when you first create it because new volumes don’t have a filesystem.
Every time you attach a volume to a Droplet, including the first time, you need to mount it. Mounting a formatted volume adds the volume’s filesystem to the Droplet’s existing file hierarchy. You need to mount a volume every time you attach it to a Droplet to make it accessible to that Droplet’s operating system.
Only during a volume’s initial creation, you can choose to automatically format and mount it to a Droplet with a supported operating system.
We cannot automatically mount volumes for you at any time other than when you first create the volume.
We automatically format and mount newly-created volumes by writing some metadata to the volume for the Droplet to read and perform the setup. Once the volume is mounted, this metadata is deleted. For privacy and security reasons, we can’t write to a volume after it’s fully created, so we can’t automatically mount volumes after their initial creation.
You can set up persistent mounting to tell the operating system to mount certain filesystems on boot, which lets volumes remain accessible after reboots.
To mount a formatted volume, first choose a mount point, which is the directory where the volume’s filesystem should be attached. This is where you access the volume’s files after it’s mounted.
We recommend creating a new directory in /mnt
to use as a mount point:
sudo mkdir /mnt/example_mount_point
Next, use mount
to mount the volume’s filesystem to the mount point. We recommend using the same options as automatic mounting, which are defaults,nofail,discard,noatime
:
sudo mount -o defaults,nofail,discard,noatime /dev/disk/by-id/scsi-example /mnt/example_mount_point
These options include read/write access, executing programs, error suppression for nonexistent devices, and continuous TRIM. mount
’s man page (man mount
) explains these and all other mount options in detail.
You can check that the mount itself was successful by passing the mount point to findmnt
:
findmnt /mnt/use_your_mount_point
You should see output indicating that it is currently mounted:
TARGET SOURCE FSTYPE OPTIONS
/mnt/example_mount_point /dev/sda1 ext4 rw,noatime,discard,data=ordered
The /etc/fstab
file contains static information about filesystems that the operating system can mount, including which ones to mount automatically at boot. You can add a line to this file for the volume’s filesystem to make it mount automatically when the Droplet boots. This keeps the volume’s filesystem persistent through reboots.
Each line in /etc/fstab
represents one filesystem and consists of six space-separated fields:
fs_spec
, the block device to mount. Use the /dev/disk/by-id
identifier for the volume or partition.
fs_file
, the mount point for the filesystem.
fs_vfstype
, the type of filesystem in lowercase, like ext4
or xfs
.
fs_mntops
, the mount options. We recommend the same options as automatic mounting, defaults,nofail,discard,noatime
. nofail
in particular lets the OS continue its boot sequence if the filesystem can’t be found, which is helpful if you detach the volume in the future without removing its fstab
entry.
fs_freq
, whether dump
should operate on the filesystem. Use 0 to disable this functionality unless you know you need it.
fs_passno
, the order that fsck
should check filesystems in. Use 2
to enable checking. The root filesystem should be 1
, and 0
disables checking.
Ultimately, the line you add to /etc/fstab
should look like this, with your volume’s identifier and mount point:
/dev/disk/by-id/scsi-example /mnt/example-mount-point ext4 defaults,nofail,discard,noatime 0 2
After you edit the file, check that /etc/fstab
is parsable and usable:
findmnt --verify --verbose
This lists any parsing errors, execution errors, and warnings. Once you resolve all errors, you can use mount -a
to mount the volume.