Learn how to add additional disks to the Ubuntu server

In this step-by-step guide, we'll walk you through the process of adding a new disk to your Ubuntu server, partitioning it, formatting it, and mounting it. We'll also cover common issues you might encounter along the way and how to troubleshoot them. By the end of this guide, you'll have a better understanding of how to manage storage on your Ubuntu server and be able to add additional disks with ease.

first, run the lsblk command to see how many disks you have attached in my case two sda and sdb

Attach a new disk to an Azure Ubuntu VM, you can follow these steps

  1. Open the Azure portal and navigate to your Ubuntu VM.

  2. Click on the "Disks" option under the "Settings" section of the left-hand menu.

  3. Click on the "Add data disk" button and fill in the required details, such as disk name, size, and storage account.

  4. Click on "Create" to create the new disk and attach it to the VM.

After adding the disk verify by running lsblk

Some Description on the above lsblk result

sda disk, which contains the root file system because it is mounted on /

sdc (NEW ADDED DISK) is a 10GB disk that is currently not being used by the system. It is present as a disk device, but there is no partition on it, and it is not mounted to any directory. so we can not use it yet.

You can use the fdisk command or a similar partitioning tool to create one or more partitions on the sdc disk and then format and mount the partition(s) to a directory if you need to use the disk for storing data or backup, or anything.

let us see how we can use this disk to store our backup data.

Steps:

  1. Create a new partition, write changes, and exit fdisk

  2. Format the new partition with the file system

  3. Create a directory to mount the new disk to

  4. Mount the new disk to the /usama-backup disk directory

Create a new partition, write changes, and exit fdisk

# plese make sure to use your disk name 
sudo fdisk /dev/sdc

when you run fdisk command it will let take you interactive screen with a prompt, first I specify n (FOR NEW PARTITION OF SDC DISK)

Next, it will ask for the Partition type I provided P (PRIMARY)

then press enter to choose the default option

in the second last step of LAST SECTOR I specify +7G means I want to create a portion of 7G as sdc1

finally, let's verify with lsblk that a partition has been created in disk sdc as sdc1

Here is a cheat sheet for fdisk options when partitioning:

  1. m - Displays the help menu with a list of available commands.

  2. p - Prints the partition table.

  3. n - Creates a new partition.

  4. d - Deletes a partition.

  5. t - Changes the type of partition.

  6. w - Writes the partition table to disk and exits.

  7. q - Quits fdisk without saving any changes.

When creating a new partition (n command), the following options are available:

  1. p - Creates a primary partition.

  2. e - Creates an extended partition.

  3. l - Lists the partitions in the extended partition.

When changing the type of a partition (t command), you will be prompted to enter the hex code or alias for the desired partition type. Some common partition types include:

  1. 83 or Linux - Linux file system.

  2. 82 or Linux swap - Linux swap space.

  3. 8e or Linux LVM - Linux Logical Volume Manager.

When deleting a partition (d command), you will be prompted to enter the partition number to delete.

Remember to always double-check your changes before writing them to disk with the w command, and make sure to back up any important data before making any changes to your partition table.

Format the new partition with the file system

sudo mkfs -t ext4 /dev/sdc1

Here are some other filesystem types that can be created using the mkfs command on Linux:

  1. mkfs.ext2: creates an ext2 filesystem

  2. mkfs.ext3: creates an ext3 filesystem

  3. mkfs.xfs: creates an XFS filesystem

  4. mkfs.btrfs: creates a Btrfs filesystem

  5. mkfs.ntfs: creates an NTFS filesystem (requires ntfsprogs package)

  6. mkfs.fat: creates a FAT filesystem (supports FAT12, FAT16, and FAT32)

  7. mkfs.vfat: creates a VFAT filesystem (an extension of FAT16 and FAT32 with long file names)

Create a directory to mount the new disk to /mnt/usama-backup

let's create a file inside /usama-backup and mount our new disk sdc1

sudo mkdir /usama-backup
# Create a directory to mount the new disk to

sudo mount /dev/sdc1 /usama-backup
# Mount the new disk to the /usama-backup directory

in case you want to unmount

get out from the directory of mounted folder and run

umount /usama-backup
# or provide with the name you choose for you your additional disk

if you are getting the error

This error message typically means that a process or application is still using files or data on the device or partition you are trying to unmount, so the system cannot unmount it safely.

To resolve this issue, you need to identify which process or application is using the device and stop it before trying to unmount again. You can use the lsof command to list open files and processes that are using them.

Here's an example command to find the processes using the /usama-backup device

 sudo lsof +f -- /usama-backup

Once you have identified the process, you can try to stop it or close the file or data it is using. Once the process is stopped, you should be able to unmount the device using the umount command.

Did you find this article valuable?

Support Muhammad Usama by becoming a sponsor. Any amount is appreciated!