View the disks on your machine
fdisk is a tool used on Linux to manipulate disk partition tables. Using the
fdisk -l command, you can list all the disks and their partitions recognized by the system.
sd? in the
/dev directory is the physical disk. For example,
sda is the first disk read by the system, and
sdb is the second disk. In older kernels, the physical disk may be
/dev/hd? (IDE) or
/dev/sd? (SCSI) since there is no ATA support.
/dev/sda? is the partition on the physical disk
/dev/sda1 is the first partition on that disk.
Here the disk
/dev/sdb has not been mounted properly and it is the one that holds our data.
Creating a mount point
Before you can mount a disk, you must first create a mount point for it. A mount point is, in short, a directory that must already exist before you can mount it with the
mount command. After a successful mount, you can access the directory to access the contents of the corresponding disk. If the contents of the mount point existed before the mount, they will be temporarily invisible after the mount, and will become visible again when the mount is done.
For example, if I want to mount a disk on
/mnt/data, I need to create such an empty directory.
Determining the disk file system type
Before mounting the disk, you also need to determine the file system type of the disk (partition). Otherwise, selecting the wrong file system type when mounting may cause a series of strange phenomena. To do this, we need to execute the
parted -l command.
This shows that the target disk
/dev/sdb has the file system type
Mount the disk
At this point, we are able to mount the disk.
-t ext4 means that the target disk (partition) has the file system type
/dev/sdb is the disk (partition) to be mounted, and
/mnt/data is the target mount point.
Unmounting a disk
The opposite command to
umount. Note that it is
umount and not
unmount - there is no
When unmounting, the argument given to
umount can be either the mount point or the name of the disk (partition). In this case, the following two operations are equivalent.
If the disk you want to mount is being read or written by another process, Linux will prompt
device is busy. In this case, you can run the
umount -l command and let Linux unmount the disk when no other processes are reading or writing to it. Alternatively, you can use the
ps command to see which processes are using the disk and then dispose of them properly before unmounting.