U disk mount (mount) and uninstall (umount) for Linux system operation

Foreword:

There is such a work scenario; Xiaobai is an operation and maintenance engineer who has just entered the workplace. Today, Xiaobai received an order from the leader and needs to go to the computer room to assist the third-party terminal manufacturer to test the transmission link in the isolation area. Xiaobai was a little panicked, he had never been to the computer room, and he didn't know what to do; he asked his colleagues for advice, and the colleagues told him not to be afraid, he was just going to make soy sauce. Then Xiaobai went to the computer room, met the third-party terminal manufacturer and asked me what to do? The third-party terminal manufacturer said: Help me get two files from the server. Xiaobai thought it was easy, and then plugged in the USB flash drive to prepare to copy files; however, after plugging in the USB flash drive, he found that the directory of the USB flash drive could not be found in the system! ! !

1. Why should the U disk be mounted before it can be used?

Because Linux treats all hardware devices as files, when using hardware devices such as optical drives, they must be mounted in the system, only in this way can Linux recognize them.

1. The /mnt directory stores manually mounted hardware;

2. The /media directory stores automatically mounted hardware (mount points are automatically created and deleted by the system)

3. /dev is not a device driver, but an interface for accessing external device files. For example, after inserting our U disk into the Linux system, use fdisk -l to check the partition, and the file is displayed as /dev/sda1.

Use the command fdisk -l to view the partition where the USB device is located

Through the above command, you can see that the U disk has been recognized by the system; but the problem comes again, obviously the system has recognized the U disk, so why can’t it be accessed directly, isn’t it already in the /dev/sdb1 directory ?

There are five types of files under the Linux system:

1. Ordinary files; starting with - symbol is an ordinary file; generally created by related applications, such as: cp tool, touch tool, etc.

[root@chaser ~]# ls -lh install.log

-rw-r–r– 1 root root 53K 03-16 08:54 install.log

2. Directory file; the directory starts with the letter d; it is created with commands such as mkdir and cp.

[root@chaser ~]# ls -lh

drwxr-xr-x 2 root root  4.0K 04-19 10:53 mydir

3. Character device or block device file; use mknode to create, generally do not need to manually create device files, because these files are associated with the kernel.

Device files start with the letter c. Such as serial devices such as cats.

[root@chaser~]# ls -la /dev/tty

crw-rw-rw- 1 root tty 5, 0 04-19 08:29 /dev/tty

Those starting with the letter b are block devices, such as hard disks, optical drives and other devices.

[root@chaser ~]# ls -la /dev/hda1

brw-r—– 1 root disk 3, 1 2006-04-19 /dev/hda1

4. Socket file; start with the letter s, this is enough to know that there is such a thing

5 Symbolic link files; start with | character,

[root@chaser ~]# ls -lh start.log

lrwxrwxrwx 1 root root 11 04-19 11:18 start.log -> install.log

According to the above quote, the Linux system is divided into five types of files; now you can look at the file attributes of /dev/sdb1.

It can be seen that the Linux system recognizes a block type file, and the block type Linux system cannot be accessed directly; if you want to access it, you must mount it to the file directory through the mount command for access.

 2. How to mount the U disk (mount)

1. The mount point must be a directory.

2. Mount on an existing directory, this directory may not be empty, but after mounting, the previous content in this directory will not be available, and umount will return to normal after umount.

3. The format of the file system used by CD-ROM, floppy disk, and other operating systems is different from that used by Linux. CD is ISO9660; floppy is fat16 or ext2; windows NT is fat16, NTFS; windows98 is fat16, fat32; windows2000 and windowsXP is fat16, fat32, NTFS. Before mounting, you need to know whether Linux supports the file system format to be mounted.

mount Basic mount usage

mount [-fnrsvw]  [-t vfstype] [-o options] device dir

parameter:

device indicates the device to be mounted,

dir represents the mount point

-t Specifies the file system type of the device.

Commonly used option descriptions are:    

(1) The earliest file system used by minix Linux.    

(2) Ext2 is the current common file system of Linux.     

(3)msdos MS-DOS 的 FAT。    

(4) vfat VFAT of Win85/98.    

(5) nfs network file system.    

(6) The standard file system of iso9660 CD-ROM disc.    

(7) ntfs Windows NT file system.    

(8) hpfs OS/2 file system. The file system of versions prior to Windows NT 3.51.    

(9) auto Automatically detect the file system.

Example 1: Mount the U disk of FAT32

mkdir /mnt/usbFAT32   --/mnt 目录下创建手动进行挂载的目录
fdisk -i              --查看挂载的设备信息(需要root用户进行查看)
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          72        3767    29681664    c  W95 FAT32 (LBA)
--一般情况下系统会自动检测对应的文件系统类型,所以可以不使用 -t vfat 指定文件系统类型
mount -t vfat /dev/sdb1 /mnt/usbFAT32 
df -h --查看设备挂载情况,如下即成功挂载。
/dev/sdb1              29G   16G   13G  55% /mnt/usbFAT32

Example 2: Mount NTFS mobile hard disk

mkdir /mnt/usbNTFS   --/mnt 目录下创建手动进行挂载的目录
fdisk -i              --查看挂载的设备信息(需要root用户进行查看)
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1      121601   976760001    7  HPFS/NTFS
mount /dev/sdb1 /mnt/usbNTFS --不指定文件系统类型的情况下
mount: you must specify the filesystem type --提示:你必须指定文件系统类型
mount -t ntfs /dev/sdb1 /mnt/usbNTFS --没有提示则ok
mount: unknown filesystem type 'ntfs'  --提示:‘ntfs’文件系统类型未知,需要自行安装ntfs-3g(工具运行在C++语言下,如不能编译则还需要安装 gcc-c++ 工具)
df -h --查看设备挂载情况,如下即成功挂载。
/dev/sdb1              123G   1G   122G  98% /mnt/usbNTFS

3. Uninstall

Uninstallation is relatively simple, just use the umount command to uninstall.

例如:
已经挂载的 /dev/sdb1              29G   16G   13G  55% /mnt/usbFAT32
umount /dev/sdb1    或者   umount /mnt/usbFAT32   都可以进行卸载

4. Automatic mount

Configure the /etc/fstab file to realize that linux will automatically mount the linux partition that needs to be mounted every time it is turned on.

# /etc/fstab
# Created by anaconda on Fri Oct 22 22:25:49 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
#》》》》》》》》》》》》  注意看这里 《《《《《《《《《《《《《《《《《《《《《《
#挂载的文件系统的设备名     挂载点    挂载的文件系统类型     挂载的选项,选项间用逗号分隔
/dev/sdb1             /mnt/usbFAT32      vfat        defaults,codepage=936,iocharset=cp936 0 0           
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/dev/mapper/vg_chaser-lv_root /                       ext4    defaults        1 1
UUID=81c96f40-5068-4ec7-9ecd-369ce041dd7e /boot                   ext4    defaults        1 2
/dev/mapper/vg_chaser-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_chaser-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

The parameter defaults actually contains a set of default parameters:

rw mount in read-write mode

suid enable user ID and group ID set bit dev can interpret characters or block devices on the file system exec executable binary files

auto mount automatically

nouser makes normal users unable to mount

async performs file system input and output operations in an asynchronous manner,

codepage=936 and iocharset=cp936 parameters to support Chinese file names.

The optical drive and floppy drive are not mounted automatically, and the parameter is set to noauto.

/dev/cdrom1 /mnt/cdrom1 udf, iso9660 noauto, owner, kudzu, ro 0 0

To mount files in ISO format, mount -loop -o iocharset=cp936 xxxxx.iso /mnt/iso

Hard disk partition introduction:

/dev/ This string is the directory name where all device files are located. Because partitions are on hard disks, and hard disks are devices, these files represent all possible partitions on /dev/.

The first two letters of the xx partition name indicate the type of device on which the partition resides. Usually hd (IDE disk) or sd (SCSI disk). The letter y identifies the device on which the partition resides.

For example, /dev/hda (first IDE disk) or /dev/sdb (second SCSI disk) N The last number represents the partition. The first four partitions (primary or extended) are numbered from 1 to 4. Logical partitions start at 5. For example, /dev/hda3 is the third primary or extended partition on the first IDE hard disk; /dev/sdb6 is the second logical partition on the second SCSI hard disk.


→ →Reference and summary record notes

Guess you like

Origin blog.csdn.net/weixin_40648849/article/details/124037307