How to mount a partitions in Linux
In Linux, you must mount a disk or partition to a folder, called a mount point, to access its data. This makes the filesystem on the disk available for reading and writing. Mounting is required to use any disk or partition with the system. You can mount disks and partitions manually as needed or configure them to mount automatically at startup by editing the /etc/fstab file, you can mount using the disk’s device name, label, or UUID. Knowing how to mount disks in Linux is crucial for accessing and managing your storage devices. This guide explains the process for manual and automatic mounting.
Steps to mount a partition in Linux
1. To check the mounted partitions, use the command
# df -h
2. List the partitions using the fdisk -l commands to identify the hard drive you want to mount.
# fdisk -l
Looking at the output in the screenshot above, we have two hard disks added to the test system and we will mount the disk. /dev/vdb
To determine the filesystem type of the disk or partition.
# blkid /dev/vdb
3. Create a data folder to mount /dev/vdb into
# mkdir -p /data
4. Format disk /dev/vdb in ext4
# mkfs.ext4 /dev/vdb
5. Add to fstab file to automatically mount the system when reboot
# echo '/dev/vdb /data ext4 defaults 0 0' >> /etc/fstab
Or xfs:
# echo '/dev/vdb /data xfs defaults 0 0' >> /etc/fstab
6. Apply the changes by mounting all filesystems.
# mount -a
7. Confirm the disk or partition is mounted.
Conclusion
That’s all! In this article, we’ve explained how to mount a partition in Linux, format it with ext4 file system type, and mount it as a filesystem. For more information or to share any queries with us, use the feedback form below.