Linux Mount command details

Source: Internet
Author: User

In Windows, mounting usually refers to assigning a drive letter to a disk partition (including a virtualized disk partition. This operation can be performed through "disk management" in "Computer Management. Third-party software, such as disk partition management software and Virtual Disk software, is usually attached with the mounting function.

In a Linux operating system, mounting is a very important feature and is frequently used. A device (usually a storage device) is mounted to an existing Directory. (This directory may not be empty, but the contents in the directory will not be available after mounting .)

It should be understood that the Linux operating system regards all devices as files and integrates the resources of the entire computer into a large file directory. To access a file on a storage device, you must mount the partition where the file is located to an existing Directory, and then access the storage device by accessing this directory.

◆ Mount conditions:

1. the mount point must be a directory.

2. A partition is mounted to an existing Directory. The directory cannot be empty, but the contents in the directory are unavailable. This is also true for mounting file systems created by other operating systems.

◆ File System Format

It should be understood that the file system formats used by CD, floppy disk, and other operating systems are different from those used by Linux. The disk is iso9660; the disk is fat16 or ext2;

Windows NT is fat16 and NTFS;

Windows 98 is fat16 and FAT32;

Windows and Windows XP are fat16, FAT32, and NTFS.

Before mounting, check whether Linux supports the file system format to be mounted.

◆ Mount command

Run the mount command during mounting:

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

Common parameters include:

-T <file system type> specifies the file system type of the device,

Common examples: minix Linux's earliest File System

Ext2 common file systems in Linux

Msdos MS-DOS fat, is fat16

FAT32 commonly used in vfat Windows98

NFS Network File System

ISO CD-ROM CD standard file system

NTFS Windows NT 2000 File System

HPFs OS/2 File System

Auto automatically detects the File System

-O <option> specifies the option when the file system is mounted. Some of them are also available in/etc/fstab.

Commonly used codePage = xxx code page iocharset = xxx Character Set Ro is mounted in read-only mode

RW mounting nouser in read/write mode makes it impossible for a general user to mount a user so that a general user can mount a device

◆ Example

Remind me where you want to mount the file system, first create a directory.

For example, Windows 98 is installed in the hda1 partition, and the disk and disk need to be mounted on the computer.

# Mk/mnt/winc

# Mk/mnt/floppy

# Mk/mnt/CDROM

# Mount-T vfat/dev/hda1/mnt/winc

# Mount-T msdos/dev/fd0/mnt/floppy

# Mount-T iso9660/dev/CDROM/mnt/CDROM

Now you can access/mnt/winc and other directories to read and write these file systems.

Make sure that the last two lines of commands are correct. Make sure that the drive and the drive have disks.

◆ LINUX partition ID

Describes how partitions are identified in Linux,

Usually hdyn (IDE disk) or sdyn (SCSI disk ).

Y indicates the device where the partition is located.

For example,/dev/hda (the first IDE disk) or/dev/SDB (the second SCSI disk)

N indicates the Partition Number.

The first four partitions (primary or extended partitions) are arranged in numbers from 1 to 4. Logical partitions start from 5.

For example,/dev/hda3 is the third primary partition or extended partition on the first IDE hard disk;/dev/sdb6 is the second logical partition on the second SCSI hard disk.

◆ Chinese support

If your Windows 98 directory contains a Chinese file name, after mounting the file with the above command, a bunch of garbled characters are displayed.

This requires the codePage iocharset option in the-O parameter.

CodePage specifies the code page of the file system. The simplified Chinese code is 936;

Iocharset specifies the character set. cp936 or gb2312 is generally used for simplified Chinese.

When the mounted file system is not supported by Linux, Mount must report an error, for example, Windows NTFS file system.

You can re-compile the Linux kernel to obtain support for the file system or the next patch that supports NTFS.

◆ Automatic mounting

It is too cumbersome to run the mount command every time you access the Windows partition at startup,

We can configure Linux to mount the partitions we want to mount at startup, such as Windows partitions,

To automatically mount the file system.

There is a fstab file in the/etc directory, which lists the file systems automatically mounted when Linux is started.

My/etc/fstab file is as follows:

Label = // ext3 defaults 1 1

Label =/boot ext3 defaults 1 2 None

/Dev/PTS devpts gid = 5, mode = 620 0 0 none

/Proc defaults 0 0 none

/Dev/SHM tmpfs defaults 0 0

/Dev/hda8 swap defaults 0 0

/Dev/CDROM/mnt/cdrom udf, iso9660 noauto, owner, kudzu, RO 0 0

/Dev/fd0/mnt/Floppy auto noauto, owner, kudzu 0 0

/Dev/cdrom1/mnt/cdrom1 UDF, iso9660 noauto, owner, kudzu, RO 0 0

/Dev/hdb1/mnt/winc NTFS ults, codePage = 936, iocharset = cp936 0 0

/Dev/hda5/mnt/wind vfat defaults, codePage = 936, iocharset = cp936 0 0

/Dev/hda6/mnt/winf vfat defaults, codePage = 936, iocharset = cp936 0 0

In the/etc/fstab file,

The first column is the device name of the mounted file system,

The second column is the mount point,

The third column is the mounted file system type,

The fourth column is the mounting option,

The options are separated by commas.

In the last three lines, I manually added C, D, and f disks in windows,

Added the codePage = 936 and iocharset = cp936 parameters to support Chinese file names.

The defaults parameter actually contains a set of default parameters:

RW mounting SUID in read/write mode enable user ID and group ID setting bit Dev can interpret characters or block devices on the file system

Exec executable binary file auto mount nouser so that general users cannot mount

Async executes the input and output operations of the file system in non-synchronous Mode

You can see that in this list, the optical drive and the soft drive are not automatically mounted, and the parameter is set to noauto.

◆ Attaching a CD image file

Thanks to the huge advances in disk technology in recent years, new computer systems are equipped with large-capacity disk systems. In Windows, many people are used to making software and materials into disc image files and using virtual optical drives. This has many advantages: 1. It reduces the wear and tear of the optical drive; 2. It is not a problem that the hard disk capacity is huge to store dozens of disc image files, and it is very convenient to use as needed; iii. Hard Disk reading speed is much higher than the disk reading speed, and the CPU usage is greatly reduced. In fact, it is more convenient to create and use a CD image in a Linux system than in a Windows system. You do not have to borrow any third-party software package.
1. Create a CD image file from the CD. Put the CD in the optical drive and execute the following command.
# Cp/dev/CDROM/home/sunky/mydisk. ISO or
# Dd If =/dev/CDROM of =/home/sunky/mydisk. ISO
Note: You can execute any of the above commands to make the current CD in the optical drive into a CD image file/home/sunky/mydisk. ISO
2. Make the files and directories into a CD image file and execute the following command.
# Mkisofs-r-J-V mydisk-o/home/sunky/mydisk. ISO/home/sunky/mydir
Note: This command will make all the directories and files under the/home/sunky/mydir Directory into a CD image file/home/sunky/mydisk. ISO, and the disc volume is marked as mydisk.
3. Mount the disk image file)
# Mkdir/mnt/vcdrom
Note: create a directory for mount point)
# Mount-o loop-T iso9660/home/sunky/mydisk. ISO/mnt/vcdrom
Note: You can use/mnt/vcdrom to access all files in the disk image file mydisk. ISO.
◆ Mount a mobile hard drive

For Linux systems, mobile hard disks with USB interfaces are treated as SCSI devices. Before inserting a mobile hard disk, use fdisk-l or more/proc/partitions to view the system's hard disk and hard disk partition.
[Root at pldyrouter/] # fdisk-l
Disk/dev/SDA: 73 dot 4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sda1 1 4 32098 + de Dell Utility
/Dev/sda2*5 2554 20482875 7 HPFs/NTFS
/Dev/sda3 2555 7904 42973875 83 Linux
/Dev/sda4 7905 8924 Win95 ext 'd (LBA)
/Dev/sda5 7905 8924 8193118 + 82 Linux swap
Here we can clearly see that the system has a SCSI hard disk/dev/SDA and its four Disk Partitions/dev/sda1 --/dev/sda4, /dev/sda5 is the logical partition of/dev/sda4. After the mobile hard disk is connected, use fdisk-l or more/proc/partitions to view the hard disk and hard disk partition of the system.
[Root at pldyrouter/] # fdisk-l
Disk/dev/SDA: 73 dot 4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sda1 1 4 32098 + de Dell Utility
/Dev/sda2*5 2554 20482875 7 HPFs/NTFS
/Dev/sda3 2555 7904 42973875 83 Linux
/Dev/sda4 7905 8924 Win95 ext 'd (LBA)
/Dev/sda5 7905 8924 8193118 + 82 Linux swap
Disk/dev/SDC: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sdc1 1 510 4096543 + 7 HPFs/NTFS
/Dev/sdc2 511 4864 Win95 ext 'd (LBA)
/Dev/sdc5 511 4864 34973473 + B Win95 FAT32
We should be able to find that there is an additional SCSI hard disk/dev/SDC and its two disk partitions/dev/sdc1? /Dev/sdc2, where/dev/sdc5 is the logical partition of the/dev/sdc2 partition. We can use the following command to mount/dev/sdc1 and/dev/sdc5.
# Mkdir-P/mnt/usbhd1
# Mkdir-P/mnt/usbhd2
Note: creating a directory is used as a mount point)
# Mount-t ntfs/dev/sdc1/mnt/usbhd1
# Mount-T vfat/dev/sdc5/mnt/usbhd2
Note: The-t ntfs parameter should be used for Disk Partitions In NTFS format, and the-T vfat parameter should be used for disk partitions in FAT32 format. If the Chinese character file name is garbled or not displayed, you can use the following command format.
# Mount-t ntfs-O iocharset = cp936/dev/sdc1/mnt/usbhd1
# Mount-T vfat-O iocharset = cp936/dev/sdc5/mnt/usbhd2
In Linux, The fdisk partition command and The mkfs file system creation command can be used to make the partition of the mobile hard disk into the ext2 and ext3 formats specific to the Linux system. In this way, it is more convenient to use in Linux. Use the following command to directly mount the file.
# Mount/dev/sdc1/mnt/usbhd1
◆ Mount a USB flash drive

Like a USB-based mobile hard drive, USB flash drives are also treated as SCSI devices for Linux systems. The usage is exactly the same as that of a mobile hard disk. Before inserting a USB flash drive, use fdisk-l or more/proc/partitions to view the hard disk and hard disk partition of the system.
[Root at pldyrouter root] # fdisk-l
Disk/dev/SDA: 73 dot 4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sda1 1 4 32098 + de Dell Utility
/Dev/sda2*5 2554 20482875 7 HPFs/NTFS
/Dev/sda3 2555 7904 42973875 83 Linux
/Dev/sda4 7905 8924 Win95 ext 'd (LBA)
/Dev/sda5 7905 8924 8193118 + 82 Linux swap
After the USB flash drive is inserted, use fdisk-l or more/proc/partitions to view the hard disk and hard disk partition of the system.
[Root at pldyrouter root] # fdisk-l
Disk/dev/SDA: 73 dot 4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/sda1 1 4 32098 + de Dell Utility
/Dev/sda2*5 2554 20482875 7 HPFs/NTFS
/Dev/sda3 2555 7904 42973875 83 Linux
/Dev/sda4 7905 8924 Win95 ext 'd (LBA)
/Dev/sda5 7905 8924 8193118 + 82 Linux swap
Disk/dev/SDD: 131 MB, 131072000 bytes
9 heads, 32 sectors/track, 888 Cylinders
Units = cylinders of 288*512 = 147456 bytes
Device boot start end blocks ID system
/Dev/sdd1*1 889 127983 + B Win95 FAT32
Partition 1 has different physical/logical endings:
Phys = (1000, 8, 32) logical = (888, 7, 31)
The system has a SCSI hard disk/dev/SDD and a disk partition/dev/sdd1./dev/sdd1 is the USB flash drive to be attached.
# Mkdir-P/mnt/USB
Note: create a directory for mount point)
# Mount-T vfat/dev/sdd1/mnt/USB
Note: You can now access the USB flash drive through/mnt/USB. If the Chinese character file name is garbled or not displayed, use the following command.
# Mount-T vfat-O iocharset = cp936/dev/sdd1/mnt/USB
Similar to Windows Network Sharing, Unix (Linux) systems also have their own network sharing, that is, NFS (Network File System ), next we will take Sun solaris2.8 and RedHat as Server 3 as an example to briefly introduce how to mount nfs network sharing in Linux. Before mounting an NFS disk to a Linux client, you must configure the NFS server.
1. Configure the NFS server of the Solaris system as follows:
(1) Modify/etc/dfs/dfstab to add a shared directory.
Share-F nfs-o rw/export/home/sunky
(2) Start the NFS service
#/Etc/init. d/nfs. Server start
(3) After the NFS service is started, you can also use the following command to add a new share.
# Share/export/home/sunky1
# Share/export/home/sunky2
Note:/export/home/sunky and/export/home/sunky1 are shared directories.

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.