The Linux mount command is a required command for Linux users. The mount and umount commands are described in detail here. In combination with examples, we can understand the specific usage of the Linux mount command, we learned how to use Linux.
Mount the File System
Its syntax is:
Mount [Option] <-t type> [-o mount Option] <device> <mount point>
In this example, we will first temporarily mount the partition to/mnt (or any other mount point you selected: Remember that the mount point must already exist ). The command to mount the newly created partition is:
$ Mount-t ext3/dev/hdb1/mnt
The-t option is used to specify the type of the file system on the partition. The most common file system you encounter should be ext2FS (GNU/Linux File System) or ext3FS (ext2FS that improves log performance), VFAT (applicable to all DOS/Windows & reg; partitions: FAT 12, 16 or 32) and ISO9660 (CD-ROM File System ). If you do not specify any type, mount will try to read the ultra block in the partition to guess the file system.
-O options are used to specify one or more mount options. The available options vary depending on the file system type. See mount (details on the manual page.
Now that you have mounted your new partition, copy the entire/usr directory to the new partition:
$ (Cd/usr & tar cf-.) | (cd/mnt & tar xpvf -)
All the files have been copied. Now you can unload the partitions.
Umount command
The syntax is simple:
Umount <mount point | device>
Therefore, to unload our new partition, enter:
$ Umount/mnt
Or:
$ Umount/dev/hdb1
Prompt
Sometimes some devices (usually CD-ROM) are busy or unable to respond. In this case, the solution for most users is to restart the computer. We don't have to do this. For example, if umount/dev/hdc fails, you can try "lazy" umount. The syntax is very simple:
Umount-l <mount point | device>
This command will disconnect the device and close all handles that open the device. Generally, you can use the eject <mount point | device> command to pop up the disc. Therefore, if the eject command is invalid and you do not want to restart it, use lazy umount.
As the partition is about to become our/usr directory, we need to notify the system now. To complete this operation, we should edit the/etc/fstab file. This file enables the system to automatically mount a specific file system at startup. Each row of the file describes a set of Mount relationships, including the file system, mount point, and other options. Here is an example of this file:
/Dev/hda1/ext2 defaults 1 1
/Dev/hda5/home ext2 defaults 1 2
/Dev/hda6 swap defaults 0 0
None/mnt/cdrom supermount dev =/dev/bq0, fs = udf: iso9660, ro, -- 0 0
None/mnt/floppy supermount dev =/dev/fd0, fs = ext2: vfat, --, sync, umask = 0 0 0
None/proc defaults 0 0
None/dev/pts devpts mode = 0622 0 0
Each line consists of the following content:
The device where the file system is located;
Mount point;
File System type;
Mount option;
Dump tool backup mark;
The ChecK sequence of fsck (FileSystem ChecK.
There is always a line indicating the root file system. Swap partition is a special partition, because you cannot find its corresponding location in the tree structure, and the mount point fields of these partitions only contain the swap keyword. For the/proc file system, we will provide a more detailed description in Chapter 10th/proc file system. Another special file system is/dev/pts.
Here, we need to move the entire/usr level to/dev/hdb1 and mount the partition to/usr at startup. To achieve this goal, add the following line to the/etc/fstab file:
/Dev/hdb1/usr ext2 defaults 1 2
Now, the partition will be automatically mounted at each start and an error will be checked if necessary.
Now we will introduce two special options: noauto and user. The noauto option specifies that the file system should not be mounted at startup, but should only be mounted when you want to mount. The user option specifies that any user can mount or detach the file system. These two options are typically used for CD-ROM and floppy drive. For details about other options in/etc/fstab, see the fstab (5) manual page.
The advantage of using/etc/fstab is that it greatly simplifies the syntax of the mount command. To mount the file system described in the file, you only need to reference the mount point or device. To mount a floppy disk, you can only enter:
$ Mount/mnt/floppy
Or:
$ Mount/dev/fd0
At the end of the partition transfer example, let's take a look at what we have done. We copied the/usr level to the new partition, and modified/etc/fstab, so that the new partition will be automatically mounted at startup. This seems to be a success. Slow, there is another problem. Files in old/usr remain in the original place in the drive, and we need to delete them to free up space (this is our initial goal ). Before executing the following command, you must switch to the single-user mode. Run the telinit 1 command on the command line.
Next, we will delete all the files in the/usr directory. Remember, we still mean the "old" directory, because the new large directory is not mounted yet. Rm-Rf/usr /*.
Finally, we need to mount the new/usr Directory: mount/usr/
When using the Linux Mount command, pay attention to the combination of mounting and unmounting.
- Detailed command 1 for running Linux background)
- In-depth analysis of Linux partition Basics
- Detailed parsing of Linux user operation records
- Detailed analysis of Linux scp command Application
- Detailed analysis of Linux Process Scheduling time