Linux mount command details

Source: Internet
Author: User

Disk image files, mobile hard drives, USB flash drives, Windows and NFS network sharing in linux

Linux is an excellent open-source operating system, which can run on various computer systems, from large to small, with the increasingly mature and stable linux system and its unique advantages of open source code, linux has been widely used in the world. Nowadays, many enterprise computer systems are a hybrid system consisting of UNIX, Linux, and Windows systems. Data Exchange is often required between different systems. Next, based on my actual work experience, I will introduce how to mount a CD image file, a mobile hard disk, a USB flash disk, Windows network sharing, and UNIX NFS network sharing in linux.
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; III. The 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 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.
Permission issues:
False server user jack, user id is 1818, gid is 1818, client also has a user jack, but uid and gid is 1818. The client jack wants to completely expose/home/jack to the server. The/etc/exports on the server is
For example:
/Home/jack * (rw, all_squash, anonuid = 1818, anongid = 1818)
This parameter indicates that all client users access server/home/jack
At the moment, it will map to jack (uid, gid = 1818) on the server side ). The result of my mount operation is
1. the root user of the client can fully access this category, including the category, category, category ...... And so on
2. client jack (uid, gid = 1818) I can do:
Rm-rf server_jack /*
Cp something server_jack/
Mkdir server_jack/


Automatic mount of Remote File System during startup
 
Html code
1. if you use the manual mount method to access an NFS share, the file system must be mounted after the system is restarted, red Hat Enterprise Linux provides two methods to automatically mount a remote file system. /Etc/fstab and autofs services.
2.
3./etc/fstab
4. The netfs Service uses the file/etc/fstab as a reference, so NFS shared files are automatically executed.
5. The following is a record of mounting NFS in/etc/fstab.
6. <server>: </remote/export> </local/directory> nfs <options> 0 0
7. Replace the above <server> with your NFS server,
8. Replace the preceding </remote/export> with the NFS output path.
9. Use the local mount point directory to replace </local/directory;> This directory must be created manually.
10. the nfs option in the preceding example describes the file system type used by the system.
11. You can replace <options> with nfs options. Separate multiple options with ",". For more information, see man fstab.
12.
13. Example:
14. server1.example.com:/share/directory/mnt/share nfs defaults 0 0
15.
16. Method 2: autofs service:
17. one disadvantage of using/etc/fstab is that the system always uses resources to maintain the NFS mount regardless of the number and time of NFS access. Although this is not a problem for one or two NFS mounts, if the system maintains many NFS mounts, the system performance will be affected, an alternative method is to use a kernel-based automatic mounting tool that can automatically mount NFS as needed.
18.
19. The autofs service will control the automatic mount command based on the/etc/auto. master File: The automount command can more easily specify the mount point, host name, and output directory.
20. the autofs configuration file is organized based on the parent-child relationship. The main configuration file (/etc/auto. master) lists all the mount points, and then connects to a specific ing type, which can be configuration files, programs, NIS ing or other Mount methods, auto. the master file contains the following content.
21. <mount-point> <map-type>
22. <mount-point> specifies a local mount point. <map-type> specifies how to mount the file. The most common NFS mount method is to use a file, which is usually named as auto. <mount-point>, <mount-point> is in auto. the mount point specified by the master, an NFS-Type auto. the content of <mount-point> is as follows:
23. </local/directory>-<options> <server >:</remote/export>
24. Replace </local/directory;> with a local mount point, which must be created manually.
25. you can replace <options> with nfs options. Separate multiple options with commas (,). For more information, see man fstab. make sure the symbol "-" is used before the options list "-".
26. Replace the above <server> with your NFS server,
27. Replace the preceding </remote/export> with the NFS server output path.
28. You can replace <options>
29. the autofs configuration file can be used in many mounting methods and different file systems. The Special Envoy is particularly useful in NFS mounting. For example, some organizations place all the/home directories on an NFS server, and then configure auto on each node. master points to auto. home, so that each node can mount the/home Directory through autofs. All users can access the data and configuration files under their/home/on any workstation. The auto. master in this case will look like the following.
30./home/etc/auto. home
31. This file sets/home/mount point to the/etc/auto. home file. auto. home should look like this:
32. *-fstype = nfs, soft, intr, rsize = 8192, wsize = 8192, nosuid, tcp server.example.com:/home
33. this file shows that if you want to access a directory in/home, it should generate an NFS mount to nfs.example.com, the mount Option indicates that each directory in/home uses its own settings. for more information about mount Options, see Section 9.4.3 Common NFS Mount Options in Red Hat Enterprise Linux 3 Reference Guide.
34. For more information about autofs, see the man manual and Installation Wizard.
35.

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.