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
🐧 Как смонтировать устройство на Linux
Команда mount – это команда, используемая в Linux для подключенных файловых систем и дисков, а команда umount используется для отключения (размонтирования) любых подключенных файловых систем или устройств.
В этом руководстве мы научимся монтировать (подключать) диск в Linux с файловой системой EXT Linux, FAT или NTFS с помощью команды mount.
Мы можем использовать ту же команду для подключения USB-накопителя и ISO-образа.
Как в Linux, так и в UNIX-подобных операционных системах мы можем использовать команду mount / umount для подключения / отключения устройств.
Список установленных файловых систем и дисков Linux
Чтобы отобразить все подключенные в настоящее время файловые системы, мы наберем:
$ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=491472k,nr_inodes=122868,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=100904k,mode=755) /dev/sda1 on / type ext4 (rw,relatime,data=ordered) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) .
По умолчанию выходные данные будут включать все файловые системы, включая виртуальные, такие как cgroup, sysfs и другие.
Каждая строка содержит информацию об имени устройства, каталоге, к которому подключено устройство, типе файловой системы и опциях монтирования.
Чтобы перечислить только определенные типы файловых систем, мы будем использовать опцию -t:
$ mount -t ext4 /dev/sda1 on / type ext4 (rw,relatime,data=ordered)
В списке только файловая система Linux ext4 и обычно отображаются наши диски Linux.
Вы можете использовать fdisk, чтобы иметь представление о том, какие у вас Linux-разделы и устройства, например:
$ sudo fdisk -l Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x817e2210 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 20971486 20969439 10G 83 Linux Disk /dev/sdb: 10 MiB, 10485760 bytes, 20480 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
$ sudo fdisk -l Disk /dev/sda: 223.58 GiB, 240057409536 bytes, 468862128 sectors Disk model: TS240GSSD220S Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 7AA5C627-6B3A-4500-91B2-757F762207CF Device Start End Sectors Size Type /dev/sda1 2048 411647 409600 200M EFI System /dev/sda2 411648 2508799 2097152 1G Linux filesystem /dev/sda3 2508800 468860927 466352128 222.4G Linux LVM Disk /dev/mapper/fedora_localhost--live-root: 70 GiB, 75161927680 bytes, 146800640 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/fedora_localhost--live-swap: 7.84 GiB, 8401190912 bytes, 16408576 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/fedora_localhost--live-home: 144.56 GiB, 155206025216 bytes, 303136768 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 1.88 GiB, 1998585856 bytes, 3903488 sectors Disk model: DataTraveler 2.0 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x00000000 Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2048 3903487 3901440 1.9G c W95 FAT32 (LBA)