Basic usage of the mount and umount command in linux and the method of automatically mounting the boot

  • 2020-05-13 04:20:13
  • OfStack

This paper introduces the basic usage of the mount/umount command in linux and the automatic startup mount. The specific methods are as follows:

The mount command format is as follows:

Format: mount [- parameter] [device name] [mount point]

The commonly used parameters are:


-a  Installed in the /etc/fstab All file systems classed in a file. 
-f  camouflage mount , which looks like checking devices and directories without actually mounting the file system. 
-n  Do not record the installation in /etc/mtab  File. 
-r  Install file system as read-only. 
-v  Displays installation details. 
-w  Install the file system as writable by command default. 
-t < File system type >  Specify the file system type of the device. Common examples are: 
ext2 is linux Current file systems in common use 

mdoM-DO the fat , it is fat16

vfatwindow98 The commonly used fat32

nf Network file system 

io9660CD-ROM CD standard file system 

ntfwindowNT/2000/XP File system 

auto Automatic file system detection 

-o< options > Specifies options for mounting the file system, some of which can also be written to /etc/ftab In the. Common ones are: 

default Use the default values for all options ( auto , nouer , rw , uid ) 

auto/noauto allow / You are not allowed to use copyright a Option to install 

dev/nodev right / Does not interpret special devices on the file system 

exec/noexec allow / Not allowed to execute 2 Hexadecimal code 

uid/nouid confirm / Don't confirm uid and gid position 

uer/nouer allow / Don't allow 1 User mount 

codepage=XXX The code page 

iocharet=XXX Character set 

ro Mount as read-only 

rw Mount in read-write mode 

remount Reinstall the installed file system 

loop Mount "gyroscope" and" IO Mirror file" 

It is important to note that the mount point must be an existing directory. This directory may not be empty, but the previous contents in this directory will not be available after the mount. umount will return to normal after the mount. When multiple -o parameters are used, -o is used only once, and the parameters are separated by a half-angle comma:


# mount  � o remount,rw / 

For example, to mount D disk with FAT32 as the file system under windows, 1 generally speaking, this partition under Linux corresponds to /dev/hda5. It will vary according to the specific partition situation. Here, hda5 is taken as an example:


# mkdir /mnt/hda5 // create hda5 As a mount point, the location and directory name can be customized //

# mount -t vfat /dev/hda5 /mnt/hda5 

1 generally speaking, Linux will automatically probe the partition's file system, unless you specify it, -t vfat can be omitted.


# mount /dev/hda5 /mnt/hda5 

This allows you to go to /mnt/hda5 and access the resources in the partition.

1. Why can't Chinese files be displayed as question mark/garble after mount partition?

The display of the question mark indicates that there is no recognizable Chinese font in your system. Please install the Chinese font first. Make sure your system is ready to display Chinese. The appearance of garble 1 is caused by the default file system encoding used by mount and the actual file encoding in the file system. To properly display Chinese files, mount requires the codepage and iocharset options in the -o parameter. codepage specified file system code page, simplified Chinese Chinese code is 936; iocharset specified character set, simplified Chinese 1 for cp936 or gb2312.


# mount  � o iocharset=gb2312 codepage=936 /dev/hda5 /mnt/hda5 

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

If there are further questions after doing so, please try UTF-8 encoding:


# mount  � o iocharset=utf8 /dev/hda5 /mnt/hda5

2. Why can't normal users write after mount goes up?

When using mount, add the copyright with o umask=000:


# mount  � o umask=000, iocharset=cp936 /dev/hda5 /mnt/hda5

3. Why do the files in the partition on mount become short file names?

This is the reason why the file system is hung incorrectly. This will happen when FAT32 is mounted as FAT16. The problem can be solved by mounting umount first and t vfat again.


# 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 of the inserted U disk is /dev/sda1, using the command:


# mkdir /mnt/u

# mount /dev/sda1 /mnt/u 

Just mount it.

5. Can you use the iso file directly?

Yes, it is this 1 option of mount that makes Linux a free virtual drive.


# mkdir /mnt/iso

# mount  � o loop linux.iso /mnt/iso 

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

6. How to boot the partition automatically?

It is tedious to type such a long command every time you mount. If you write the partition information to /etc/fstab file, you can automatically mount the system. For example, you can add the following lines to the /dev/hda5 automatic mount:


# mount  � o remount,rw / 
0

7. How do I mount the samba partition?


# mount  � o remount,rw / 
1

If the Chinese display is abnormal, please try UTF-8. Of course, you can write to fstab for automatic mount.

8. What does mount --bind mean?

mount --bind mounts the contents of one directory to another directory


# mount  � o remount,rw / 
2

This command makes it especially convenient for your custom built FTP to share a directory. If you want to cancel mount with the command:


 # mount --move olddir newdir

Can.

If mount --bind also wants to write fstab, the format is as follows:


# mount  � o remount,rw / 
4

9. Why does umount always show device busy?

This is because a program is accessing the device, and the easiest way is to have the program accessing the device exit later. Sometimes the user may not be able to clear what program is actually accessing the device. If the user is not in a hurry to use umount, they can use:


# mount  � o remount,rw / 
5

To unload the device. Option, l, not umount immediately, but umount when the directory is free. You can also use the command ps aux to see the program PID that is occupying the device, and then use the command kill to kill the process that is occupying the device, so umount is very comfortable.

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

Boot mount and /etc/fstab format

When mounting a disk, in addition to using the disk code (/dev/hdxx), you can also directly use the label of the disk as the mount disk mount point. Basically, it is the /etc/fstab file Settings,Label as the basis for disk mount, which can be good or bad:

Advantages: no matter how the hard disk code is changed, no matter whether you plug the hard disk into the IDE interface (IDE1 or IDE2 or master or slave, etc.), since the system is through Label, the disk plugging into the interface will not be affected.

Cons: if two hard disks are inserted and the Label of the two disks are duplicated, that's a disaster! The system will not be able to tell which slot is correct!

Boot mount /etc/fstab and /etc/mtab:

1 limitations of system mount:

The root/must be mounted, and 1 must be mounted before the other mount point.

Other mount point must be an established directory and can be specified at will, subject to the required system directory architecture principles

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

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

To uninstall, you must first move the working directory outside mount point(and its subdirectories).


# mount  � o remount,rw / 
6

In fact, this /etc/fstab is to mount a device to a certain hardpoint of the system by using mount, and then write all the instructions to /etc/fstab, and then let system 1 mount actively after starting up. So what parameters do you need for an mount command? Instead of "device codes, hardpoints, file system categories, parameters" and so on, our /etc/fstab has added two additional functions, which are whether or not the backup instruction dump is executed, and whether or not to boot fsck to scan the disk.

The first four are already very familiar, and there are many parameters that can be added to each file system, such as iocharset=big5,codepage=950, etc., of course, there are many common parameters, you can see the detailed introduction of mount, dump and fsck.

Can be used by dump backup instruction:

In Linux, the dump directive can be used for system backup. The dump command selects whether or not to backup the partition at the set value of /etc/fstab. 0 means do not do dump backup, and 1 means do dump. 2 also means that you want to do an dump backup, but that partition is less important than 1.

Whether to check the sector with fsck:

During startup, the system will check whether the filesystem in our partition is complete (clean) by default with fsck. However, some filesystem do not need to be verified, such as virtual memory swap, or special file systems, such as /proc and /sys, etc. So, in this field, we can specify whether we want to verify the filesystem with fsck. Zero is not to be tested, one is to be tested, two is to be tested, but one is going to be tested earlier! Generally speaking, the root directory is set to 1, and all other filesystem to be tested are set to 2.

1 generally speaking, when we edit /etc/fstab, mount-a will be used to test it in order to avoid possible errors. This is an important test action!

/etc/fstab is the boot file, but the actual mount of filesystem is recorded in the files /etc/mtab and /proc/mounts. Every time we change the mount of filesystem, we change both files at the same time. However, due to the data error you entered in /etc/fstab, you cannot start the machine successfully and enter the single maintenance mode. At that time, the/read only is in the state of/read only. Of course, you cannot modify /etc/fstab, and you cannot update /etc/mtab.


# mount  � o remount,rw / 
7

Plus -n does not update /etc/mtab, plus -o provides additional parameter Settings. Use this 1 action, hehe hehe! Your/can then be read and written, and the file content can be updated naturally.


Related articles: