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 disk or partition in Linux:
Open the terminal.
Identify the disk or partition you want to mount.
$ lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 55.4M 1 loop /snap/core18/1944loop1 7:1 0 55.4M 1 loop /snap/core18/1932loop2 7:2 0 217.9M 1 loop /snap/gnome-3-34-1804/60loop3 7:3 0 219M 1 loop /snap/gnome-3-34-1804/66loop4 7:4 0 64.8M 1 loop /snap/gtk-common-themes/1514loop5 7:5 0 51M 1 loop /snap/snap-store/518loop6 7:6 0 62.1M 1 loop /snap/gtk-common-themes/1506loop7 7:7 0 51M 1 loop /snap/snap-store/498loop8 7:8 0 31.1M 1 loop /snap/snapd/10707loop9 7:9 0 31.1M 1 loop /snap/snapd/10492sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 513M 0 part /boot/efi└─sda3 8:3 0 19.5G 0 part /sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part sr0 11:0 1 1024M 0 rom
Determine the filesystem type of the disk or partition.
$ blkid /dev/sdb1/dev/sdb1: UUID="ccab0f8d-3b5b-4189-9da3-23c49159c318" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c088a647-01"
Create a directory for the mount point if it does not exist.
$ mkdir disk
Temporarily mount the disk or partition.
$ sudo mount -t ext4 /dev/sdb1 disk[sudo] password for user:
Replace ext4 with the actual filesystem type if different.
Verify that the disk or partition is mounted.
$ df -hFilesystem Size Used Avail Use% Mounted ontmpfs 391M 1.8M 389M 1% /run/dev/sda3 20G 7.1G 12G 39% /tmpfs 2.0G 0 2.0G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup/dev/sda2 512M 7.8M 505M 2% /boot/efitmpfs 391M 112K 391M 1% /run/user/1000/dev/sdb1 20G 45M 19G 1% /home/user/disk
Unmount the previously mounted drive.
$ sudo umount /dev/sdb1
To mount the disk automatically at startup, edit the /etc/fstab file.
$ sudo vi /etc/fstab
Add an entry in /etc/fstab for the disk or partition.
/dev/sdb1 /home/user/disk ext4 defaults 0 0
Apply the changes by mounting all filesystems.
$ sudo mount -a
Confirm the disk or partition is mounted.
$ df -hFilesystem Size Used Avail Use% Mounted ontmpfs 391M 1.8M 389M 1% /run/dev/sda3 20G 7.1G 12G 39% /tmpfs 2.0G 0 2.0G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup/dev/sda2 512M 7.8M 505M 2% /boot/efitmpfs 391M 112K 391M 1% /run/user/1000/dev/sdb1 20G 45M 19G 1% /home/user/disk
Author: Mohd Shakir Zakaria
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.