Adding an extra hard disk to your Ubuntu machine involves physically installing the drive, identifying its device name using terminal commands like
lsblk, creating a partition table and filesystem, mounting it to a specific directory, and finally updating the
/etc/fstab file to ensure the system automatically mounts the drive at every boot.
Physical Installation and Hardware Verification
Before touching any software configurations, you must ensure the hardware is correctly seated in your system. Power down your computer completely and unplug the power cable to avoid electrical shorts or damage to components. If you are working with a desktop tower, open the case and locate an available SATA data port on your motherboard and a free SATA power connector from your power supply unit. For M.2 NVMe drives, identify the appropriate slot on the motherboard, remove the existing screw if necessary, insert the drive at a 30-degree angle, and secure it with the provided standoff and screw.
Once the physical connection is established, reconnect the power and boot into your Ubuntu system. It is crucial to verify that the operating system recognizes the new hardware before proceeding with configuration. You can do this by opening a terminal window and running the
lsblk command. This utility lists all block devices currently attached to your system. Look for a new entry that matches the capacity of your newly installed drive. Typically, internal drives appear as
sda,
sdb, etc., while NVMe drives appear as
nvme0n1. Do not proceed until you have positively identified the correct device identifier, as mistaking a system drive for the new one can result in catastrophic data loss.
For those interested in optimizing other aspects of their Ubuntu experience after expanding storage, such as monitoring system resources, you might find our guide on
Customize Linux Sensors: 3 Outputs to Try on Ubuntu 24.04 helpful for keeping an eye on your system's health.
Partitioning the New Drive
With the drive identified, the next step is to prepare it for use by creating a partition table and a filesystem. The standard tool for this in Linux is
fdisk or
parted. Using
sudo fdisk /dev/sdX (replace
sdX with your actual device identifier), you enter an interactive menu. First, create a new partition table by typing
o to create a new empty DOS partition table or
g for a GPT table, which is recommended for modern drives larger than 2TB.
Next, create a new primary partition by typing
n, accepting the default partition number and first sector, and pressing Enter for the last sector to use the entire disk. Change the partition type to Linux filesystem by typing
t and selecting the appropriate code (usually
83 for Linux). Finally, write the changes to the disk by typing
w. This action commits the partition table to the disk. If you prefer a graphical interface, you can use
gnome-disks via the application menu, select the drive, click the menu icon, choose "Format Disk," and then add a new partition.
Formatting the Filesystem
After partitioning, the drive exists but contains no filesystem. You must format it so the operating system can read and write data. The most common filesystems for Ubuntu are ext4 and xfs. To format the new partition as ext4, use the command
sudo mkfs.ext4 /dev/sdX1, replacing
X1 with your partition number. This process will take a few moments depending on the size of the drive. Alternatively, if you prefer xfs, use
sudo mkfs.xfs /dev/sdX1. Ext4 is generally the default choice for general-purpose Linux systems due to its stability and widespread support, while xfs offers better performance for large files and parallel I/O operations.
Mounting the Drive
A formatted drive must be mounted to a directory in the filesystem hierarchy to be accessible. Create a mount point directory using
sudo mkdir -p /mnt/data. Then, mount the drive temporarily with
sudo mount /dev/sdX1 /mnt/data. Verify the mount was successful by running
df -h, which should show your new drive listed under the specified mount point. To test write permissions, you can create a test file with
sudo touch /mnt/data/testfile and then delete it.
However, this manual mount will disappear upon reboot. To make the mount persistent, you need to edit the
/etc/fstab file. Open the file with a text editor like
sudo nano /etc/fstab. Add a line at the end with the following format:
/dev/sdX1 /mnt/data ext4 defaults 0 2. The
defaults option applies standard mount options. Save the file and exit. You can verify the fstab entry by running
sudo mount -a, which attempts to mount all filesystems described in fstab. If no errors occur, your drive is now permanently configured to mount at boot.
For users who frequently switch between different hardware setups or virtual environments, understanding how to manage kernel parameters can be useful. While this guide focuses on storage, you may also want to explore topics like
Booting Linux Kernels on Multiple VGA Adaptors with Ubuntu 22.04 to 24.04 to ensure your system remains stable across various configurations.
Frequently Asked Questions
How do I find the UUID of my new hard disk?
You can find the UUID by running the command
sudo blkid /dev/sdX1. This will output the unique identifier string along with the device path, which you can use in
/etc/fstab instead of the device name for more reliable mounting.
Why is my new hard disk not showing up in lsblk?
If the drive does not appear, check the physical connections, ensuring both data and power cables are securely attached. Additionally, verify that the BIOS/UEFI settings recognize the drive; if it is not detected there, the operating system cannot see it either.
Can I use NTFS format for my external Ubuntu drive?
Yes, you can format the drive as NTFS using
mkfs.ntfs, which allows easy sharing with Windows machines. However, you must install the
ntfs-3g package on Ubuntu to ensure full read-write support and proper handling of permissions.
What happens if I accidentally format the wrong drive?
Formatting overwrites the partition table and filesystem metadata, making data recovery difficult. Always double-check the device identifier in
lsblk by comparing sizes before running any formatting commands to prevent accidental data loss on your system drive.
How do I change the ownership of the mounted drive?
By default, the root user owns the mounted directory. To allow your regular user account access, run
sudo chown -R $USER:$USER /mnt/data. This recursively changes the owner and group of all files and directories within the mount point to your current user.