How to mount hard disk partitions in Linux

Source: Internet
Author: User
How to mount hard disk partitions in Linux-general Linux technology-Linux technology and application information. For more information, see the following. 1. Use Autofs to automatically mount partitions
2. Modify/etc/fstab
3. Write a shell script and run the mount command automatically upon startup.

Method 1: Use Autofs
1. Features of Autofs: The difference between Autofs and Mount/Umount is that it is a guard Program (deamon ). If it detects that the user is attempting to access a file system that has not been attached, it will automatically detect the file system. If the file system exists, Autofs will automatically mount it. On the other hand, if it detects that a mounted file system is not used for a period of time, Autofs will automatically uninstall it. Therefore, after running Autofs, you do not need to manually mount or uninstall the file system.

2. Autofs installation: run the following command: rpm-ivh autofs-3.1.3-10.i386.rpm. After the installation is complete, Autofs runs automatically every time Linux is started.

3. Autofs configuration: first, Autofs needs to read the configuration information from the/etc/auto. master file. This file can specify multiple contacts at the same time, each of which is defined by a single row. Each row can contain three parts, which are used to specify the location of the contacts, the configuration file (the so-called map file) to be used for mounting and the automatic uninstallation of the mounted file system after the idle time. For example, the auto. master file contains the following line:/auto/etc/auto. misc -- timeout 60. The first part specifies the installation point as/auto, and the second part specifies the/auto map file as/etc/auto. misc, the third part specifies that the file system is automatically uninstalled 60 seconds after it is idle. Second, read the configuration information required for mounting from the/etc/auto. misc file. For example, the auto. misc file contains the following content:

Cd-fstype = iso9660, ro, nosuid, nodev:/dev/cdrom
Windows_C-fstype = auto, iocharset = cp936:/dev/hda1
Windows_D-fstype = auto, iocharset = cp936:/dev/hda5
Windows_E-fstype = auto, iocharset = cp936:/dev/hda6

The first line indicates that the device/dev/cdrom is mounted to the cd subdirectory of/auto, and the second line indicates that the Windows partition of the hard disk is mounted to the Windows _ * subdirectory of/auto. The second value of each row-fstype is an optional option to indicate the type and mounting options of the mounted file system. The mount command can use the mounting option as well as-fstype. After the configuration file is modified, run the "/etc/init. d/autofs restart" command to make the new configuration take effect. Now input the command "ls/auto/cd". Autofs will automatically check whether there is a cd in the optical drive. If yes, it will automatically attach it to/auto/cd, in this way, ls will list the content. If we do not access/auto/cd again within 60 seconds, Autofs will unmount it automatically.

Method 2: Modify/etc/fstab

1. Functions of fstab files
File/etc/fstab stores the file system information in the system. When the file is correctly set, you can run the "mount/directoryname" command to load a file system. Each file system corresponds to an independent line, fields in each row are separated by spaces or tabs. At the same time, fsck, mount, umount and other commands all use this program.

2. The following is an example line of the/etc/fstab file:
Fs_spec fs_file fs_type fs_options fs_dump fs_pass
/Dev/hda1/ext2 defaults 1 1

Fs_spec-this field defines the device or remote file system where the file system to be loaded is located. For general local Block devices, the IDE device is generally described as/dev/hdaXN, X is the channel (a, B, or c) of the IDE device. N represents the Partition Number. SCSI device 1 is described as/dev/sdaXN. For NFS, the format is generally:, for example, 'knuth. aeb. nl :/'. For procfs, use 'proc' for definition.

Fs_file-this field describes the directory point to be loaded by the file system. For a swap device, this field is none. For a directory name containing spaces, 40 is used to indicate spaces.

Fs_type-defines the file system on the device. The common file types are ext2 (common file types for Linux devices) and vfat (fat32 format for Windows systems), NTFS, iso9600, etc.

Fs_options-specifying the file system to load the device is a specific parameter option that needs to be used, multiple parameters are separated by commas. Most systems can use "defaults" to meet their needs. Other common options include:

Option description
Ro loads the file system in read-only mode
Sync does not buffer write operations on the device, which can prevent file system damage during abnormal shutdown, but reduces the computer speed.
User allows normal users to load the File System
Quota forces disk quota limit on this file system
Noauto no longer uses the mount-a command (for example, when the system is started) to load the File System

Fs_dump-this option is used by the "dump" command to check how often a file system should be dumped. If no dump is required, set this field to 0.

Fs_pass-this field is used by The fsck command to determine the sequence of the file system to be scanned at startup. The value of the "/" pair of the root file system should be 1, other file systems should be 2. If the file system does not need to scan at startup, set this field to 0.

3. Modify/etc/fstab to automatically mount Windows partitions and display Chinese directories.
LABEL = // ext3 defaults 1 1
None/dev/pts devpts gid = 5, mode = 620 0 0
None/proc defaults 0 0
None/dev/shm tmpfs defaults 0 0
LABEL =/usr ext3 defaults 1 2
/Dev/hda9 swap defaults 0 0
# Add the following lines
/Dev/hda1/mnt/win_c vfat codepage = 936, iocharset = cp936 0 0
/Dev/hda5/mnt/win_d vfat codepage = 936, iocharset = cp936 0 0
/Dev/hda6/mnt/win_e vfat codepage = 936, iocharset = cp936 0 0

4. Support for some partition formats must be compiled to the kernel, such as NTFS.

Method 3: compile a shell script and run the mount command automatically upon startup.
First, log in as root. In/mnt, you need to have the win_c win_d win_e directories. If not, you can enter mkdir/mnt/win_c on the virtual terminal, mkdir/mnt/win_d, mkdir/mnt/win_e. Start the virtual terminal, enter vi mymount, and press insert to enter the following code:

#! /Bin/bash
Case $1 in
M)
Mount-o iocharset = cp936-t vfat/dev/hda1/mnt/win_c
Mount-o iocharset = cp936-t vfat/dev/hda5/mnt/win_d
Mount-o iocharset = cp936-t vfat/dev/hdc6/mnt/win_e
;;
U)
Umount-o iocharset = cp936-t vfat/dev/hda1/mnt/win_c
Umount-o iocharset = cp936-t vfat/dev/hda5/mnt/win_d
Umount-o iocharset = cp936-t vfat/dev/hda6/mnt/win_e
;;
Esac

Then Press Esc and enter wq to press Enter. The first line #! /Bin/bash specifies to execute this file using bash shell. case $1 in is the command line parameter. if it is m, the mount is started. If it is u, the mount is uninstalled. -o iocharset = cp936 can display the Chinese name. -t vfat: specifies that the file system type is VFAT in WINDOWS. win_c win_d win_e is the subdirectory under/mnt.

At this point, the program has been written, but it has no right to execute. We just need to enter the following command.

Chmod u + x mymount

In this step, you only need to enter./mymount m to mount the windows partition. If you add this line to the/etc/rc. d/rc. local file:

Sh./root/mymount m

After linux is restarted, windows partitions are automatically mounted.
Related Article

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.