Linux partitioning and mounting (mount command learning)

Source: Internet
Author: User
Tags ftp site
When a Windows system encounters a problem, you may need to reinstall the system. at this time, we often use the system disk to re-install the system on the C disk. the files on other disks are not affected by the re-installation of the system, this is one of the benefits of partitioning. Partitions are also required in Linux, but Linux... when a Windows system encounters a problem, you may need to reinstall the system. at this time, we often use the system disk to re-install the system on the C disk. the files on other disks are not affected by the re-installation of the system, this is one of the benefits of partitioning. Partitions are also required in Linux, but the representation of partitions in Linux is not the same as that in Windows. The following uses my computer as an example to describe the Linux system and mounting by describing the Linux startup process. (This article is suitable for beginners of Linux)
1. Basic concepts
1. partition concept
Partitioning is essentially a format of the hard disk. When we create a partition, we have set the physical parameters of the hard disk, specifying the storage location of the hard disk master boot record and boot record backup. For file systems and other operating systems to manage the hard disk, the required information is through the advanced formatting. Before installing the operating system and software, you must partition and format the hard disk before using the hard disk to save various information. Each partition is relatively independent. your operations on one partition will not affect the other partition.
Previously, we thought that drive C is the first partition, and drive D is the second partition. In fact, this is not appropriate. disk C and disk D are all disk symbols and are the names given by Windows. Before Windows is started, they are partitioned, not specific drive letters. The concept of this drive letter is inherent in Windows. that is to say, even if the Windows system is not installed on the hard disk, the partition on the hard disk still exists. Therefore, we can say that the drive letter is a software-level concept, and the partition is a hardware-level concept.
1.2.Linux file system organization
The structure of a Linux file system is called hierarchical directory structure. At the top of this structure is the root directory "/", and then other directories and subdirectories under this root directory. Like Windows, Linux uses "paths" to indicate the levels of files or directories in the file system. The path consists of multiple directory name strings separated by "/" and is divided into absolute paths and relative paths. In Linux, the so-called absolute path refers to the method that uses the root directory "/" as the starting point to represent the location of a file or directory in the system. the relative path is the starting point of the current directory, indicates the location of a file or directory in the file system. For example, enter pwd on the terminal (command for displaying the current location in Linux) and "/home/csc" on the terminal, which is the absolute path. If the csc folder contains a test folder, enter "cdtest" (or cd. /test), test or. /test is the relative path to the csc folder, where ". /"indicates the current directory, which can be omitted. The following describes some directories in Linux and their functions (for Linux partition and startup)
/: The top Directory of the Linux file system. All other directories are subdirectories of the Directory.
/Bin: short for Binary. it stores executable programs, such as cp and mv, and Shell, such as bash and csh. You should not place the Directory in a separate partition. Otherwise, these commands cannot be used in LinuxRescue mode.
/Boot: the kernel is stored here. the files required when the operating system starts, including vmlinuz and initrd. img, etc. if these files are damaged, the system may fail to start normally, so it is best not to make any changes.
/Dev: Directory of the device file. for example,/dev/sda indicates the first SCSI device, /dev/hda indicates the first IDE device (the representation of SCSI and IDE interface hard disks in Linux will be discussed later)
/Home: the home directory or FTP site directory of a common user, which is usually stored in the/home directory. (To learn about features in other default directories in Linux, see: http://www.xtzj.com/read-htm-tid-69582.html)
1.3.Linux mount point
Partitions in Windows are clear. a partition is a drive letter. If there is a compatible file system, the system can also read and write that partition. If it is an incompatible file system, Windows ignores this partition.
Linux puts everything under a "Big Tree. If you have another partition or hard disk, they will be "mounted" to the sub-directory of the branches, such as the/media or/mnt Directory. this sub-directory is a so-called mount point, you can mount a partition to any directory.
2. partition suggestions
Partitioning is related to the security and robustness of a system. when a system encounters a problem, we should fix the system with the smallest changes, so as to reduce unnecessary losses.
When installing Linux, I divide the hard disk into four partitions: The First Partition is mounted under the "/" directory, and the second partition is mounted under the "/boot" directory, the third partition is mounted under "/home", and the fourth partition is a Swap partition)
Reason:
(1) a root partition. The root partition is mounted to the "/" directory. Used to store system files.
(2) "/home" partition: this is the location of the user's home directory. its size depends on the number of users in your Linux system and the amount of data these users will store. When your system is damaged and needs to be re-installed, the files in the "/home" partition will not be affected.
(3) "/boot" partition: contains the kernel of the operating system and the files to be used during system startup. Independent mounting/boot allows multiple Linux instances to share one/boot. The size of the "/boot" directory is usually very small, about 20 MB. You can allocate a partition to/boot based on your hard disk space, but it should not be too large. Otherwise, it is a waste.
(4) one swap partition. Swap partitions are used to support virtual memory. If your computer memory is less than 16 MB, you must create swap partitions. Swap partitions are recommended even if you have more memory. The physical memory is less than or equal to 512 MB. we recommend that you allocate swap with 2 times the actual physical memory capacity. the physical memory is greater than 512 MB. we recommend that you allocate swap with physical memory and other capacity.
3. Linux startup process (take my computer as an example)
The system starts from reading grub. cfg (grub is a multi-operating system startup program from the GNU project. GRUB is the implementation of multi-boot specifications. it allows you to have multiple operating systems in your computer and select the operating system you want to run when the computer starts. GRUB can be used to select different kernels on the operating system partition, or to pass startup parameters to these kernels ). The location of the grub. cfg file is in the/boot/grub directory. (If a dual system is installed on the computer, you can modify the grub file to change the system startup sequence and wait time .) After opening a file, the file contains the following section:
Menuentry 'Ubuntu, Linux2.6.32-33-generic '-- class Ubuntu -- class gnu-linux -- class gnu -- class OS {
Recordfail
Insmodext2
Setroot = '(hd0, 8 )'
Search -- no-floppy -- fs-uuid -- set 089b3e37-bf9b-4811-94f8-b2f73fc313f6
Linux/vmlinuz-2.6.32-33-genericroot = UUID = abdb3fa2-45cd-447d-8cc5-83cf326195bd ro quiet splash
Initrd/initrd. img-2.6.32-33-generic
}
This is a standard ubuntu boot menu. the menuentry line shows the name of the project. insmod is a command in Linux and is used to load modules. The partition name is involved here, so let's take a look at it below:
Two representation methods for storage devices in Linux
(1) Two representation methods for the hard disk of the IDE interface
The entire hard disk in the IDE interface is expressed as/dev/hd [a-z] in Linux, such as/dev/hda,/dev/hdb ...... and so on. Another representation method is hd [0-n], where n is a positive integer, such as hd0, hd1, hd2... hdn; if there is only one hard disk in the machine, whether/dev/hda or/dev/hdb is listed (you can view the partition of the hard disk and hard disk by using the fdisk-l command, both are hd0; if two or more hard disks exist in the machine, the first hard disk/dev/hda is represented as hd0, the second hard disk/dev/hdb, HD1.
(2) Two representation methods for hard disk partitions of the IDE interface
The first method of hard disk partitioning:/dev/hd [a-z] X. X is a positive integer starting from 1. for example,/dev/hda1, /dev/hda2 ....., if the value of X is 1 to 4, it indicates the primary partition of the hard disk (including the extended partition). The Logical Partition starts from 5. for example,/dev/hda5 must be a logical partition.
The second hard disk partition representation method (hd [0-n], y). We have already mentioned that there are two representation methods for the entire hard disk, one is for/dev/hd [a-z], and the other is for hd [0-n]. for a hard disk partition, you must first confirm the hard disk on which it is located, then confirm the location of the disk. Therefore, we need to know a hard disk partition, in addition to/dev/hd [a-z], and where it is, after you confirm the partition in/dev/hd [a-z], you also need to confirm the location through X; the value of y is the X-1 in/dev/hd [a-z] X.
(3) Two representation methods for SATA and SCSI hard disks
The method is the same as that of the IDE interface, but the hd is replaced with sd.
The following example shows how to run the fdisk-l command on the terminal (to be viewed under the super user ):
Disk/dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sectorsize (logical/physical): 512 bytes/512 bytes
I/Osize (minimum/optimal): 512 bytes/512 bytes
Diskidentifier: 0x48000000
DeviceBoot Start End Blocks Id System
/Dev/sda1*1 13054 104856223 + 7 HPFS/NTFS
/Dev/sda2 13055 60802 383529250 + f W95 Ext 'd (LBA)
/Dev/sda5 13055 32635 157284351 7 HPFS/NTFS
/Dev/sda6 32636 52216 157284351 7 HPFS/NTFS
/Dev/sda7 55329 55578 1998848 82 Linux swap/Solaris
/Dev/sda8 55578 55640 498688 83 Linux
/Dev/sda9 55640 60802 41459712 83 Linux
/Dev/sda10 52217 55328 24996864 83 Linux
The first line in the file: Disk/dev/sda: 500.1 GB, 500107862016 bytes. This indicates that the machine has only one hard Disk device/dev/sda, and the size is 500 GB; the following is the partition of the hard disk. each partition has detailed information.
Here, we will all be a bit strange. since the IDE interface is hd, and both the SATA and SCSI interfaces are sd, why is there a line of "setroot =" (hd0, 8) '"code? Shouldn't it be "sd? For grub files, hard disks are expressed in hd and the disk number is calculated from 0, the partition number is calculated from 1 (grub2 is calculated from 1 and grub1 is calculated from 0). For Linux kernel, the IDE hard disk is expressed by hd, the SATA hard disk is represented by sd. the disk serial number is calculated from a and the partition number is calculated from 1. In my computer, the Linux system is Ubuntu10.04LTS and the grub file is grub2. Therefore, (hd0, 8) in the grub file represents the eighth partition on the first hard disk, that is, sda8.
Continue to explain the grub. cfg file above. the search command is used to find the kernel, which truly enters the Linux system boot process. The kernel is stored in the/boot directory. Linux in the following line is a command that tells the grub program to use the kernel given later, so the kernel named "vmlinuz-2.6.32-33-generic" is loaded into the memory, and read some necessary files for the partition "root = UUID = abdb3fa2-45cd-447d-8cc5-83cf326195bd. The last line of the command in the above code indicates: "/initrd. the img-2.6.32-33-generic file first constructs a "virtual" root file system in the memory, so that the kernel can load the necessary modules after detecting the hardware information. After grub's work ends, the Linux kernel will take over control of the computer and start the initialization phase. No root partition has been mounted so far. Then, the Linux system will read a file named fstab and execute the command line by line. Next, let's take a look at the fstab File (/etc/fstab ). Here are the fstab files on my computer:
#/Etc/fstab: static file system information.
#
# Use 'blkid-o value-s uuid' to print the universally uniqueidentifier
# For a device; this may be used with UUID = as a more robust way toname
# Devices that works even if disks are added and removed. See fstab (5 ).
#
#
Proc/proc nodev, noexec, nosuid 0 0
#/Was on/dev/sda10 during installation
UUID = abdb3fa2-45cd-447d-8cc5-83cf326195bd/ext4 errors = remount-ro 0 1
#/Boot was on/dev/sda8 during installation
UUID = 089b3e37-bf9b-4811-94f8-b2f73fc313f6/boot ext4 defaults 0 2
#/Home was on/dev/sda9 during installation
UUID = 11ec48a8-5ca9-4e39-9bff-fd56b811d58e/home ext4 defaults 0 2
# Swap was on/dev/sda7 during installation
UUID = 2c80ec4a-769c-40c5-8d87-39a2332661cfnone swap sw 0 0
# The line starting with "#" is a comment, indicating the text. it is not executed when the command is executed.
Partitions are mounted from top to bottom in sequence in linux. The first line that works is proc. for details about proc, see the http://www.2cto.com/ OS /201202/119553.html.
First, Mount sda10 to "/", which is the first root partition to be mounted in linux. then, Mount sda8 to "/boot ", when sda9 is mounted to "/home" and sda7 is mounted to the swap partition, this swap partition is a bit special because it is not "affiliated" to/but used independently.
So far, all partitions used in Linux have been mounted. You can use the system.
4. manually Mount partitions
Someone may ask, what should I do when I need to use partitions in Windows? Can I mount Windows partitions in Linux? The answer is yes. if you are using Ubuntu on the desktop and dual systems, click "location"> "computer" in Linux to list partitions in Windows, right-click and select "Mount". by default, it is mounted to the media directory. we can use commands to set the partition to be mounted and the location to be mounted. for example, I want to mount the/dev/sda5 partition. the file system format is NTFS. mount it to the/home/csc/music directory. The command is as follows:
Mount/dev/sda5/home/csc/music
Cd/home/csc/music
Ls
Run the preceding command to view the files in the sda5 partition in the music directory.
The unmount command is also very simple. execute the command umount/dev/sda (or/home/csc/music) and then OK.
 
References:
Linux mount-mount: http://forum.ubuntu.org.cn/viewtopic.php? T = 257333
Linuxproc: http://dqw19880428.blog.163.com/blog/static/2051131620093144735924/
Linux hard disk partition details: http://blog.csdn.net/freexploit/article/details/961330
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.