Detailed Linux mount command: mount the file system outside of Linux

Linux after all storage devices must be mounted to use, including hard disk, U disk and CD-ROM (swap partition is a system called directly, there is no need to mount). However, when you install the hard disk partition has been mounted, and it will be automatically mounted each time the system is started, there is no need to manually participation. But to use the CD-ROM and U disk in a Linux system, you need to learn some mount command.

Mount refers to the hard disk partition (eg partition / dev / sdb1, in fact, refers to the file system) and mount point (already established an empty directory) linking process. It should be noted that the mount point must be a directory, an empty directory and should in principle as the mount point.

If you do not use an empty directory as a mount point, use has catalog data (such as / etc / directory) as the mount point, what will happen then? Very simple, the original data in the / etc / directory to find less, and in / etc / directory can only see the new partition. This is because the / etc / directory was not originally a separate partition, but the / partition subdirectories, so the data / etc / directory is actually stored in the block / partition.

But now to the / etc / directory separate partition, and again / etc / directory to save the data will be saved in the block / etc / directory of the new partition, then of course, the original data can not be seen. If you want access to the raw data, you can only uninstall the new partition.
The basic format of the mount command
basic format mount command is as follows:
[the root @ localhost ~] # mount [-l]
# query system has been mounted in the apparatus, -l label name displayed
[root @ localhost ~] # mount - a
# according to the configuration file / etc / fstab content, automatically mount
[root @ localhost ~] # mount [-t file system] [-L label name] [-o specific options] device file name mount point

Options:
-t file systems: the file system type is added to specify the type of mount, it can be ext3, ext4, iso9660 and other file systems;
-L label name: Specifies the label mount partitions instead of installing equipment to mount the file name ;
-o special options: you can specify mount additional options, such as read and write permissions, synchronous / asynchronous, etc. If not specified, the default values to take effect. Specific special options see Table 1;

Table 1 mount command to mount special options
Option Description
atime / noatime update the access time / not update the access time. When the partition file access, whether to update the file access time, the default is to update
async / sync asynchronous / synchronous, asynchronous by default
auto / noauto automatic / manual. As mount -a command is executed, will automatically install the / etc / fstab file contents mounted, the default is automatically
defaults to define a default value, equivalent to rw, suid, dev, exec, auto, nouser, async seven options
exec / noexec execution / non-execution. Set whether execution of the executable file in the file system, the default is to allow
remount remount already mounted file system, generally used to specify special permissions to modify
rw / ro write / read-only. When the file system is mounted, whether it has read and write permissions, the default is rw
the SUID / the nosuid with / without SetUID rights. Set the file system is owned and SetGID SetUID authority, the default is to have
user / nouser allow / do not allow ordinary users to mount. Set the file system whether to allow ordinary users to mount, the default is not allowed, only root can mount the partition
usrquota written on behalf of the file system supports disk quotas, default does not support
grpquota written on behalf of the file system disk quota support group, not supported by default
[Example 1]
[root @ localhost ~] # Mount
# View system already mounted file systems, note that there is a virtual file system
/ dev / sda3 on / type ext4 (rw)
proc ON / proc type proc (RW)
sysfe ON / SYS type the sysfs (RW)
the devpts ON / dev / PTS type the devpts (RW, GID =. 5, MODE = 620.)
tmpfs ON / dev / SHM type tmpfs (RW)
/ dev / sda1 ON / the Boot of the type ext4 (rw)
none ON / proc / SYS / Fe / binfmt_misc of the type binfmt_misc (rw)
sunrpc ON / var / lib / NFE / rpc_pipefs of the type rpc_pipefs (rw)
# command of results: the / dev / sda3 partition is mounted to / directory, the file system is ext4, is read and write permissions

[Example 2] modify special permissions.
[root @ localhost ~] # Mount
# we look to the / boot partition has been mounted, and it uses defaults option, then we remount the partition, and use #noexec permissions prohibit execution file is executed, and see what will case (be careful not to use / partition to do the experiment, otherwise the system would be unable to command execution of #)
... output omitted ...
/ dev / sda1 ON / the Boot of the type ext4 (rw)
... output omitted ...
[root @ localhost ~] # Mount remount -o, noexec / boot
# remount / boot partition, and use the noexec permissions
[root @ localhost SH] # cd / boot /
[root @ localhost the Boot] #vi hello.sh
# write a shell of it
#! / bin / bash
echo "the Hello !!"
[root @ localhost the Boot] # chmod 755 hello.sh
[root @ localhost the Boot] # / hello.sh.
-bash: ./ hello.sh: enough authority
# although given the hello.sh execute permission, but still can not perform
[root @ localhost the boot] # Mount -o remount, Exec / the boot
# remember to change it back, otherwise it will affect the system starts

If we do experiments to modify the special options, it is important to remember, but also need to modify; otherwise, the system is very prone to problems, but also can not find the source of the problem.

[Example 3] mountable partition.
[root @ localhost ~] # mkdir / mnt / disk1
# establish a mount point directory
[root @ localhost ~] # Mount / dev / sdb1 / mnt / disk1
# Mount partition

/ dev / sdb1 partition has not been divided. We are here only to see mount the partition of the way, very simple, do not even need to use "-text4" command specifies the file system, because the system is automatically detected.
Mount the CD
in the Windows CD-ROM if you want to use, just put the CD into the drive, click to use. But in addition to Linux, put the disc into the drive, and must use the correct order after the mount. Also remember that after using the disc can not be like Windows - like, pop-up drive to remove the disc directly, but must first uninstall to remove the CD (Windows does not as convenient, but this is only an operating habit, you get used to it).

Mount command as follows (of course, remember to put the disc in Linux):
[root @ localhost ~] # mkdir / mnt / cdrom /
# build mount point
[root @ localhost ~] # mount -t iso9660 / dev / cdrom / mnt / cdrom /
# mount the CD

CD-ROM file system is iso9660, but the file system can be omitted, the system will automatically detect the following command:
[root @ localhost ~] # Mount / dev / cdrom / mnt / cdrom /
# mount the CD. Two disc mount a command it
[the root @ localhost ~] # Mount
# view of the device already mounted
... output omitted ...
/ dev / SrO ON / mnt / ISO9660 CDROM type (RO)
# disc has been linked to uploaded, but mounted device file name is / dev / sr0

We already know is to mount the CD-ROM device file and mount point connected. Mount point / mnt / cdrom is an empty directory we created by hand, I personally used to build the mount point in / mnt / directory, because when we learn that there is no Linux / media / directory, if everyone is willing and can establishment / media / cdrom as the mount point, as long as it has established an empty directory can be used as a mount point. Then / dev / cdrom is the CD-ROM device file name, but note that / dev / cdrom is just a soft link. Command is as follows:
[the root @ localhost ~] #ll / dev / CDROM
lrwxrwxrwx the root the root. 3. 1. 1 dated 31 01: 13 / dev / cdrom -> sr0

/ dev / cdrom source file is / dev / sr0. / dev / sr0 drive is a real device file name, on behalf of the drive SCSI interface or SATA interface, so just see when the query command to mount CD-ROM device file is / dev / sr0. In other words, the mount command can also be written like this:
[root @ localhost ~] # Mount / dev / SR0 / mnt / cdrom /

In fact, drive the real device file name is stored in the / proc / sys / dev / cdrom / info file, so you can query the disc by looking at this document real device file name, the command is as follows:
[root @ localhost ~] # CAT / proc / SYS / dev / CDROM / info
the CD-Information a ROM, LD: 3.20 2003/12/17 cdrom.c
Drive name: SR0
... ... omitted output portion

Mount U disk
to mount U disk and mount the CD approach is the same, but the device file name of the disc is fixed (/ dev / sr0 or / dev / cdrom), but the device file name U disk is inserted U disk automatically assigned. Because U disk using the hard disk device file name, and inserted on each server hard disk partitions and the number of ways that are not the same, so U disk requires a separate detection device number and distribution, and so as not to produce hard disk device file name conflict. U disk device file name is automatically assigned, as long as we find out then mount it.

First U disk into Linux systems (Note: If a virtual machine, you need to first click of the mouse into the virtual machine and then insert U disk), then you can use the fdisk command to view the file name of the U disk. Command is as follows:
[the root @ localhost ~] # the fdisk -l
Disk / dev / SDA: 21.5GB, 21,474,836,480 bytes
# hard disk system
... output omitted ...
Disk / dev / SDB: 8022 MB, 8,022,654,976 bytes
# U disk that is identified , the size of 8GB
94 Heads, 14 sectors / Track, 11906 Cylinders
Units = Cylinders of 1316 * 512 = 673 792 bytes
Sector size (Logical / PHYSICAL): 512 bytes / 512 bytes
the I / O size (Minimum / Optimal): 512 bytes / bytes 512
disk identifier: 0x00000000
device Id the Boot the Start End Blocks the system
/ dev / sdb1. 1 B 11907 7,834,608 the FAT32 W95
# dispensing system to a U-device file name

View U disk to the device file name, the next step is to create a mount point. Command is as follows:
[the root @ localhost ~] # mkdir / mnt / USB

Then is the mount, the mount command is as follows:
[the root @ localhost ~] # Mount -t vfat / dev / sdb1 / mnt / USB /
mount U disk. Because Windows partition, so is the vfat file system format
[root @ localhost ~] # cd / mnt / the USB /
# mount point to visit U disk data
[root @ localhost the USB] # LS
# output is garbled
# reason garbled because different encoding format

The reason garbled, because the U disk is stored in Windows data, and inconsistencies in the Chinese Windows and Linux encoding format, just specify the correct encoding format when mounted can solve the garbage problem, command as follows:
[the root @ localhost ~] # -t vfat -o Mount UTF8 iocharset = / dev / sdb1 / mnt / USB /
# U-mount, designated Chinese coding format. 8-UTF
[the root @ localhost ~] # CD / mnt / the USB /
[root @ localhost the USB] LS #
1111111 annual summary and schedule .xls ZsyqlHL7osKSPBoGshZBr6.mp4 agreement
December 21 .doc Kung Hei Fat Choy (fixed) .mp4 New year's VCR (fixed) .mp4
# can correctly view the Chinese

Because our Linux installation is used in the UTF-8 encoding format, so let U disk can also be specified when mounted as UTF-8 encoding format, to display correctly.
[root @ localhost ~] # echo $ LANG
zh_CN.UTF-8
# look at the Linux default encoding format

Note, Linux by default does not support NTFS file system, so the default is not to mount mobile hard disk NTFS format. To get Linux support mobile hard disk, there are three main methods:
recompile the kernel, adding ntfs module, and then install ntfs module can;
do not compile their own kernel, but download precompiled kernel, can be installed directly;
install the NTFS file third-party plug-in system can also support the NTFS file system;

Published 160 original articles · won 97 Like · views 160 000 +

Guess you like

Origin blog.csdn.net/zyy1659949090/article/details/88176635