Mounting Volumes on VMs

This page describes how to mount disk volumes on Virtual Machines in the "SKY" cluster.

Often times, your VM will come with more than one volume.  The primary volume is the operating system partition, and is usually 50gb.  If you have purchased a "medium" or "large" VM, you will also have a second volume with additional storage space, but you may need to format and mount it before you are able to use it.

Detecting Volumes

Use the fdisk -l command to list available volumes on your VM. The output will look similar to the following:

# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00089a75

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    96468991    48233472   83  Linux
/dev/vda2        96468992   104857599     4194304   82  Linux swap / Solaris

Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008bba1

   Device Boot      Start         End      Blocks   Id  System

Notice that there are two lines that begin with Disk.  This means there are two volumes attached to this VM.  The first one is /dev/vda.  As you can see, this is formatted and partitioned already.

The second disk is /dev/vdb, and you can see from the toutput that there are no items listed in the table, Device Boot Start End Blocks..  This means that the volume has not been formatted yet.

Formatting the Volume

Before you can mount the volume, you must create a filesystem on it.  The most common filesystem is ext4, but you can use whatever filesystem you wish.

To format it, run the command:

$ sudo mkfs.ext4 /dev/vdb

Be VERY CAREFUL to specify the correct device.  If you accidentally format your primary volume, you may end up deleting all data on your server.  This command will take a moment to runa nd produce some output similar to the following:

mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

Mounting the volume

Now that the volume is formatted, you can mount it in your file tree.  Create a directory where you can mount the filesystem, or use an existing empty directory (for example; /srv).

Edit the /etc/fstab file and add the following lines to the end of it:

# Volume Mount
/dev/vdb /srv ext4 defaults 0 0

Now, you can mount the volume by running:

$ sudo mount /srv

You can test to ensure that the volume is mounted in that location by running the mount command:

$ mount

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=931812k,nr_inodes=232953,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/vda1 on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=33,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
/dev/vdb on /srv type ext4 (rw,noatime,data=ordered)

Notice the line in that output that begins with /dev/vdb.  This volume will now be mounted at /srv every time you boot your system.