Manual mounting of rhel6 file system

Source: Internet
Author: User
We have partitioned and formatted the disk through the previous section. if it is in windows, we can use it normally, but not in Linux, it must be mounted before it can be used normally. Now, mounting is what we learned today. To learn how to mount a mount point, first come...

We have partitioned and formatted the disk through the previous section. if it is in windows, we can use it normally, but not in Linux, it must be mounted before it can be used normally. Now, mounting is what we learned today.
Mount point
To learn how to mount a mount point, let's first look at what is a Mount point and what its role is?
We know that the file system structure in Linux is an inverted tree structure. If we want to add new things to this tree, we need to find a way to build something. then we can call this thing a mount point. This mount point allows other file systems to access our directory tree. Therefore, a Mount point must be a directory.
Here is an example.
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928372 7422356 49%/
Tmpfs 255784 0 255784 0%/dev/shm
From the above information, we can see that the first sda1 partition of my disk sda, and its Mount point is /. If you followed the experiment in the previous section, the information of our second disk is not shown here, because: We have not mounted it yet, so our directory tree does not exist.
Mount

In addition to the features of the Mount point we mentioned above, it should generally be an empty directory. Of course, there is no big impact if it is not an empty directory, because during mounting, all the original contents in this directory are hidden. when we unmount the Directory, the original content is displayed. However, we do not recommend that you use non-empty directories as Mount points. If the mount point is incorrect, it may affect the system, for example, mounting it to the user's home directory. As a result, do not mount multiple file systems at one mount point.
How to mount a file system

If you want to mount a file system, you need to come up with the main character "mount" today. This command is very likely to be used on Linux systems. This document briefly introduces the usage of this command.
Mount command format
Mount parameter-t file system-o option device mount point
If there is nothing next to mount, the current mount information will be displayed.
Mount-a will mount all the mounted files based on the information in the/etc/fstab file.
Mount-t file system
The file system mainly includes: ext3 ext4 vfat ntfs iso nfs smbfs
-O is followed by many options, mainly including permission restriction classes during mounting.
Ro/rw: Read-only or read/write (rw) is used to mount a file system)
Exec/noexec: whether to allow executable files on this file system
Suid/nosuid: whether to allow suid files on this file system
Dev/nodev: whether to allow the creation of device files on this file system
Auto/noauto: allows the file system to mount automatically with mount-.
Async/sync: whether the file system uses the memory mechanism for synchronous or asynchronous writing to the hard disk
User/nouser: whether to allow this file system to allow any user to execute the mount command
Defaults: Default value: rw, suid, dev, exec, auto, nouser, and async
Remount: remount. This option is often used when the system is repaired or when parameters are updated again.
Device: Which storage devices are in the system, mainly through fdisk-l or view/etc/fstab or dmesg. In general, the optical drive device is/dev/cdrom, and the soft drive device is/dev/fd0 (it seems that there is no soft drive now). the hard drive and mobile hard drive are subject to the output of fdisk-l.
Mount point: no need to mention this. it is okay to create an empty directory.
Of course, there are other parameters and options. here you can use MAN to view more help information. The key is practice. Next we will familiarize ourselves with the use of this command through examples.
We will use the hard disk partition yesterday as an example to demonstrate how to mount the EXT4 file system. The same is true for other file systems, but the-t file system type is different here. Of course, we should note some other considerations.

[Root @ yufei ~] # Fdisk-l
View disk and partition information in the system

I only take part of the content as follows:
Disk/dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0xd6737273
Device Boot Start End Blocks Id System
/Dev/sdb1 1 132 1060258 + 83 Linux
/Dev/sdb2 133 183 409657 + 83 Linux
/Dev/sdb3 184 2610 19494877 + 5 Extended
/Dev/sdb5 184 445 2104483 + 83 Linux
/Dev/sdb6 446 511 530113 + 82 Linux swap/Solaris
In the previous course, only sdb1 is formatted, while other partitions are not formatted. So here we will show you that the mounting is not formatted.
Mount ext4 file system
Create a mount point first. I prefer to use the/mnt Directory of the system, so I will not create a directory here.

Then mount
[Root @ yufei ~] # Mount/dev/sdb1/mnt
I didn't specify the file system type here. Why can it be correctly recognized without specifying it? The main reason is that we already have these default type drivers in our system. So how do I know how many default drivers are in the system? You can view the following two files.
/Etc/filesystems: default mount file system type specified by the system
/Proc/filesystems: types of file systems that have been loaded in Linux
Although there is, how do I know if my Linux system has a file system driver? We may view the supported file system drivers through the information in the/lib/modules/$ (uname-r)/kernel/fs/directory.
If it is a file system other than this, you must add-t and the corresponding file system type.
We use df to view the mounting status, which is compared with the first view results.
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928404 7422324 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sdb1 1033560 40980 939568 5%/mnt
We can see that the last row has the partition we just Mounted. now we can write something in/mnt.
[Root @ yufei ~] # Touch/mnt/testfile
[Root @ yufei ~] # Ls-l/mnt/
Total 16
Drwx ------. 2 root 16384 May 26 16:19 lost + found
-Rw-r --. 1 root 0 May 26 23:15 testfile
OK. the file has been written. Next, let's change the mounting option so that it is read-only.
[Root @ yufei ~] # Mount-o ro, remount/dev/sdb1
[Root @ yufei ~] # Touch/mnt/testfile2
Touch: cannot touch '/mnt/testfile2': Read-only file system
Now, the mount point/mnt cannot write any content to it. I didn't unmount/dev/sdb1. I only used remount to re-mount it. with the ro option added, it became read-only. Test the functions of other parameters on your own.
Note: multiple options are separated in English.
Attach a CD
Disk mounting, which is the same as partition mounting.
[Root @ yufei ~] # Mkdir/media/cdrom
[Root @ yufei ~] # Mount/dev/cdrom/media/cdrom/
Mount: block device/dev/sr0 is write-protected, mounting read-only
The prompt here is read-only, because it is a CD!
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928416 7422312 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sdb1 1033560 40980 939568 5%/mnt
/Dev/sr0 2862360 2862360 0 100%/media/cdrom
The last line has another cdrom.
Note: On RHEL6, the device name of the disc is changed to sr0, instead of the previous cdrom.
-T iso9660 should be added to the mounting disc, because our system file system driver already exists, so I don't need to add parameters, the system will be able to understand.
USB flash disk mounting
The mount of a USB flash disk is the same as that of a hard disk.

1. fdisk-l
2. create a mount point
3. execute the Mount command
The specific demonstration is skipped here. if you have any conditions, please do it yourself!
Mounting the NTFS file system

See Mount NTFS partitions on RHEL6 and make it readable and writable http://www.opsers.org/base/mount-ntfs-partition-in-rhel6-and-let-it-read-and-write.html
The following shows how to mount an unformatted partition.
[Root @ yufei ~] # Mkdir/test
[Root @ yufei ~] # Mount/dev/sdb2/test
Mount: you must specify the filesystem type
Even if I add the file system type, it is meaningless to add the file system type here. after all, it is not formatted. this is just a demonstration, so I will use ext4 to demonstrate it.
[Root @ yufei ~] # Mount-t ext4/dev/sdb2/test
Mount: wrong fs type, bad option, bad superblock on/dev/sdb2,
Missing codepage or helper program, or other error
In some cases useful info is found in syslog-try
Dmesg | tail or so
I will first format it. this time I will format it into VFAT format, so I will first convert the partition type
[Root @ yufei ~] # Fdisk/dev/sdb
Command (m for help): t
Partition number (1-6): 2
Hex code (type L to list codes): B
Changed system type of partition 2 to B (W95 FAT32)
Don't forget to save it.
Command (m for help): w
Format
[Root @ yufei ~] # Mkfs. vfat/dev/sdb2
Mkfs. vfat 3.0.9 (31 Jan 2010)
Then mount
[Root @ yufei ~] # Mount/dev/sdb2/test
Check the mounting status.
[Root @ yufei ~] # Df-T
Filesystem Type 1K-blocks Used Available Use % Mounted on
/Dev/sda1 ext4 15118728 6928520 7422208 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sdb1 ext4 1033560 40980 939568 5%/mnt
/Dev/sr0 iso9660 2862360 2862360 0 100%/media/cdrom
/Dev/sdb2 vfat 409424 0 409424 0%/test
Fat32 format is also mounted.
Note: in practice, a Windows partition is directly attached, and the Chinese file name and directory name may be garbled. to avoid this problem, you can specify a character set by running the following command:
Mount/dev/sdb2/test-o codepage = 936, iocharset = cp936
Mount/dev/sdb2/test-o codepage = 936, iocharset = cp936
Note: cp936 refers to simplified Chinese and cp950 refers to traditional Chinese.
Mount with the volume label of the device

We specify the tag name when Formatting/dev/sdb1. Let's take a look.
[Root @ yufei ~] # Tune2fs-l/dev/sdb1 | more
Tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: opsers_tech
Many rows are omitted here.
Mount
[Root @ yufei ~] # Mount-L opsers_tech-o remount
Df is used to see the original content. to make it clear to everyone, we uninstalled this first,
[Root @ yufei ~] # Umount/mnt
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928544 7422184 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sr0 2862360 2862360 0 100%/media/cdrom
/Dev/sdb2 409424 0 409424 0%/test
And then mount it as a volume label.
[Root @ yufei ~] # Mount-L opsers_tech/mnt
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928544 7422184 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sr0 2862360 2862360 0 100%/media/cdrom
/Dev/sdb2 409424 0 409424 0%/test
/Dev/sdb1 1033560 40980 939568 5%/mnt
You can also mount the device by replacing the device name with the volume label.
Mounting ISO files

We create a 50 m ISO file.
[Root @ yufei ~] # Dd if =/dev/zero of = test. iso bs = 1 M count = 50
50 + 0 records in
50 + 0 records out
52428800 bytes (52 MB) copied, 0.513358 s, 102 MB/s
Format it
[Root @ yufei ~] # Mkfs. ext4 test. iso
Mke2fs 1.41.12 (17-May-2010)
Test. iso is not a block special device.
Proceed anyway? (Y, n) y
Many rows are omitted here.
Mount
[Root @ yufei ~] # Mkdir/loop
[Root @ yufei ~] # Mount-o loop test. iso/loop
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6979752 7370976 49%/
Tmpfs 255784 0 255784 0%/dev/shm
/Dev/sr0 2862360 2862360 0 100%/media/cdrom
/Dev/sdb2 409424 0 409424 0%/test
/Dev/sdb1 1033560 40980 939568 5%/mnt
/Dev/loop0 49574 4906 42108 11%/loop
You can write files normally.
[Root @ yufei ~] # Touch/loop/test
[Root @ yufei ~] # Ls/loop/
Lost + found test
We will explain how to mount the Network File System in the following services.
File system uninstallation
OK. I have introduced so many mounting contents. what should I do if I want to detach the content?

This is the umount command, which is relatively simple.
The format is
Umount parameter device name or mount point
-F: force uninstall. It can be read by a network-like File System (NFS ).
-N: unmount without updating/etc/mtab
[Root @ yufei ~] # Umount/mnt # mount point
[Root @ yufei ~] # Umount/dev/sr0 # connect to the device
[Root @ yufei ~] # Umount/dev/sdb2 # connect to the device
[Root @ yufei ~] # Df
Filesystem 1K-blocks Used Available Use % Mounted on
/Dev/sda1 15118728 6928528 7422200 49%/
Tmpfs 255784 0 255784 0%/dev/shm
In this way, all the content I just mounted is detached.
Didn't we create a file for/mnt? Now let's see if he is still in/mnt,
[Root @ yufei ~] # Ls/mnt
Hgfs
The file we created is not here, while the hgfs directory is provided by the system. This also verifies that, as mentioned at the beginning of the article, the original content in the directory will not be damaged and will be restored after the file system is uninstalled. While our Mount point serves as a bridge, although it is to write content to the Mount point, but in fact, the written object is the corresponding device. We can mount the device to see if this is the case.
[Root @ yufei ~] # Mount/dev/sdb1/mnt
[Root @ yufei ~] # Ls/mnt
Lost + found testfile
Testfile again.
[Root @ yufei ~] # Umount/mnt
[Root @ yufei ~] # Ls/mnt
Hgfs
/Mnt restored again

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.