When you add a new physical disk to a Linux system, you need to format, partition, and mount it before use. Here’s a step-by-step guide:
✅ Summary of Commands
Task | Command |
---|---|
Check available disks | lsblk or fdisk -l |
Open fdisk |
sudo fdisk /dev/sdb |
Create partition | n → p → w in fdisk |
Format partition | sudo mkfs.ext4 /dev/sdb1 |
Create mount point | sudo mkdir /mnt/newdisk |
Mount disk | sudo mount /dev/sdb1 /mnt/newdisk |
Auto-mount (permanent) | Add entry in /etc/fstab |
Step 1: Identify the New Disk
After attaching a new disk, check if the system recognizes it:
or
🔹 Look for a device like /dev/sdb
(assuming it’s the new disk).
If the disk is not detected, refresh the disk list:
or
Step 2: Create a New Partition
Use fdisk
to create a partition:
Inside fdisk
:
- Press
n
→ Create a new partition. - Press
p
→ Select Primary partition. - Choose the partition number (default:
1
). - Specify the size (e.g.,
+20G
for 20GB). - Press
w
→ Save changes.
Verify the partition:
Now, you should see /dev/sdb1
.
Step 3: Format the New Partition
Format the partition with a filesystem (e.g., ext4
):
For XFS:
Step 4: Create a Mount Point
Choose a directory where you want to mount the disk:
Step 5: Mount the New Disk
Manually mount the partition:
Verify:
Step 6: Auto-Mount on Reboot (Persistent Mount)
To make the mount permanent, add an entry in /etc/fstab
:
🔹 Note the UUID, then edit /etc/fstab
:
Add this line at the end:
Save and exit. Apply changes:
Step 7: Set Permissions (Optional)
If needed, change ownership:
or set permissions: