Что такое монтирование в линуксе

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.

Читайте также:  Open doc file on linux

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.

Читайте также:  Astra linux обновить java

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.

Читайте также:  Linux mint на слабый пк

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

Источник

Оцените статью
Adblock
detector