Linux Disk Mount

Source: Internet
Author: User

Disk mount and dismount

Linux Disk mounts use mount commands to uninstall the use umount command.

The Mount command is used to load the file system to the specified mount point. The most common use of this command is to mount the CDROM so that we can access the data in the CDROM because you insert the disc into the CDROM, Linux does not mount automatically, and you must manually complete the mount using the Linux mount command.

Disk mount Syntax:

mount [-hV]mount -a [-fFnrsvw] [-t vfstype]mount [-fnrsvw] [-o options [,...]] device | dirmount [-fnrsvw] [-t vfstype] [-o options] device dir


Options Description
-V Show Program version
-H Show auxiliary messages
-V Show more messages, usually and-F for debugging.
-A Hang all the file systems defined in the/etc/fstab.
-F This command is usually used with-a, which generates a stroke for each mount action. You can speed up the action of hanging when the system needs to hang a large number of NFS file systems.
-F Usually used in the use of debugging. It makes mount not perform the actual hanging action, but rather simulates the entire hanging process. It is usually used with-V.
-N In general, Mount hangs on the/etc/mtab to write a piece of information. However, this option can be used to cancel this action if there is no writable file system in the system.
-s-r equals-o ro
-W Equals-o RW
-L Split the hard drive with a specific label on it.
-U The file system that divides the files into serial numbers is hung. The-L and-u must be meaningful when the/proc/partition file is present.
-T Specifies the type of the file system, which is usually not required. Mount will automatically select the correct form.
-O Async Open non-synchronous mode, all the file read and write actions will be performed in the asynchronous mode.
-O Sync Executes in synchronous mode.
-O atime,-o noatime When Atime is turned on, the "Last Call time" of the archive is updated each time the file is read. When we use the Flash file system, we may turn this option off to reduce the number of writes.
-O auto,-o Noauto Turn on/off auto-hang mode.
-O Defaults Use preset options for RW, suid, dev, exec, auto, Nouser, and async.
-O Dev,-o nodev-o exec,-o noexec Allows execution of the file to be executed.
-O suid,-o nosuid Allows execution of the file under root authority.
-O user,-o nouser The user can perform mount/umount actions.
-O remount Put an already hung file system back in a different way. For example, a system that was originally read-only, is now re-hung in a read-write mode.
-O ro Hang up in read-only mode.
-O RW Use the read-write mode to hang up.
-O loop= Use loop mode to mount a file as a hard disk partition system.

- t verbose options:

? Disc or disc Image: iso9660

? DOS FAT16 file system: MSDOS

? Windows 9x FAT32 file system: VFAT

? Windows NT NTFS file system: NTFS

? Mount Windows file network share: SMBFS (requires kernel support) Recommended CIFS

? UNIX (LINUX) file network share: NFS

- o verbose options:

? Loop: Used to attach a file as a hard disk partition on the system

? RO: Hook device with read-only method

? RW: Mount device with read-write mode

? Iocharset: Specifies the character set used to access the file system, such as Iocharset=utf8

? Remount: Re-mount

But before you mount it, you'd better identify a few things:

    • A single file system should not be repeatedly mounted in different mount points (directories);
    • A single directory should not repeatedly mount multiple file systems;
    • To be a directory of mount points, it should theoretically be an empty directory.

If the directory you want to mount is not empty, the contents of the original directory will disappear temporarily after the file system is mounted. For example, assuming that your/home is in the same filesystem as the root directory (/), there are two directories/home/test and/home/vbird. Then you want to add a new disk, and directly mount home/home below, then when you mount the new partition, the/home directory shows the data in the new partition, as for the original test and vbird the two directories will be temporarily hidden out! Notice is not overwritten, but temporarily hidden, and until the new partition is unloaded, then/home original content will run out again!

Mount Disc image File

1. Make disc image file from CD-ROM. Put the disc in the CD drive and execute the command below.

#cp /dev/cdrom /home/sunky/mydisk.iso 或 #dd if=/dev/cdrom of=/home/sunky/mydisk.iso

Note: Any of the above commands can be used to make discs in the current optical drive into a disc image file/home/sunky/mydisk.iso

2. Make the files and directories into a disc image file, execute the following command.

#mkisofs -r -J -V mydisk -o /home/sunky/mydisk.iso /home/sunky/ mydir

Note: This command makes all directories and files in the/home/sunky/mydir directory into a disc image file/home/sunky/mydisk.iso, the disc is labeled: Mydisk

3. Mounting of the disc image file (Mount)

#mkdir /mnt/vcdrom

Note: Create a directory to use as a mount point

#mount -o loop -t iso9660 /home/sunky/mydisk.iso /mnt/vcdrom

Note: With/mnt/vcdrom, you can access all the files in the disc image file Mydisk.iso.

Hooking up a removable hard disk

For Linux systems, the USB interface's removable hard disk is treated as a SCSI device. Before inserting a removable hard disk, you should first use fdisk –l or more /proc/partitions view the system's hard disk and hard disk partition.

[root at pldyrouter /]# fdisk -l

After the removable hard drive is connected, use fdisk –l or more .
/proc/partitions View the system's hard disk and hard disk partition, you should be able to find a SCSI hard disk/DEV/SDC and its two disk partition/dev
/SDC1,/DEV/SDC2, where/DEV/SDC5 is the logical partition of the/DEV/SDC2 partition, we can use the following command to hook up/DEV/SDC1 and

#mkdir -p /mnt/usbhd1 #mkdir -p /mnt/usbhd2

Note: Create a directory to use as a mount point

#mount -t ntfs /dev/sdc1 /mnt/usbhd1 #mount -t vfat /dev/sdc5 /mnt/usbhd2

Note: For NTFS-formatted disk partitions, parameters should be used -t ntfs and parameters should be used for disk partitions in FAT32 format -t vfat . If the kanji file name is displayed as 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

Using the fdisk partition command and the mkfs file system creation command under the Linux system, the partition of the removable hard disk can be made into the ext2 and ext3 format peculiar to the Linux system. This makes it easier to use under Linux. Use the following command to hook up directly.

#mount /dev/sdc1 /mnt/usbhd1
mount USB flash drive

As with the USB interface of a removable hard disk, the USB stick is also treated as a SCSI device for Linux systems. Use the same method as moving the hard disk. Before inserting a USB flash drive, you should first use fdisk –l or more /proc/partitions view the system's hard disk and hard disk partition.

[root at pldyrouter root]# fdisk -l

After inserting the USB flash drive, use fdisk –l or more /proc/partitions view the system's hard disk and hard disk partition condition.

[root at pldyrouter root]# fdisk -l

The system has a SCSI hard disk/DEV/SDD and a disk partition/DEV/SDD1,/DEV/SDD1 is the USB stick we want to hook up.

#mkdir -p /mnt/usb

Note: Create a directory to use as a 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 displayed as garbled or not displayed, you can use the following command.

#mount -t vfat -o iocharset=cp936 /dev/sdd1 /mnt/usb
hooking up Windows file shares

The core of Windows network sharing is smb/cifs, where you must install and use Samba if you want to mount a disk share for Windows on Linux
Package. The majority of popular Linux distributions now contain samba packages, and if you install a Linux system without samba, install Samba first. Of course, you can also download the new version of the website is the 3.0.10 version.
When the Windows system share is set up, you can hook up (mount) on the Linux client, with the following details:

# mkdir –p /mnt/samba

Note: Create a directory to use as a mount point

# mount -t smbfs -o username=administrator,password=pldy123 //$ /mnt/samba

Note: Administrator and pldy123 are a user name and password for the IP address of the Windows computer, and C $ is a disk share for this computer.
This allows you to access the files on the Windows system disk via/mnt/samba on your Linux system. The above operations were tested in Redhat as Server3, Redflag Server 4.1, SuSE Server 9, and Windows NT 4.0, Windows 2000, WindowsXP, and Windows 2003 environments.

hooking up UNIX system NFS file shares

Similar to the Windows-based network share, UNIX (Linux) systems also have their own network shares, that is, NFS (Network File system), below we are in the Sun Solaris2.8 and Redhat as server 3 For example, briefly describe how to mount an NFS network share under Linux.
Before the Linux client mounts (Mount) NFS disk share, the NFS server must be configured first.

1. The Solaris system NFS Server configuration method is as follows:

(1) Modify/etc/dfs/dfstab, add 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 directories that are ready to be shared

2, the Linux system NFS server configuration method is as follows:

(1) Modify/etc/exports, add shared directory

/export/home/sunky /export/home/sunky1 *(rw) /export/home/sunky2 linux-client(rw)

Note: Sunky, Sunky1, sunky2 in the/export/home/directory are the directories to be shared,, *,
Linux-client is the IP address or host name that is allowed to hook up this shared Linux client. If you want to use host name linux-client must be on the server host
Add linux-client host IP definition in/etc/hosts file. The format is as follows: linux-client

(2) Start and stop NFS services

/etc/rc.d/init.d/portmap start (在REDHAT中PORTMAP是默认启动的) /etc/rc.d/init.d/nfs start 启动NFS服务 /etc/rc.d/init.d/nfs stop 停止NFS服务

Note: If you modify the/etc/export file to add new shares, you should stop the NFS service before starting the NFS service to make the newly added share work.
The same effect can be achieved using the command EXPORTFS-RV.

3, Linux client mount (Mount) NFS sharing for other Linux systems or UNIX systems

# mkdir –p /mnt/nfs

Note: Create a directory to use as a mount point

#mount -t nfs -o rw /mnt/nfs

Note: Here we assume that is the host IP address of the NFS server, of course, the host name can be used here, but the server-side IP definition must be added to the native/etc/hosts file. /export/home/sunky the directory that is shared with the server.
This allows the Linux client to access files that are shared on NFS by other Linux systems or UNIX systems via/MNT/NFS.
These actions are tested in Redhat as Server 3, Redflag server4.1, SuSE Server 9, and Solaris 7, Solaris 8, and Solaris 9 for X86&SPARC environments.


Linux load CD-ROM:
(1) Before using the optical drive, mount it first:

#mount /dev/cdrom /mnt/cdrom

You can then go to the/mnt/cdrom directory to read the contents of the disc.
(2) When you want to exit the disc, you must use the Umout command, or the optical drive will always be in a deadlock state:

#umount /mnt/cdrom
Disk Offload Command Umount

The umount command is used to unload a file system that has already been loaded. The file system can be umount with a device name or mount point, but it is best to uninstall it by Mount point to avoid confusion when using bound mounts (one device, multiple mount points).


umount [-ahnrvV][-t <文件系统类型>][文件系统]


Options Description
-A Remove all file systems recorded in the/etc/mtab;
-H Display Help;
-N Do not deposit information into the/etc/mtab file when unloading;
-R Attempt to re-mount the file system as read-only if it fails to dismount successfully;
-T <文件系统类型> Remove only the file system specified in the option;
-V Display detailed information when executing;
-V Displays version information.

The following two commands unload the file system by device name and mount point, respectively, and output the details:

Uninstall by device name

umount -v /dev/sda1/dev/sda1 umounted

Unloading by Mount point

umount -v /mnt/mymount//tmp/diskboot.img umounted

If the device is busy, the uninstallation fails. A common cause of uninstallation failure is that an open shell's current directory is a directory in the mount point:

umount -v /mnt/mymount/umount: /mnt/mymount: device is busyumount: /mnt/mymount: device is busy

Sometimes, the cause of a busy device is not easy to find. When this happens, you can use the lsof (lsof command to view the file you are running, the process of opening the file, the port on which the process opened (TCP, UDP). Retrieve/Recover deleted files. is a very convenient system monitoring tool, because the lsof command requires access to core memory and various files, so the root user needs to execute. List the open files, and then search the list to find the mount points to unload:

lsof | grep mymount         查找mymount分区里打开的文件bash   9341  francois  cwd   DIR   8,1   1024    2 /mnt/mymount

From the above output, the Mymount partition cannot be unloaded because the Francois is running a 9341-PID bash process.

Another way to deal with system files being busy is to perform deferred uninstallation:

umount -vl /mnt/mymount/     执行延迟卸载

Deferred offload (lazy unmount) immediately uninstalls the file system in the directory tree and cleans up all related resources until the device is no longer busy. Uninstalling Removable Storage media can also be used eject (theeject command is used to exit the pull-out device.) If the device is already mounted, the eject command will first dismount the device before exiting. Command The following command uninstalls the CD and pops up the CD:

eject /dev/cdrom      

Linux Disk Mount

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.