Linux : Mounting Hard Disk using fdisk.

 How to Mount a Hard Drive at Boot in Ubuntu 22.04 - Format Swap - Tech  Tutorials

Adding an external hard disk to your Linux system can be useful for additional storage, backups, or data migration. This guide covers the step-by-step process to partition, format, and permanently mount an external hard disk on a Linux system.

Step 1: Identify the External Hard Disk

First, connect your external hard disk to your Linux machine and identify it using the following command:

df -kh

Alternatively, you can use:

lsblk

This will list all storage devices connected to your system.

Step 2: Partitioning the External Hard Disk

Use fdisk to partition the external drive. Replace /dev/sdb with the correct device name.

sudo fdisk /dev/sdb

Inside fdisk, follow these steps:

  • Press n to create a new partition.

  • Select p for a primary partition.

  • Choose a partition number (default is 1).

  • Specify the first and last sector (or press Enter to use the default values).

  • Press w to write the changes and exit.

Step 3: Formatting the Partition

Once partitioning is complete, format the new partition with an appropriate filesystem (e.g., ext4):

sudo mkfs.ext4 /dev/sdb1

Step 4: Creating a Mount Point

Create a directory where you will mount the external hard disk:

sudo mkdir /shubham

Step 5: Mounting the Partition

To temporarily mount the disk, use:

sudo mount /dev/sdb1 /shubham

Verify the mount using:

df -kh

Step 6: Making the Mount Permanent

To ensure the disk mounts automatically on reboot, edit the /etc/fstab file:

sudo nano /etc/fstab

Add the following line at the end:

/dev/sdb1   /shubham   ext4   defaults   0   0
 

Step 7: Testing the Permanent Mount

Reboot your system and check if the mount persists:

df -kh

If the disk is not mounted, manually mount it using:

sudo mount -a

Conclusion

By following these steps, you have successfully mounted an external hard disk permanently on your Linux system. This method ensures that your external disk is always available, even after a system restart.



=======================================================================
Thank you, check out more blogs for such information..!
For any queries,feel free to reach out me on shubhammore07007@gmail.com

Comments

Popular posts from this blog

Nginx : Setting Up Nginx with Load Balancing

Nginx : Virtual hosting using Location directives

Terraform project with AWS to build infra within seconds! (Web Ec2 with eIP)