The basic usage of mount/umount command in Linux and the automatic mounting method of boot _linux

Source: Internet
Author: User
Tags mkdir

This article introduces the basic usage of the Mount/umount command in Linux and automatic mount, the following methods are as follows:

The Mount command format is as follows:

Format: Mount [-parameters] [device name] [Mount Point]

Among the commonly used parameters are:

-A all file systems that are class-installed in the/etc/fstab file. -
F camouflage mount, make check device and directory appearance, but does not really mount file system.
-N does not record the installation in the/etc/mtab file.
-R Speaking file system installed as read-only.
-V Displays installation information in detail.
-W installs the file system as writable, which is the default for the command. -
T < file system type > Specifies the file system type of the device, which
is common: ext2 is a commonly used file system for Linux

mdom-do fat, which is FAT16

Vfatwindow98 commonly used FAT32

NF Network File system

Io9660cd-rom CD standard file system

ntfwindownt/2000/xp file System

Auto automatically detect file system The

-o< option > Specifies the options for mounting the file system, and some can also be written to the/etc/ftab. Commonly used are:

default uses the defaults for all options (auto, Nouer, RW, UID)

Auto/noauto allow/disallow installation with –A option

Dev/nodev pair/ Do not interpret special devices on file system

exec/noexec allow/disallow execution of binary code

uid/nouid confirm/do not confirm UID and GID bit

Uer/nouer allow/disallow general user Mount

Codepage=xxx code page

iocharet=xxx character set

ro Mount RW in read-

write mode mount

remount Reinstall installed file system

loop mount "Swing Device" "and Io Mirrored files"

It is important to note that the mount point must be an existing directory, this directory can not be empty, but the previous contents of this directory will not be available, Umount will return to normal later. When using multiple-o parameters,-O is used only once, separated by a half-width comma between parameters:

 
 

For example, to mount the D disk under Windows file system as FAT32, generally under Linux this partition corresponds to/dev/hda5, depending on the specific partition situation will be different, here to Hda5 to illustrate:

# MKDIR/MNT/HDA5//Create hda5 directory as mount point, location and directory name customizable//

# MOUNT-T Vfat/dev/hda5/mnt/hda5 

In general, Linux automatically detects partitioned file systems, unless you specify them, the-t vfat can be omitted.

 
 

This allows you to enter the/MNT/HDA5 directory to access resources in the partition.

1. Why the mount on the partition after the Chinese file will not show the question mark/garbled?

The display question mark indicates that there is no recognizable Chinese font in your system, please install the Chinese font first. Make sure your system is well displayed in Chinese. The display of garbled code is usually the default file system encoding used by mount and the actual coding inconsistency of files in the file system. To display Chinese files normally, mount requires the codepage and Iocharset options in the-o parameter. CODEPAGE specifies the code page for the file system, the Simplified Chinese code is 936;iocharset the specified character set, and the Simplified Chinese is generally cp936 or gb2312.

 
 

Generally speaking, mount–o iocharset=cp936/dev/hda5/mnt/hda5 can solve the problem.

If you have a problem after this, try UTF-8 encoding:

# Mount–o Iocharset=utf8/dev/hda5/mnt/hda5

2. Why does the partition ordinary user not write after mount up?

Mount when added –o umask=000 can:

# Mount–o umask=000, Iocharset=cp936/dev/hda5/mnt/hda5

3. Why does the file in the partition after the mount go into short file names?

This is the cause of the file system hangs wrong, will FAT32 mount into FAT16 When this happens, first umount, and then use –t vfat again to solve the problem of mount.

# mount–t Vat/dev/hda5/mnt/hda5

4. How to mount U disk and MP3?

If the computer does not have other SCSI devices and USB peripherals, the device path for the inserted USB drive is/dev/sda1, using the command:

# mkdir/mnt/u

# mount/dev/sda1/mnt/u 

can be mounted.

5. Can I use the ISO file directly?

Yes, that's the option to mount that allows free virtual optical drives under Linux, and the specific usage is:

# mkdir/mnt/iso

# Mount–o Loop linux.iso/mnt/iso 

Of course, mount point/mnt/iso is also read-only after mounting.

6. How to boot automatically mount partition?

It is really cumbersome to enter such a long command per mount, as long as the partition information is written to the/etc/fstab file to enable automatic mounting of the system, such as adding the following line for the/dev/hda5 automatic mount:

/dev/hda5/mnt/hda5 vfat defaults,iocharset=cp936, rw 0 0

7. How do I mount the samba partition?

# mkdir/mnt/share

# mount-t Smbfs-o username=root,password=abc,codepage=936,iocharset=gb2312//192.168.1.100/ Share/mnt/share 

If the Chinese display is not normal, try UTF-8 encoding. Of course, can be written into the fstab to implement automatic mount.

8. What does Mount--bind mean?

Mount--bind is to mount the contents of one directory to another directory, using the

 
 

This command makes it especially convenient for FTP to share a directory. If you want to cancel the Mount command:

 # Mount--move Olddir newdir

Can.

If the Mount--bind also wants to write to Fstab, the format is as follows:

Olddir newdir None bind 0 0

9. Why Umount Show device busy When you are old?

This is because the program is accessing the device, the easiest way is to let access to the device after the program exit and then Umount. Maybe sometimes the user does not clear what is the program in the access device, if the user is not in a hurry to umount, you can use:

 
 

To uninstall the device. The option –l is not umount immediately, but umount after the directory is idle. You can also use the command PS aux to see the device to occupy the program PID, and then use the command kill to kill the process of seizing the device, so umount very relieved.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Boot mount and/etc/fstab format

When we mount the disk, in addition to the use of the disk code (/DEV/HDXX) can also directly use the disk label as a mounted disk mount point Oh! Basically, that's the/etc/fstab file Setup, Label as the basis for disk mount, so there are good and bad:

Advantages: Regardless of the hard drive code changes, whether you plug the hard disk in that IDE interface (IDE1 or IDE2 or master or slave, etc.), because the system is through the Label, so the disk plug in that interface will not have an impact.

Disadvantage: If two hard drives, just two hard disk Label has duplicate, that's miserable ~ because the system will not be able to determine the disk split slot is the correct!

Boot Mount/etc/fstab and/etc/mtab:

Some limitations of system mounts:

The root directory/must be mounted, and must be mounted prior to other mount point.

Other mount point must be an established directory, optionally specified, but must adhere to the required System directory architecture principles

All mount point can only be mounted once at the same time.

All partition can only be mounted once at the same time.

If you uninstall, you must first move the working directory outside of Mount point (and its subdirectories).

[Root@linux ~]# cat/etc/fstab
# Device mount_point filesystem parameters dump fsck
label=/    /     ext3   Defaults  1   1 (mounted with header name)
/dev/hda5   /home   ext3   defaults  1  2
/dev/hda3   swap   swap   defaults  0   0
/dev/hdc/media/cdrom   auto   pamconsole,exec, Noauto,managed 0 0
/dev/devpts    /dev/pts devpts gid=5,mode=620 0 0
/dev/shm  /dev/shm   TMPFS   defaults  0  0
/dev/proc/   proc   proc   defaults  0   0
/dev/sys   /sys   sysfs   defaults  0   0

In fact, this/etc/fstab is that we use mount to mount a device to the system of a mount point, the required instructions, the content will be written to/etc/fstab inside, and let the system boot on the active mount. So what are the parameters required to mount the command? Not just "device code, mount point, File system category, parameters" and so on, and our/etc/fstab added two additional functions, namely, the backup instruction dump execution or not, and whether the power-on for FSCK scan disk.

The previous 4 are very familiar with each file system there are many parameters can be added, such as Chinese-encoded iocharset=big5,codepage=950 and so on, of course, there are many common parameters, specific can see the details of the mount, Specifically, the latter 2: Dump and fsck.

Can be dump backup directive function:

In Linux, you can use the dump command to make a backup of your system. And the dump instruction will be for the/etc/fstab set value, to choose whether to be the partition to backup the action! 0 means do not do dump backup, 1 represents the action to be dump. 2 also represents a dump backup action, however, the partition is less important than 1.

Whether to check the sector with fsck:

During the boot process, the system preset will check with fsck to see if the filesystem in our partition is complete (clean). However, some filesystem are not required to be tested, such as virtual memory swap, or special file systems such as/proc and/sys, and so on. So, in this field, we can set whether to test the filesystem with fsck. 0 is not to test, 1 is to test, 2 is to be tested, but 1 will be more early test! In general, the root directory is set to 1, and the other filesystem to be tested are set to 2.

Generally speaking, when we edit the/etc/fstab, in order to avoid possible errors, usually will be mount-a (simulate boot automatic mount operation) This instruction to test to see it! This is a very important test action!

/etc/fstab is the setup file at boot time, however, the actual filesystem mount is recorded in the/etc/mtab and/proc/mounts of the two files. Every time we change filesystem's mount, we change the two files at the same time. However, in case of the data you entered in the/etc/fstab error, resulting in the failure to successfully boot, and into the single maintenance mode, when the/but read only state, of course, you can not modify the/etc/fstab, also can not update/etc/mtab, it does not matter, can benefit Use this trick:

[Root@linux ~]# mount-n-o REMOUNT,RW/

Plus-n does not update/etc/mtab, plus-o provides additional parameter settings. Use this action, hehe! You can read and write, then you will be able to update the contents of the file.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.