NavigationContentFooter
Jump toSuggest an edit

Managing a Block Storage volume

Reviewed on 28 May 2024Published on 29 November 2019

This documentation only explains how to mount additional block volumes to your Instance, as the root volume of your Instance is already mounted at creation. The volume where your OS is running cannot be mounted.

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • An SSH key
  • An Instance
  • Attached an additional Block Storage volume to your Instance

Mounting and using a Block Storage volume

In order to mount and use your Block Storage volume, you need to connect to the Instance it is attached to, via SSH. Then, check that the volume is available, format it, and mount it following the instructions below.

Verifying device availability

  1. Connect to your Instance with ssh.

    ssh root@<your_instance_ip>
  2. Use the lsblk command to make sure your block volume is available:

    lsblk

    You should see an output similar to the following. The root Block volume sda, runs your OS. The Block volume named sdb is the one we will be mounting to the Instance.

    root@scw-festive-agnesi:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    sda 8:0 0 18.6G 0 disk
    ├─sda1 8:1 0 18.5G 0 part /
    ├─sda14 8:14 0 4M 0 part
    └─sda15 8:15 0 106M 0 part /boot/efi
    sdb 8:16 0 27.9G 0 disk
Note

The Scaleway ecosystem uses GB to define storage sizes and not GiB as the default on linux.


Formatting the Block volume

Formatting your volume prepares it for storing files.

  1. Create a filesystem with the following command. This command uses the ext4 filesystem, though you can choose another if you prefer.
    # Make sure that you replace `/dev/sdX` with the name of your volume
    mkfs.ext4 /dev/sdX
  2. Make sure your filesystem is correctly created by running the lsblk -f command.
    lsblk -f

You should see an output like the following. Check that the FSTYPE field matches ext4 for your Block volume. In this example, we have formatted the sdb volume.

root@scw-festive-agnesi:~# lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1
│ ext4 1.0 cloudimg-rootfs
│ cf5b092b-9a8b-49e9-980c-b44b5e3ed197 14.5G 18% /
├─sda14
└─sda15
vfat FAT32 UEFI D590-3FD4 98.3M 6% /boot/efi
sdb ext4 1.0 d36bdf8b-b2ff-4e2b-9736-cc05940aea35

Creating the mount point and mounting the Block volume

Once you have created your filesystem, you need to define where you want to mount your volume, and create a mount point (directory) for it.

  1. Create the mount point. Feel free to replace block-volume with another name for your mount point.

    mkdir /mnt/block-volume
  2. Mount the volume. We recommend that you use the defaults option, as in the command below.

    # Make sure that you replace sdX with the name of your volume
    mount -o defaults /dev/sdX /mnt/block-volume

    If you want to see all available options, you can run man mount on your Instance.

  3. Make sure your filesystem is properly mounted by running the lsblk command.

    lsblk

    You should see an output like the following. Check the MOUNTPOINT field.

    root@scw-festive-agnesi:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 18.6G 0 disk
    ├─sda1 8:1 0 18.5G 0 part /
    ├─sda14 8:14 0 4M 0 part
    └─sda15 8:15 0 106M 0 part /boot/efi
    sdb 8:16 0 27.9G 0 disk /mnt/block-volume

The sdb volume is mounted at /mnt/block-volume


Using fstab for Persistent Mounting

With the current configuration, your volume will not be mounted automatically upon reboot. Use the /etc/fstab file to make sure the reboot does not impact your filesystem.

Run the following command to make sure your volume is automatically mounted to your Instance upon reboot. Make sure that you replace sdX with your volume.

echo "UUID=$(blkid --output value /dev/sdX | head -n1) /mnt/block-volume ext4 defaults 0 0" >> /etc/fstab

Transferring data from your local machine to the remote Block volume

You may wish to transfer files from your local machine to your Instance’s remote Block volume. This can be achieved with rsync, a tool for efficiently transferring and copying files. The rsync utility is pre-installed on most Linux distributions and macOS.

  1. Check that rsync is installed on your local machine with the following command:

    rsync --version

    You should see an output similar to the following:

    rsync version 3.1.3 protocol version 31
    Copyright (C) 1996-2018 by Andrew Tridgell, Wayne Davison, and others.
    Web site: http://rsync.samba.org/
    Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc
    rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
    are welcome to redistribute it under certain conditions. See the GNU
    General Public Licence for details.
    Tip

    If you get a command not found output (or similar), you need to install rsync:

    • On Linux Ubuntu and Debian systems, you can do this with the APT package tool using the sudo apt install rsync command.
    • For Linux CentOS/ Fedora, you can use the YUM package manager: sudo yum install rsync.
    • On Mac OSX with the Homebrew package manager, you can use brew install rsync.
  2. On your local machine, open a new terminal and use the following command to create a file called hello-world.txt:

    nano hello-world.txt
  3. Enter the text Hello World!.

  4. Press Ctrl O, Enter, and Ctrl X to save and exit the file.

  5. Enter the following command to transfer the file to your Instance’s mounted block volume. Ensure that you use your own Instance’s IP address:

    rsync -a hello-world.txt root@<your_instance_ip>:/mnt/block-volume

The file is now transferred. You can connect to your Instance again, and use the command cd /mnt/block-volume ; ls to check that the file appears in the directory.


Increasing the partition size of the volume with growpart

Important
  • We recommend that you make a backup of your data using the snapshot feature, before increasing the partition size of your volume. This helps you avoid any potential data loss.
  • You need to have partitioned your volume to follow the procedure below
  • If the partition you want to resize is mounted, you need to unmount it beforehand

growpart allows you to resize partitions. If you have increased the size of the partition’s underlying volume, for example, you might want to increase the size of the partition to make use of the additional space.

  1. Connect to your Instance using SSH.

  2. Use the lsblk command to identify your volume partition. Make sure that the partition is not mounted before you resize it. In the following example, we are resizing sdb1:

    root@scw-festive-agnesi:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    sda 8:0 0 23.3G 0 disk
    ├─sda1 8:1 0 23.2G 0 part /
    ├─sda14 8:14 0 4M 0 part
    └─sda15 8:15 0 106M 0 part /boot/efi
    sdb 8:16 0 38.6G 0 disk
    └─sdb1 8:17 0 18.6G 0 part
  3. Use growpart to increase the partition size of your block storage volume (here sdb1):

    # Replace /dev/sdX 1 with the name of your partition
    growpart /dev/sdX 1
    Tip

    Make sure that you add a space between the device identifier (/dev/sdX) and the partition number (1).

    You should see an output similar to the following:

    CHANGED: partition=1 start=0 old: size=39061504 end=39061504 new: size=58490880 end=58490880
  4. Use lsblk to check that the partition was correctly resized. In the following output, you can see in the SIZE field that our partition sbd1 went from 18.6G (step 2) to 27.9G.

    root@scw-festive-agnesi:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    sda 8:0 0 18.6G 0 disk
    ├─sda1 8:1 0 18.5G 0 part /
    ├─sda14 8:14 0 4M 0 part
    └─sda15 8:15 0 106M 0 part /boot/efi
    sdb 8:16 0 27.9G 0 disk
    └─sdb1 8:17 0 27.9G 0 part
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway