Photo by Jainath Ponnala on Unsplash
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
Open the Azure portal and navigate to your Ubuntu VM.
Click on the "Disks" option under the "Settings" section of the left-hand menu.
Click on the "Add data disk" button and fill in the required details, such as disk name, size, and storage account.
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:
Create a new partition, write changes, and exit fdisk
Format the new partition with the file system
Create a directory to mount the new disk to
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:
m
- Displays the help menu with a list of available commands.p
- Prints the partition table.n
- Creates a new partition.d
- Deletes a partition.t
- Changes the type of partition.w
- Writes the partition table to disk and exits.q
- Quitsfdisk
without saving any changes.
When creating a new partition (n
command), the following options are available:
p
- Creates a primary partition.e
- Creates an extended partition.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:
83
orLinux
- Linux file system.82
orLinux swap
- Linux swap space.8e
orLinux 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:
mkfs.ext2
: creates an ext2 filesystemmkfs.ext3
: creates an ext3 filesystemmkfs.xfs
: creates an XFS filesystemmkfs.btrfs
: creates a Btrfs filesystemmkfs.ntfs
: creates an NTFS filesystem (requiresntfsprogs
package)mkfs.fat
: creates a FAT filesystem (supports FAT12, FAT16, and FAT32)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.