Summary of mounting a file system in Linux

Source: Internet
Author: User

When learning about the operating system, we all know that the file system is an important part of the operating system. There are many types of file systems, such as windows fat, fat32, Linux ext, ext2 or ext3, And FreeBSD ufs. During the use of Linux, the Linux operating system often uses the Virtual File System (VFS) to directly access various file systems that have been supported by the kernel through VFS, it is used like in a common Linux ext file system. There were not many built-in file systems supported in Linux in the early days. Since kernel 2.0.x, VFAT was supported and will be gradually increased in the future. It can be said that most file systems have support. Only the kernel needs to be re-compiled to support NTFS.
During Linux Startup, the file system on each partition is mounted to the corresponding loading point according to the settings in/etc/fstab. Linux requires at least two partitions to start: one is the root partition/and the other is the swap partition. If the root partition fails to be loaded at startup, Linux cannot start. If the swap partition fails to be loaded, Linux cannot be started, and the speed will be greatly affected if the memory is insufficient. The file system type of the root partition is usually ext, ext2, or ext3, but it can also be other file systems.
In addition to the file system required for Linux, Linux users often need to use other file systems, especially when multiple operating systems are installed on one machine at the same time. For example, I installed Linux and Windows on my machine at the same time. Windows C adopts the NTFS file system and D adopts the FAT32 file system. When I work on Linux, I often need to access the Windows drive C and drive D, or even the shared directory on the network, in Linux, the mount command is used to mount a file system. The man mount command can be used to get a detailed explanation of the command parameters. The following describes how to mount a file system using the command line in several cases:
1. Add the FAT32 File System

Simplest usage
Mount/dev/hda6/mnt/d
/Dev/hda6 is the author's Windows d disk,/mnt/d is the directory mount point. Linux recognizes the type of the file system in the/dev/hda6 partition, and then adds it. Of course, you can also specify the file system type of the partition. The command is as follows:
Mount-t vfat/dev/hda6/mnt/d
In practice, a windows partition is directly attached, and the Chinese file name and directory name are garbled. To avoid this problem, you can specify a character set by running the following command:
Mount/dev/hda6/mnt/d-o codepage = 936, iocharset = cp936
Mount-t vfat/dev/hda6/mnt/d-o codepage = 936, iocharset = cp936
Note: cp936 refers to simplified Chinese and cp950 refers to traditional Chinese.
2. Mount the NTFS file system
In most Linux versions, you need to re-compile the Linux core to mount the NTFS partition (see other articles for the compilation method ). After the core supports NTFS, run the following command:
Mount-t ntfs/dev/hda2/mnt/c
You can also specify the character set for garbled characters in Chinese file names and directory names. However, unlike the vfat partition, the following command is practical:
Mount-t ntfs-o iocharset = cp936/dev/hda2/mnt/c-r
Mount-t ntfs-o iocharset = cp936, rw/dev/hda2/mnt/c
3. Mount the file system on the USB flash drive

More and more people are using USB flash drives. In fact, using USB flash drives in Linux is also very simple. Linux has good support for USB devices. After you insert a USB flash drive, the USB flash disk is recognized as a SCSI disk. You can use the following command to mount the file system on the USB flash disk.
Mount/dev/sda1/usb
You can specify a character set for garbled characters in Chinese file names and directory names. The command is similar to the one described in FAT32:
Mount/dev/sda1/usb-o pagecode = 936, iocharset = cp936
4. Add a Linux directory shared by samba.
The directory shared by samba is hard to tell which file system it was originally, but this is not important as long as it is transparent to users. When mounting, we specify the smbfs type. When mounting a samba shared partition, Chinese file names and directory names may also be garbled. You can run the following command to mount the file:
Mount-t smbfs-o
Username = terry, password = terry, codepage = 936, iocharset = cp936
// Terry-linux/terry/mp3/
Mount-t smbfs-o
Username = terry, password = terry, codepage = 936, iocharset = cp936
// 192.168.100.228/terry/mp3/
Note: you do not need to directly write the password = terry parameter. In the system field, you will need to enter the password to prevent anyone from directly viewing your password. Depending on the actual situation, the parameters following-o can be increased or decreased accordingly.
5. Add the directory shared by the Window system

In the LAN, you often need to access the directories shared by other Windows systems. In Linux, after samba is installed, you can use the commands in samba to access the shared resources of Windows machines.
Use smbclient to list shared resources of Windows machines
Smbclient-L 192.168.100.111
Based on the Windows Shared resources listed above, you can select the Windows Shared resources to be attached to the local Linux, and then use smbmount or mount to add the resources. refer to the following commands:
Smbmount // 192.168.100.111/public/
Mount // 192.168.100.111/d/mnt/cdrom-o username = terry (enter the password on the command line)
Mount // 192.168.100.111/d/mnt/cdrom-o username = terry $1234 (you do not need to enter the password in the command line)

Note: In addition to the command line method described above, the best method is to use other clients, such as LinNeighborhood, networkneighbours, and ksmbshare. Please refer to other articles.
The above is a command line method. You must enter the command once each time you use it. If you often need to mount some file systems, what should you do if you want to automatically mount them at startup? The following two methods are described:
Method 1.
Place the mounting command in/etc/rc. d/rc. local.
Method 2.
Modify the partition configuration file/etc/fstab and mount the file system at startup. The following is my/etc/fstab file:
LABEL = // ext3defaults
1 1
None/dev/pts devpts gid = 5, mode = 620
0 0
LABEL =/home/homeext3defaults
1 2
None/procprocdefaults
0 0
None/dev/shm tmpfs ults
0 0
/Dev/hda4 swap swapdefaults
0 0
/Dev/cdrom/mnt/cdrom iso9660
Noauto, owner, kudzu, ro 0 0
/Dev/hda2/ntfs ntfsdefaults, iocharset = cp9360 0
/Dev/hda6/win vfatdefaults, codepage = 936, iocharset = cp9360 0
// 192.168.100.228/terry/mp3smbfsusername = terry, password = terry, codepage = cp936, iocharset = cp936 0 0
Note the last three lines:
The fourth to last line adds my C drive, NTFS format
In the last row, mount my d disk, in FAT32 format.
In the penultimate line, a directory is mounted to another Linux file server on which samba is installed in my LAN.
This article summarizes several common methods for mounting a file system in Linux under different circumstances, including how to mount FAT/NTFS/smbfs/U disk, and solve the problem of Chinese display/User Password in mounting.

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.