Whether you’re a beginner or experienced system administrator, knowing how to format and mount a new disk in Linux is an essential skill. This tutorial will guide you step by step through the complete process, from disk identification to permanent mounting.
I tested this tutorial on a Debian virtual machine and encountered no particular issues. The commands presented should work on most modern Linux distributions.
1. Identify the New Disk
Start by identifying the new disk in the system:
fdisk -l
This command will display all connected disks. The new disk will typically be /dev/sdb for the second SATA disk.
2. Create a New Partition
To create a new partition on the disk:
fdisk /dev/sdb
Then follow these steps in the fdisk interface:
- Type ‘n’ to create a new partition
- Choose ‘p’ for primary partition
- Select ‘1’ as the partition number
- Accept the default values for first and last sector (use all space)
- Type ‘w’ to write changes and exit
3. Format the Partition
Format the new partition in ext4:
mkfs.ext4 /dev/sdb1
4. Create the Mount Point
Create a directory that will serve as the mount point:
mkdir /data
5. Configure Automatic Mounting
There are two methods to configure automatic disk mounting:
Method 1: Using UUID (Recommended)
Get the disk’s UUID:
blkid
Edit the /etc/fstab file and add the line:
UUID=your-uuid /data ext4 defaults 0 0
Method 2: Using Device Name
Alternatively, edit /etc/fstab and add:
/dev/sdb1 /data ext4 defaults 0 0
6. Test the Mount
To test the configuration without rebooting:
mount -a
Verify that the mounting is effective:
mount
Congratulations! You have successfully formatted and mounted your new disk. The disk will now automatically mount at system startup, and you can start using it to store your data.