How to mount disk and partition in Linux
To use the data stored on a disk or partition in Linux, you need to mount it to a folder or mount point. After it’s mounted, you can explore the filesystem and read or write files and folders.
You can choose to manually mount disks and partitions whenever necessary, or you can set them to mount automatically when your system starts by creating an entry in the /etc/fstab file. You can mount the disk or partition using its device name, label, or UUID.
Steps to mount a disk or partition in Linux:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 55.4M 1 loop /snap/core18/1944 loop1 7:1 0 55.4M 1 loop /snap/core18/1932 loop2 7:2 0 217.9M 1 loop /snap/gnome-3-34-1804/60 loop3 7:3 0 219M 1 loop /snap/gnome-3-34-1804/66 loop4 7:4 0 64.8M 1 loop /snap/gtk-common-themes/1514 loop5 7:5 0 51M 1 loop /snap/snap-store/518 loop6 7:6 0 62.1M 1 loop /snap/gtk-common-themes/1506 loop7 7:7 0 51M 1 loop /snap/snap-store/498 loop8 7:8 0 31.1M 1 loop /snap/snapd/10707 loop9 7:9 0 31.1M 1 loop /snap/snapd/10492 sda 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
$ blkid /dev/sdb1 /dev/sdb1: UUID="ccab0f8d-3b5b-4189-9da3-23c49159c318" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c088a647-01"
$ sudo mount -t ext4 /dev/sdb1 disk [sudo] password for user:
$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 391M 1.8M 389M 1% /run /dev/sda3 20G 7.1G 12G 39% / tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup /dev/sda2 512M 7.8M 505M 2% /boot/efi tmpfs 391M 112K 391M 1% /run/user/1000 /dev/sdb1 20G 45M 19G 1% /home/user/disk
/dev/sdb1 /home/user/disk ext4 defaults 0 0
$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 391M 1.8M 389M 1% /run /dev/sda3 20G 7.1G 12G 39% / tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup /dev/sda2 512M 7.8M 505M 2% /boot/efi tmpfs 391M 112K 391M 1% /run/user/1000 /dev/sdb1 20G 45M 19G 1% /home/user/disk
Author: Mohd Shakir Zakaria
Mohd Shakir Zakaria, a proficient cloud architect, is deeply rooted in development, entrepreneurship, and open-source advocacy. As the founder of Simplified Guide, he combines these passions to help others navigate the intricate world of computing. His expertise simplifies complex tech concepts, making them accessible to everyone. Discuss the article:
Comment anonymously. Login not required.
Introduction To Filesystems
Data on a computer, as you may know, is stored in binary as a series of 1s and 0s. The way these are stored on a device and their structure is called the «filesystem». In Linux devices are referenced in /dev. Data is not actually stored on a device so you cannot access this data by going into /dev, this is because it is stored inside the filesystem on the device so you need to access these filesystems somehow. Accessing such filesystems is called «mounting» them, and in Linux (like any UNIX system) you can mount filesystems into any directory, that is, make the files stored in that filesystem accessible when you go into a certain directory. These directories are called the «mount points» of a filesystem. In other systems this is done differently. For example in Windows there is no distinction made between a device and the filesystem on it, and the user is restricted to mounting a device’s filesystem in a top-level volume which is automatically assigned a letter such as C:, D:, etc. and the files inside these filesystems are accessed inside each volume’s root such as «C:\», «D:\», «E:\», etc. (remember, Windows uses back slashes instead of the more common forward slashes you find in Linux)
Linux only has one top-level volume which is kept in the system’s RAM. It too has a root, but since there is only one top-level volume there is no point giving it a label (as there is nothing to distinguish it from) which means that all files in a Linux system are accessed via simply «/». This top-level volume is kept in RAM, but the files themselves are stored on various drives (some real and some fake) (also, files may be kept in the RAM before they are written to disc for reasons which I will explain further down). A Linux system needs only one «physical» (real) filesystem, which is that of /. However, it is very useful to keep some directories inside / separate. For example, users’ files are often kept on a separate hard drive partition and mounted on /home. Also, the «fake» filesystems can make it much easier to administer and run a Linux system. For example the folder «/proc» does not actually contain any data. In fact, it is «fake» since it shows various files containing useful pieces of information to do with your system, however none of these files actually exist until they are opened, in which case the system does a quick check to find the required information, displays it and pretends that it was there all along.
These system filesystems are all automatically set up, but it is creating custom filesystems and using removable media which allow for some interesting uses of mounting.
What Can Be Mounted
The most common thing to be mounted is a hard drive partition. Hard drives are kept in /dev and have different names depending on what type of drive they are. IDE/ATA drives are labelled as /dev/hda, /dev/hdb, /dev/hdc and /dev/hdd (since a PC’s IDE interfaces can only handle 4 devices at a time). Note that these can be devices such as IDE/ATA CDROMS, Compact Flash to IDE converters, and some special floppy drives (although they tend to appear mainly in laptops). For SCSI devices the labels are /dev/sda, /dev/sdb, /dev/sdc, /dev/sdd, /dev/sde, /dev/sdf, /dev/sdg, /dev/sdh and /dev/sdi (since a SCSI chain can contain up to nine devices). Other types of drive, such as USB, SATA, etc. are mapped to these SCSI devices by Linux. Therefore SATA and USB drives are labelled as /dev/sdX where X is a letter, starting at «a».
Since these are literally the devices you can issue a command such as:
If /dev/hdc is a CD drive then it will eject.
In the case of hard drives, there is another abstraction. A hard drive (and many devices such as USB «sticks» which act like hard drives) can be partitioned to allow many filesystems to be stored on them. This means that the filesystems themselves are accessible via the partition labels, such as /dev/hda1 (the first partition on /dev/hda). This means that we finally know about something we can mount, a partition, since it contains a filesystem.
Another physical filesystem which can be mounted is the ISO9660 filesystem used on CDROMs. Since there is only ever one CD in a CD drive there is no point creating /dev/hdc1 (where /dev/hdc is a CDROM drive) since there is only one filesystem on it. That means that you can mount CD drive devices explicitly, so if /dev/hdc is a CDROM drive then it is possible to mount /dev/hdc if there is a disc in it.
Floppy disks only contain one filesystem, and are labeled as /dev/fd0 for the first drive, /dev/fd1 for the second drive, etc. So now we know three things which can be mounted.
Devices like USB sticks are treated like hard drives (so /dev/sda1, for example, may contain a filesystem) and so are iPods (although I think the main data on an iPod is stored on the second partition)
Mounting is not restricted to physical devices. If you have a filesystem «image» (which IS a filesystem, whether an exact copy of an existing filesystem, or a filesystem created specifically for that file) then you can mount that through the use of a fake device called the «loopback device»
How To Mount/Unmount Filesystems
Unmounting
Firstly I will tell you how to unmount any filesystem you mount after trying these commands. Unmounting is done through the «umount» command, which can be given a device or a mount point so:
sudo umount /mnt sudo umount /dev/hda1
Would both unmount the filesystem on /dev/hda1 if it is mounted on /mnt.
Remember that a filesystem cannot be in use when it is unmounted, otherwise umount will give an error. If you know it is safe to unmount a filesystem you can use:
Note that files are often stored temporarily in the RAM to prevent filesystem fragmentation and speed up access times for slow devices like floppy disks. For this reason you should always unmount filesystems before you unplug or eject the device or you may find that your files have not actually been written to your device yet.
Mounting
Is responsible for mounting filesystems. The syntax for this command is quite simple (remember that mount must be run with super user privileges to change the system) so:
Will mount the filesystem on /dev/sda1 (which may be a USB drive, a SATA drive or a SCSI drive) into the folder /mnt. That means that going into /mnt will show you the filesystem which is on /dev/sda1.
Many options can be given to mount. A useful option is the «type» option, when automatic filesystem-type detection fails. An example would be:
sudo mount /dev/fd0 /floppy -t vfat
That command tells mount to put the filesystem on the first floppy disk into the folder /floppy, and tells it to treat the filesystem as a FAT filesystem. If the wrong type is given then mount will not mount the filesystem and you will be told of the error.
To mount a filesystem contained in a file using the loopback device the command would look like this
sudo mount Filesystem.img /home/user/MyFilesystem -o loop
To create a filesystem image you can either «dump» an existing filesystem into a file, for example by using the command:
dd if=/dev/hdc3 of=/home/user/Filesystem.img
Alternatively you can create an empty file by using:
dd if=/dev/zero of=/home/user/MyFilesystem.img bs=512 count=100000
And then creating a filesystem on this file as if it were a drive by using the command:
mkfs.ext2 -j MyFilesystem.img
Which will create an ext3 filesystem on the device (ext2 with a journal). Images created using either method can be mounted via the loopback device.
An interesting ability of mount is it’s ability to move specific parts of a filesystem around. For example:
sudo mount --bind /mnt/Files/Music /home/user/Music
Will let the folder «/mnt/Files/Music» also be accessible in /home/user/Music. If you wish to «move» a folder (no data is copied or removed, it is merely displayed in a different place) then use:
sudo mount --move /mnt/Files/Music /home/user/Music
Instead. This can come in handy, for example you may have your dual-boot Windows partition mounted in /windows. You can get easier access to your personal files by using:
sudo mount --bind "/windows/My Documents" "/home/user/Windows Documents"
For windows 98/95 users, and with:
sudo mount --bind "/windows/Documents and Settings/username/My Documents" "/home/username/Windows Documents"
Mount can mount filesystems which are accessed remotely using NFS (the Networked Files System) (Please complete this as I do not know how to use NFS)
Windows NTFS Disks
Permanently mount internal Windows NTFS disks. Install and use the NTFS Configuration Tool (external link) To get it go to the Ubuntu Software Center -> System Tools -> NTFS Configuration Tool -> Install
See Also
Mount (последним исправлял пользователь dhcp-108-170-137-89 2015-12-08 02:32:32)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details