277 lines
9.5 KiB
Markdown
277 lines
9.5 KiB
Markdown
How to attach a volume to VM less than 2TB on Linux on connectVM Cloud[🔗](#how-to-attach-a-volume-to-vm-less-than-2tb-on-linux-on-brand-name "Permalink to this headline")
|
||
===========================================================================================================================================================================
|
||
|
||
In this tutorial, you will create a volume which is smaller than 2 TB. Then, you will attach it to a VM and format it in the appropriate way.
|
||
|
||
Note
|
||
|
||
If you want to create and attach a volume that has more than 2 TB of storage, you will need to use different software for its formatting. If this is the case, please visit the following article instead: [How to attach a volume to VM more than 2TB on Linux on connectVM Cloud](How-to-attach-a-volume-to-VM-more-than-2TB-on-Linux-on-connectVM-Cloud.html.md).
|
||
|
||
What We Are Going To Cover[🔗](#what-we-are-going-to-cover "Permalink to this headline")
|
||
---------------------------------------------------------------------------------------
|
||
|
||
> * Creating a new volume
|
||
> * Attaching the new volume to a VM
|
||
> * Formatting and mounting of the new volume
|
||
|
||
Prerequisites[🔗](#prerequisites "Permalink to this headline")
|
||
-------------------------------------------------------------
|
||
|
||
No. 1 **Hosting**
|
||
|
||
You need a connectVM Cloud hosting account with Horizon interface <https://console.connectvm.com/>.
|
||
|
||
No. 2 Linux VM running on the connectVM Cloud cloud
|
||
|
||
Instructions for creating and accessing a Linux VM using default images can be found here:
|
||
|
||
[How to create a Linux VM and access it from Linux command line on connectVM Cloud](../cloud/How-to-create-a-Linux-VM-and-access-it-from-Linux-command-line-on-connectVM-Cloud.html.md)
|
||
|
||
or here:
|
||
|
||
[How to create a Linux VM and access it from Windows desktop on connectVM Cloud](../cloud/How-to-create-a-Linux-VM-and-access-it-from-Windows-desktop-on-connectVM-Cloud.html.md).
|
||
|
||
The instructions included in this article are designed for Ubuntu 22.04 LTS.
|
||
|
||
No. 3 **Basic knowledge of the Linux terminal**
|
||
|
||
You will need basic knowledge of the Linux command line.
|
||
|
||
No. 4 **SSH access to the VM**
|
||
|
||
[How to connect to your virtual machine via SSH in Linux on connectVM Cloud](../networking/How-to-connect-to-your-virtual-machine-via-SSH-in-Linux-on-connectVM-Cloud.html.md).
|
||
|
||
Step 1: Create a Volume[🔗](#step-1-create-a-volume "Permalink to this headline")
|
||
--------------------------------------------------------------------------------
|
||
|
||
Login to the Horizon panel available at <https://console.connectvm.com/>.
|
||
|
||
Go to the section **Volumes -> Volumes**:
|
||
|
||

|
||
|
||
Click **Create Volume**.
|
||
|
||
The following window should appear:
|
||
|
||

|
||
|
||
In it provide the **Volume Name** of your choice.
|
||
|
||
Choose the **Type** of your volume - SSD or HDD.
|
||
|
||
Enter the size of your volume in gigabytes.
|
||
|
||
When you’re done, click **Create Volume**.
|
||
|
||
You should now see the volume you just created. In our case it is called **volume-small**:
|
||
|
||

|
||
|
||
Step 2: Attach the Volume to VM[🔗](#step-2-attach-the-volume-to-vm "Permalink to this headline")
|
||
------------------------------------------------------------------------------------------------
|
||
|
||
Now that you have created your volume, you can use it as storage for one of your VMs. To do that, attach the volume to a VM.
|
||
|
||
In the **Actions** menu for that volume select the option **Manage Attachments**:
|
||
|
||

|
||
|
||
You should now see the following window:
|
||
|
||

|
||
|
||
Select the virtual machine to which the volume should be attached:
|
||
|
||

|
||
|
||
Click **Attach Volume**.
|
||
|
||
Your volume should now be attached to the VM:
|
||
|
||

|
||
|
||
Step 3: Partition the Volume[🔗](#step-3-partition-the-volume "Permalink to this headline")
|
||
------------------------------------------------------------------------------------------
|
||
|
||
It is time to access your virtual machine to prepare the volume for data storage.
|
||
|
||
Connect to your virtual machine using SSH or the web console.
|
||
|
||
Execute the following command to make sure that the volume has been attached:
|
||
|
||
```
|
||
lsblk
|
||
|
||
```
|
||
|
||
You should see the output similar to this:
|
||
|
||

|
||
|
||
In this example, the attached volume that was previously called **volume-small** is represented by the device file **sdb**. Its size is 100 GB. Memorize the name of the *device file* representing the drive you attached or write it somewhere down - it will be needed later during starting **fdisk**.
|
||
|
||
In order to be able to use the volume as storage, you will need to use **fdisk** to create a partition table.
|
||
|
||
Start **fdisk** (replace **sdb** with the name of the device file provided to you previously by the **lsblk** command):
|
||
|
||
```
|
||
sudo fdisk /dev/sdb
|
||
|
||
```
|
||
|
||
You should now see the following prompt:
|
||
|
||
```
|
||
Command (m for help):
|
||
|
||
```
|
||
|
||
Answer with **n** and press Enter. A series of prompts similar to the ones below will appear on screen - keep pressing Enter on your keyboard to accept the default values.
|
||
|
||
```
|
||
Partition type
|
||
p primary (0 primary, 0 extended, 4 free)
|
||
e extended (container for logical partitions)
|
||
Select (default p):
|
||
|
||
Using default response p.
|
||
Partition number (1-4, default 1):
|
||
First sector (2048-209715199, default 2048):
|
||
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):
|
||
|
||
```
|
||
|
||
You should now see the confirmation similar to this:
|
||
|
||
```
|
||
Created a new partition 1 of type 'Linux' and of size 100 GiB.
|
||
|
||
```
|
||
|
||
After it you will see the following prompt again:
|
||
|
||
```
|
||
Command (m for help):
|
||
|
||
```
|
||
|
||
This time, answer with **w**. You will see the following message:
|
||
|
||
```
|
||
The partition table has been altered.
|
||
Calling ioctl() to re-read partition table.
|
||
Syncing disks.
|
||
|
||
```
|
||
|
||
Execute the following command again to confirm that the partition was created successfully:
|
||
|
||
```
|
||
lsblk
|
||
|
||
```
|
||
|
||
The device file of the new partition should have the same name as the device file of the drive followed by the **1** digit. In this case, it will be **sdb1**. Memorize or write it somewhere down - it will be needed later during creation of the file system.
|
||
|
||

|
||
|
||
Step 5: Create the File System[🔗](#step-5-create-the-file-system "Permalink to this headline")
|
||
----------------------------------------------------------------------------------------------
|
||
|
||
In order to save data on this volume, create **ext4** filesystem on it. **ext4** is arguably the most popular filesystem on Linux distributions.
|
||
|
||
It can be created by executing the following command:
|
||
|
||
```
|
||
sudo mkfs.ext4 /dev/sdb1
|
||
|
||
```
|
||
|
||
Replace **sdb1** with the name of the device file of the partition provided to you previously by the **lsblk** command.
|
||
|
||
This process should take less than a minute.
|
||
|
||
Step 6: Create the mount point[🔗](#step-6-create-the-mount-point "Permalink to this headline")
|
||
----------------------------------------------------------------------------------------------
|
||
|
||
You need to specify the location in the directory structure from which you will access the data stored on that volume. In Linux it is typically done in the **/etc/fstab** config file.
|
||
|
||
Below are the instructions for the **nano** text editor. If you prefer to use different software, please modify them accordingly.
|
||
|
||
Install **nano** if you haven’t already:
|
||
|
||
```
|
||
sudo apt install nano
|
||
|
||
```
|
||
|
||
Open the **/etc/fstab** file using **nano**:
|
||
|
||
```
|
||
sudo nano /etc/fstab
|
||
|
||
```
|
||
|
||
Add the below line to the end of that file. Remember to replace **sdb1** with the name of the device file of your partition (it was provided to you previously be the **lsblk** command) and **/my\_volume** with the directory in which you want to mount it - the mounting point.
|
||
|
||
```
|
||
/dev/sdb1 /my_volume ext4 defaults 0 1
|
||
|
||
```
|
||
|
||

|
||
|
||
To save that file in **nano**, use the following combination of keys: CTRL+X, Y, Enter.
|
||
|
||
Warning
|
||
|
||
Unless you know what you’re doing, you should not modify the lines which you already found in the **/etc/fstab** file. This file contains important information. Some or all of it might be required for the startup of the operating system.
|
||
|
||
Next, create a new or use an existing directory to use as your mounting point. If you need to create it anew, the command would be:
|
||
|
||
```
|
||
sudo mkdir /my_volume
|
||
|
||
```
|
||
|
||
Mount the volume to your system (replace **/my\_volume** with your mount point):
|
||
|
||
```
|
||
sudo mount /my_volume
|
||
|
||
```
|
||
|
||
To check whether it was successfully mounted, execute:
|
||
|
||
```
|
||
df -h
|
||
|
||
```
|
||
|
||
The output should look like this:
|
||
|
||

|
||
|
||
The volume is owned by **root**, so **eouser** does not have access without **sudo**. To make it accessible to **eouser**, execute this command:
|
||
|
||
```
|
||
sudo chown eouser:eouser /my_volume
|
||
|
||
```
|
||
|
||
If you want everybody to have access to that directory (and you don’t care about security at all), use the following command:
|
||
|
||
```
|
||
sudo chmod 777 /my_volume
|
||
|
||
```
|
||
|
||
During the next boot of your virtual machine, the volume should be mounted automatically.
|
||
|
||
What To Do Next[🔗](#what-to-do-next "Permalink to this headline")
|
||
-----------------------------------------------------------------
|
||
|
||
You have successfully created a volume and prepared it for use on a Linux virtual machine.
|
||
|
||
You can now copy files to your new volume. If you want to move the data, attach the volume to a different machine. |