Linux: How to Use the mount command

Source: Internet
Author: User
Source: http://bbs.java.ccidnet.com
Mount command)
First, we will introduce how to use the mount command. The mount command has many parameters. Here we will focus on what we will use today.

Command Format:

Mount [-T vfstype] [-O options] device dir

Where:

1.-T vfstype specifies the type of the file system, which is usually not required. Mount automatically selects the correct type. Common types include:

CD or CD image: iso9660

DOS fat16 File System: msdos

Windows 9x FAT32 File System: vfat

Windows nt ntfs file system: NTFS

Mount Windows File network sharing: smbfs

Network Sharing for Unix (Linux) files: NFS

2.-O options is used to describe the mounting method of a device or file. Common parameters include:

Loop: used to connect a file to the system as a hard disk partition.

RO: mounting a device in read-only mode

RW: mounting a device in read/write mode

Iocharset: Specifies the character set used to access the file system

3. the device to be mounted.

4. mount point of the Dir device on the system ).

Attach 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; 3. The read speed of the hard disk is much higher than that of the optical disk, 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 8193150 F 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 8193150 F 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 34973505 F 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 8193150 F 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 8193150 F 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

Mount Windows File Sharing

The core of Windows Network Sharing is SMB/CIFS. To mount Windows disk sharing in Linux, you must install and use the samba software package. Currently, most popular Linux distributions already contain Samba packages. If Samba is not installed on Linux, install Samba first. Of course, you can download the new version 3.0.10 from www.samba.org.

After windows sharing is configured, you can mount the file on the Linux client as follows:

# Mkdir-P/mnt/samba

Note: create a directory for mount point)

# Mount-T smbfs-O username = administrator, password = pldy123 // 10.140.133.23/C $/mnt/samba

Note: Administrator and pldy123 are user names and passwords of Windows computers with IP addresses 10.140.133.23, and C $ is a disk share of this computer.

In this way, files on Windows disks can be accessed through/mnt/samba on Linux. The preceding operations are successfully performed in RedHat as Server 3, redflag Server 4.1, Suse Server 9, Windows NT 4.0, Windows 2000, Windows XP, and Windows 2003 environments.

Mount nfs file sharing in UNIX systems

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.

2. Configure the NFS server in Linux as follows:

(1) Modify/etc/exports to add a shared directory.

/Export/home/sunky 10.140.133.23 (RW)

/Export/home/sunky1 * (RW)

/Export/home/sunky2 Linux-client (RW)

Note: sunky, sunky1, and sunky2 under the/export/home/directory are the shared directories, 10.140.133.23, *, and Linux-client are IP addresses or host names allowed to connect to the shared Linux client. If you want to use the host name Linux-client, you must add the Linux-client host IP definition in the server host/etc/hosts file. The format is as follows:

10.140.133.23 Linux-Client

(2) start and stop the NFS service

/Etc/rc. d/init. d/Portmap start (Portmap is started by default in RedHat)

/Etc/rc. d/init. d/nfs start the NFS service

/Etc/rc. d/init. d/nfs stop NFS service

Note: If a new share is added to the/etc/export file, stop the NFS service and then start the NFS service to make the new share take effect. The command exportfs-RV can also achieve the same effect.

3. Mount the NFS share of other Linux or Unix systems on the Linux Client

# Mkdir-P/mnt/nfs

Note: create a directory for mount point)

# Mount-T nfs-o rw 10.140.133.9:/export/home/sunky/mnt/nfs

Note: here we assume 10.140.133.9 is the IP address of the NFS server host. Of course, the host name can also be used here, but the Server IP address definition must be added to the local/etc/hosts file. /Export/home/sunky is the directory shared by the server.

In this way, you can use/mnt/NFS on the Linux client to access files shared by NFS on other Linux or UNIX systems. The preceding operations are successfully performed in RedHat as Server 3, redflag server4.1, Suse Server 9, Solaris 7, Solaris 8, and Solaris 9 for x86 & iSCSI.
Another simple usage:
Simple usage:
FAT32 Partition
Mount-O codePage = 936, iocharset = cp936/dev/hda7/mnt/CDROM (Mount-T vfat-O iocharset = cp936/dev/hda7/mnt/CDROM)
NTFS partition
Mount-O iocharset = cp936/dev/hda7/mnt/CDROM
ISO file
Mount-o loop/ABC. ISO/mnt/CDROM
Floppy Disk
Mount/dev/fd0/mnt/floppy
USB flash memory
Mount/dev/sda1/mnt/CDROM Description: The/mnt/CDROM directory must exist.

Mount-A for all/etc/fstab content

You can specify the file format "-T format", which can be vfat, ext2, and ext3.

Image file:
Mount filename mountpoint-o loop. filename is the image file name (*. ISO, *. IMG). It is the same as above. Example: If I have. iso cd image file, mount. ISO a-o loop, so that you can browse a in directory. ISO content ,*. the usage of imgfiles is the same.

For Chinese, utf8 is better for Fedora Core 1.
Mount-O iocharset = uft8/dev/hda1/mnt/C
Mount-O iocharset = uft8/dev/sda1/mnt/USB
Mount-T smbfs // ip_addr/share/DIR/mnt/SMB/share-O iocharset = uft8, username = Name, password = passwd

Mount the partitions in windows at startup.
The Windows Drive D is automatically mounted to/mnt/D. Use VI to open/etc/fstab and add the following line.
/Dev/hda5/mnt/d vfat defaults, codePage = 936, iocharset = cp936 0 0
Note: You must create a/mnt/d directory manually.
Mount the directory shared by other Windows machines on the LAN (bjchenxu)
Mount-T smbfs-O username = guest, password = guest // machine/path/mnt/CDROM

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.