15 - mount file systems. Mount command

Lecture



In previous lectures, the topic of mounting file systems has been touched several times. Today (and in the next lecture) we will discuss this issue in more detail. In modern distributions, file systems are mounted in most cases automatically. When you insert a USB flash drive into a USB connector on a computer, a directory with the name of a USB flash drive appears in the / media directory and you can immediately work with the device (read write files). Previously (before the udev subsystem appeared), before working with a flash drive (and any other block device), you had to perform a mount operation. When a flash drive is connected (we will use a flash drive as an example I mean any block device) a physical device appears in the system (in the / dev directory ) with which you can work as a block device. For example, read information using the dd command . But we need to get access to the file system of this device, and not to the device itself, and therefore we need to perform a mount operation.

There are two main components in the mount: a physical device or a physical device partition with a specific file system (then WHAT we mount) and a mount point (then WHERE we mount). The mount point is a regular directory anywhere on the system that will be the parent of the file system of the device being mounted. A catalog can be either empty (as a rule) or with information. If you mount into a directory with information, then the previous contents of the directory will be replaced with the contents of the file system of the device being mounted, but only for the duration of the mount. It is very important to understand and remember. As soon as you unmount the directory, the information that was in it before mounting will become available again. But this is a special case. All the same, in most cases, mounted in empty directories.

To mount is used com *** and mount . Most often this comma *** is used in the form mount -t type device dir , where after the -t switch the type of file system to be mounted is specified, then the device to be mounted (device) and then the directory (mount point - dir). For example, there is a flash drive - the device / dev / sdc , it has a partition / dev / sdc1 . You need to mount the partition - / dev / sdc1 - the formatted area, and not the physical device / dev / sdc . A com *** and mount for this case would look like this: mount -t vfat / dev / sdc1 / media / fleshka . The fleshka (mount point) directory must exist and if it is not there, then you need to create it com *** th mkdir or select another - existing directory. Since the flash drive was formatted in FAT32 , the file system type vfat was used . If you were mounting Windows ntfs partitions , then you should specify the ntfs file system. All types of supported file systems can be viewed in man mount .

Unmounting the file system is done with the command umount mount point | the device . From our example with a flash drive umount / media / fleshka or umount / dev / sdc1 . Com *** and umount will not be able to unmount the device if it is occupied by any program. For example, if you go to a directory on a mounted CD-ROM disk in one console and then try to execute the *** command from umount in another console, you will get an error:

igor @ adm-ubuntu: ~ / linux $ umount / media / cdrom0
umount: / media / cdrom0: device is busy.
(In some cases useful information about processes that use
the device is found by lsof (8) or fuser (1))

A com *** and lsof / media / cdrom0 will show which files are open from the / media / cdrom0 directory and by whom:

igor @ adm-ubuntu: ~ / linux $ lsof / media / cdrom0
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
bash 4908 igor cwd DIR 11.0 2048 1664 / media / cdrom0
less 19323 igor cwd DIR 11.0 2048 1664 / media / cdrom0
less 19323 igor 4r REG 11.0 32 1669 /media/cdrom0/config.txt

As you can see there really are open files and directories. To properly unmount the file system, you must close all open files and exit all directories or execute the *** file with umount with the -f key - umount -f / media / cdrom0 .

In this regard, the following situation is often encountered in novice linux users. The CD is inserted into the CD drive and work is being done on the disk files. The user then presses the drive button to eject the disc and nothing happens. Some even overload the computer because they do not understand what's the matter. But the point is that the disk cannot be removed until it is unmounted, and it cannot be unmounted because files are opened from it (it is used). One has only to close all files to exit all the directories and the drive will “give up” the disk when you press the eject button. If the disk is not removed, then you need to execute a com *** at umount for the disk and then press the eject button.

To see which file systems are already mounted in the system, you can execute a com *** on the mount with no parameters or execute a com *** on df -a . You can also view the contents of the / etc / mtab file . Com *** and mount when mounting a new file system adds a line to this file with information about the system being added. And com *** and umount, respectively, deletes the line relating to the unmounted partition.

I want to note that the mount / umount commands do not make any changes in the course of their work with device file systems and cannot damage them. Crashes most often occur as a result of abnormal attempts to unmount the file system, for example, pressing the reset button of the system unit. Try to avoid this action and apply it only in the most extreme cases. If the command line is available, before rebooting the computer using the reset button, execute the *** command in sync . This comma *** tells the kernel that it is necessary to immediately write down all the information stored in the buffer memory to the corresponding physical devices. This will reduce the risk of losing information.

Com *** and mount can mount not only devices, but also files. For this, a device such as / dev / loop is used . As a rule, there are several similar block pseudo-devices in the system:

igor @ adm-ubuntu: ~ / linux $ ls -l / dev / loop *
brw-rw—- 1 root disk 7, 0 2009-11-16 11:05 / dev / loop0
brw-rw—- 1 root disk 7, 1 2009-11-16 11:05 / dev / loop1
brw-rw—- 1 root disk 7, 2 2009-11-16 11:05 / dev / loop2
brw-rw—- 1 root disk 7, 3 2009-11-16 11:05 / dev / loop3
brw-rw—- 1 root disk 7, 4 2009-11-16 11:05 / dev / loop4
brw-rw—- 1 root disk 7, 5 2009-11-16 11:05 / dev / loop5
brw-rw—- 1 root disk 7, 6 2009-11-16 11:05 / dev / loop6
brw-rw—- 1 root disk 7, 7 2009-11-16 11:05 / dev / loop7

Why do we need to mount files? The most obvious example is when we have an iso disk image. Since the file cannot be directly mounted to the directory, they proceed as follows: mount the file to the block device / dev / loop , and then the block device / dev / loop is mounted to the mount point. To do this, the *** at mount must be executed with the -o key through which to transfer the loop parameter:

igor @ adm-ubuntu: ~ / linux $ sudo mount -o loop /home/igor/downloads/Ubuntu_DocsPack_9.04.2.iso / home / igor / linux / docpack /
igor @ adm-ubuntu: ~ / linux $ ls ./docpack/
Document html Jurnal_FullCircle.tar.gz Jurnal_OpenSource.tar.gz Ubuntu_Docs.tar.gz
Jurnal_BlenderEmpire.tar.gz Jurnal_LGT.tar.gz readme.txt Video_Lesson.tar.gz

Thus, we have mounted the Ubuntu_DocsPack_9.04.2.iso file and can now access it as a disk.

In conclusion of this lecture I want to show someone *** that will show us all sections of all block devices of the system. We will consider this com *** u in more detail later. To look at all the partitions that are in the system, type fdisk -l at *** on behalf of the superuser:

igor @ ubuntu: ~ $ sudo fdisk -l

Disk / dev / sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors / track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd4b146b8

Device Zagr Start End Blocks Id System
/ dev / sda1 * 1 2304 18506848+ 7 HPFS / NTFS
/ dev / sda2 2305 2472 1349460 e W95 FAT16 (LBA)
/ dev / sda3 2473 10263 62581207+ 7 HPFS / NTFS
/ dev / sda4 10264 30401 161758485 f W95 ext. (Lba)
/ dev / sda5 10264 12826 20587266 83 Linux
/ dev / sda6 12827 12947 971901 82 Linux swap / Solaris
/ dev / sda7 12948 18184 42066171 7 HPFS / NTFS
/ dev / sda8 18185 27967 78581916 7 HPFS / NTFS
/ dev / sda9 27968 30401 19551073+ 7 HPFS / NTFS

Disk / dev / sdb: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors / track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xb292b292

Device Zagr Start End Blocks Id System
/ dev / sdb1 1,460 37431418+ 83 Linux
/ dev / sdb2 4661 4865 1646662+ 5 Advanced
/ dev / sdb5 4661 4850 1526143+ 82 Linux swap / Solaris
/ dev / sdb6 4851 4865 120456 83 Linux

Disk / dev / sdc: 4016 MB, 4016046080 bytes
90 heads, 25 sectors / track, 3486 cylinders
Units = cylinders of 2250 * 512 = 1152000 bytes
Disk identifier: 0 × 00000000

Device Zagr Start End Blocks Id System
/ dev / sdc1 4 3487 3917824 b W95 FAT32

This com *** is good because it shows not only the name of the partition, but also the file system of the partition. For example, the / dev / sdc1 partition file system is FAT32 .


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

LINUX operating system

Terms: LINUX operating system