New Disk Linux Ubuntu

Add New Disk in Linux / Ubuntu

Adding a new disk to a Linux PC can be a great way to expand storage capacity and improve performance.

We’ll go over the procedures for adding a new disk to a Linux machine in this post.

Physically install the new disk

Installing the disk physically is the first step in adding a new disk to a Linux computer.

This may involves opening up the computer case, connecting the disk to the power supply and the motherboard, and securing the disk in place with screws. Make sure to switch off the computer and remove all wires before installing the new disk.

Verify the new disk is recognized by the system

Once the new disk is installed, you’ll need to verify that the system recognizes it. To do this, you can use the dmesg command to view the system log messages. This will show any errors or messages related to the new disk.

sudo dmesg | grep -i 'sd'

This command will display information about all SCSI or SATA devices connected to the system, including the new disk. In the output, look for lines that contain the name of the new disk (e.g. /dev/sdb).

Once the disk is physically installed, we need to identify it in the Linux system.

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 46.8G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 419.1G 0 part /home
sdb 8:16 0 1.8T 0 disk

In the example above, we can see that there are two disks: sda and sdb. The new disk is sdb, which has a size of 1.8TB.

Partition the new disk

The next step in adding a new disk to a Linux machine is to partition the disk. This involves dividing the disk into one or more logical sections that can be formatted and used for storing data.

When partitioning the new disk, you can choose from various partitioning schemes, such as MBR or GPT. It’s recommended to use GPT as it can support disks larger than 2 TB.

To create a new partition using the fdisk utility, you can use the following command:

sudo fdisk /dev/sdb

This will launch the fdisk utility and allow you to create a new partition. Make sure to specify the partition type (e.g. Linux file system), the partition size, and the partition number.

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-3907029167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029167, default 3907029167):

Once we have created the partition, we need to save and exit fdisk by typing the following commands:

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Format the new partition

Once the new partition is created, you’ll need to format it with a file system. This involves setting up the necessary data structures on the partition so that it can be used for storing data.

Use the mkfs command to format the new partition with a file system. For instance, you can run the following command to format the partition using the ext4 file system:

sudo mkfs.ext4 /dev/sdb1

This will create a new file system on the partition and make it ready for use.

Mount the new partition

Once the new partition has been formatted, you must mount it before the system and users may access it. In order to do this, a directory in the file system hierarchy must be linked to the partition.

When mounting the new partition, you can choose any directory as the mount point. We can use a directory under the /mnt directory, as this is the location for mounting file systems.

To mount the new partition, you can use the following command:

sudo mkdir /mnt/newdisk
sudo mount /dev/sdb1 /mnt/newdisk

This will mount the new partition at the /mnt/newdisk mount point.

Make the new disk mount automatically at boot (optionally)

The new partition won’t automatically mount when the system starts up by default. We must add a line to the /etc/fstab file so that the new partition will start up automatically.

sudo nano /etc/fstab

In this file, we can add a new line that specifies the file system type, the device name, the mount point, and the mount options. For example:

/dev/sdb1 /mnt/newdisk ext4 defaults 0 2

The “defaults” option specifies the default mount options for the file system. The “0 2” at the end of the line specifies the order in which the file system should be checked by fsck at boot time.

Test the new disk

It’s a good idea to test the new disk after installation and configuration to make sure everything is operating as it should. On the new drive, you can make a test file to check that it can be read and written to.

Change the ownership of the mounted directory using the following command

sudo chown -R <username>:<username> /mnt/newdisk

Replace <username> with the username of the current user. You can find more detailed info in article:

Ubuntu Hardware Permissions: How to Set Ownership of Drive or Partition (Internal & External Hard Disks)

Conclusion

Adding a new disk to a Linux PC can be a great way to expand storage capacity and improve performance. By following the steps outlined in this article, you can easily add a new disk to your Linux PC and make it ready for use.

Just be sure to follow best practices for partitioning, formatting, and mounting the disk, and test it thoroughly before putting it into use. By doing so, you can ensure that your new disk works seamlessly with your Linux system and provides the optimal performance and reliability you need.