IBM Cloud Docs
Setting up your Block Storage for VPC data volume for use (Linux)

Setting up your Block Storage for VPC data volume for use (Linux)

You can create a Block Storage for VPC volume and attached it to an instance in the IBM Cloud console, with the CLI, API or Terraform. If you want to use your IBM® Cloud Block Storage for Virtual Private Cloud volume as a file system, your next steps are to partition the volume, format it, and then mount it as a file system.

First, connect to your instance. Then, follow this procedure from the shell.

Listing all storage volumes

Run the following command to list all Block Storage for VPC volumes that are attached to your instance.

lsblk

The output looks similar to this example.

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    202:0    0  100G  0 disk
├─vda1 202:1    0  256M  0 part /boot
└─vda2 202:2    0 99.8G  0 part /
vdb    202:32   0  100G  0 disk

Volume vdb is your data volume.

Partitioning the volume

  1. Run the following command to partition the data volume.

    fdisk /dev/vdb
    
  2. Type the n command for a new partition, then type p for primary partition.

    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    
  3. Complete the prompts to define the partition's first cylinder number and last cylinder number. You can use the default value for the first cylinder number. For the last cylinder, you can either define an absolute value for the last sector or you can define a relative value to the start sector. To define a relative value, use the + symbol followed by the partition size. The size can be specified in kibibytes (K), mebibytes (M), gibibytes (G), tebibytes (T), or pebibytes (P). For example, to set the partition size to 100 GiB, enter +100G.

  4. After the partition is created, run the w command to save changes to the partition table. Restart your system to verify the newly created partition.

Formatting the volume partition

Create a file system on the new partition.

mkfs.ext4 /dev/vdb1

To check the size of the partition, run the following command.

fdisk -s /dev/vdb1

Creating a mount point

mkdir /myvolumedir

Mounting the volume

mount /dev/vdb1 /myvolumedir

Accessing the new file system

To see your new file system, run the following command.

df -k

The command produces an output like the following example.

file system     1K-blocks    Used Available Use% Mounted on
udev             4075344       0   4075344   0% /dev
tmpfs             816936    8844    808092   2% /run
/dev/vda2     101330012 1261048 100052580   2% /
tmpfs            4084664       0   4084664   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs            4084664       0   4084664   0% /sys/fs/cgroup
/dev/vda1        245679   64360    168212  28% /boot
tmpfs             817040       0    817040   0% /run/user/0
/dev/vdb1      103081248   61176  97777192   1% /myvolumedir

Go to the directory and create a file.

cd /myvolumedir
touch myvolumefile1

Updating the file systems table

Update the configuration file /etc/fstab so the data volume is automatically mounted upon boot. Root privileges are needed to update this file with a text editor, like nano, vim, or emacs. It is recommended that you back up the file before you make any changes.

sudo cp /etc/fstab /etc/fstab.orig

The following command starts nano to edit the configuration file.

sudo nano /etc/fstab

Add a line for the newly attached data volume that looks similar to the following example.

/dev/vdb1    /myvolumedir    ext4    defaults,_netdev    0    1

Instead of the device name /dev/vdb1, you can also use the UUID. To get the UUID of the data volume, use the blkid command.

blkid /dev/vdb1

When you're done editing, you can use sudo mount -a to remount the file systems that are listed in the updated /etc/fstab file without restarting your virtual server instance.