Linux Disk partitioning detailed

Source: Internet
Author: User
Tags disk usage

If you want to learn about Linux partitions, be sure to read this article carefully. For starters, Linux partitioning doesn't look like windows.

In the process of learning Linux, installing Linux is the first hurdle for every beginner. In the middle of this process, the biggest confusion is to partition the hard disk. Although, now various distributions of Linux have provided a friendly graphical interface, but many people still feel the impossible. The main reason for this is that it is unclear about the partitioning rules for Linux and how to use the most efficient partitioning tool ―fdisk below.

First of all, we want to make some preliminary understanding of the basic concept of hard disk partition, the partition of hard disk is divided into basic partition (primary partion) and expansion partition (extension partion), the sum of basic partition and expansion partition can not be more than four. and basic partitions can be used immediately but cannot be partitioned. The expansion partition must be partitioned before it can be used, meaning it must be partitioned two times. So what is the partition going to be divided into? It is a logical partition (logical partion), and there is no limit to the number of logical partitions.

In the Linux installation when learning the Linux installation of the notebook when the notes, temporarily recorded, for their own inspection, virtual machine A total of 12GB.

First Partition

First Partition:/boot fixed size, 100M, forced to primary partition, boot program.
Second partition:/root directory 4000M
The third partition:/usr 4500M, equivalent to Windows C Disk program Files, installed software.
Fourth partition:/var 1500M, where logs are stored, users log in, read disk log.
Fifth partition: Select the file system type swap,1200m. Memory replacement space, virtual memory.
Sixth partition:/www 500M, put the website. It's a random addition.

Where the swap partition in the real memory between the 1~1.5 is appropriate, the larger the physical memory, can be set relatively small;

For users who are accustomed to using DOS or Windows, there are several partitions that have several drives, and each partition obtains a letter identifier, which can then be used to specify the files and directories on this partition, their file structure is independent and very well understood. But for those who started Red Hat Linux, it was a bit annoying. Because there are several partitions for Red Hat Linux users, which directory to use, it boils down to just one root directory, a separate and unique file structure. Each partition in Red Hat Linux is used to form part of the entire filesystem because it uses a processing method called "Loading", which contains a full set of files and directories in the entire file system, and links a partition to a directory. At this point a partition to be loaded will make its storage space available in one directory.

For Windows users, the operating system must be installed in the same partition, it is commercial software! So there's no room for you to choose! For Red Hat Linux, you have a big choice, you can put the system files in several areas (you have to specify the loading point), you can also be installed in the same partition (loading point is "/").

The following two aspects of the beginning, to explain the problems that beset everyone.

Partitioning rules for Linux

    1. Device Management

In Linux, every hardware device is mapped to a system file, which is no exception for IDE or SCSI devices such as hard drives, optical drives, and so on. Linux assigns a variety of IDE devices to a file composed of HD prefixes, and for various SCSI devices, a file consisting of an SD prefix is assigned.

For IDE hard drives, the drive identifier is "hdx~", where "HD" indicates the type of device on which the partition is located, which refers to the IDE hard disk. "X" is the disk number (A is the base disk, B is the base slave, C is the secondary primary, D is the secondary slave), "~" represents the partition, the first four partitions are represented by the numbers 1 to 4, they are the primary partition or the extended partition, and the logical partition starts at 5. Example, Hda3 is represented as the third primary or extended partition on the first IDE hard disk, and HDB2 is represented as the second primary or extended partition on the second IDE hard disk. The SCSI hard disk is identified as "sdx~", the SCSI hard disk is "SD" to indicate the type of device the partition is located, the rest is the same as the representation of the IDE hard disk, do not say more.

For example, the first IDE device, Linux is defined as HDA, and the second IDE device is defined as a HDB; SCSI devices should be SDA, SDB, SDC, and so on.

    1. Number of partitions

To partition, you must operate on every hardware device, which can be an IDE hard disk or a SCSI hard disk. For each hard disk (IDE or SCSI) device, Linux allocates a sequence number from 1 to 16, which represents the partition number above the hard drive.
For example, the first partition of the first IDE hard disk, which is mapped under Linux, is hda1, and the second partition is called Hda2. For SCSI hard drives, it is sda1, sdb1 and so on.

    1. The role of each partition

As specified in Linux, each hard disk device can have up to 4 primary partitions (which contain extended partitions), any one of the extended partition will occupy a primary partition number, that is, on one hard disk, the primary partition and the extended partition is a total of 4.
For earlier DOS and Windows (earlier versions of Windows 2000), the system admits only one primary partition, which can be further refined by adding logical disk characters (logical partitions) on the extended partition.

The primary partition is used by the computer to boot the operating system, so that each operating system's boot, or boot program, should be stored on the primary partition.

This is the biggest difference between the primary partition and the extended partition and logical partition.

The best example is the designation of the primary partition when we specify the installation of bootloader to boot Linux.
LINUX specifies that the primary partition (or extended partition) takes up the first 4 numbers from 1 to 16th numbers. As an example of the first IDE hard disk, the primary partition (or extended partition) occupies hda1, Hda2, Hda3, HDA4, while the logical partition occupies 12 numbers, such as Hda5 to Hda16.
As a result, there are up to 16 partitions per drive in Linux.
For logical partitions, Linux specifies that they must be built on extended partitions (and so on DOS and Windows systems), not on primary partitions.
Therefore, we can see that the extended partition can provide a more flexible partitioning mode, but it cannot be used as the boot of the operating system. By removing the differences between the various partitions above, we can simply treat them equally.

    1. Partition metrics

For each Linux partition, the size of the partition and the type of partition are the most important indicators. The size of the capacity of the reader is easy to understand, but the type of partitioning is not so easy to accept. The type of partition specifies the format of the file system above the partition.
Linux supports a variety of file system formats, including our familiar FAT32, FAT16, NTFS, HP-UX, and various Linux-specific Linux native and Linux swap partition types.
In a Linux system, these different types of partitions can be distinguished by partition type numbers. Various types of numbers will be introduced when describing how Fdisk is used.

5 Common partitions

/boot partition, which contains the kernel of the operating system and files to be used in the boot system, it is necessary to build this partition, because most of the current PC is limited by the BIOS, and if there is a separate/boot boot partition, even if the main root partition has a problem, The computer will still be able to boot. The size of this partition is approximately between 50MB-100MB. However, if you want to use Lilo to start the Red Hat Linux system, the partition containing/boot must be completely below the cylinder 1023. Because the data lilo cannot be read after 8GB, Red Hat Linux is installed within the 8GB area.
/usr partition, where the Red Hat Linux system stores the software and, if possible, give it the maximum amount of space.
/home partition, which is the location of the username and the size of the partition depends on how many users there are. If it is a multi-user common use of a computer, this partition is completely necessary, and the root user can also be very good control of ordinary users to use the computer, such as the user or user groups to implement limited use of hard disk, limit the average user access to which files. In fact, a single user also has the need to establish this partition, because there is no such partition, then you can only be the root of the user login system, this is dangerous, because the root users have absolute access to the system, but once you have the system by mistake, trouble will come.
/var/log partitions, which are system logging partitions, if this separate partition is set up, so that even if there is a problem with the system's log files, they do not affect the primary partition of the operating system.
/tmp partition, used to store temporary files. This is necessary for multi-user systems or Web servers. This allows the other parts of the file system to be secure even if the program is running with a large number of temporary files, or if the user is doing something wrong with the system. Because this part of the filesystem still has read and write operations, it usually has problems faster than the rest of the system.
/bin partitions, storing standard system utilities.
/dev partition to store the device files.
/OPT partition, storage of optional installed software.
/sbin partitions, storing standard system management files.

Several commonly used partitions are described above, in general we need a swap partition, A/boot partition, A/USR partition, A/home partition, and a/var/log partition. Of course, there are no rules, it's entirely up to you. But remember to have at least two partitions, one swap partition, one/partition.

Fdisk using the detailed

The following describes the use of Fdisk, to consolidate the above learned about the Linux partition knowledge.
Fdisk is the most commonly used partitioning tool in various Linux distributions and is a partitioning tool defined as an Expert level, which makes beginners a bit intimidating.
1. Fdisk parameter description
When you run Fdisk, you first come to the Welcome interface, where you manipulate fdisk by entering command parameters in this interface. The user prompts to type "M" to display a description of each parameter of the Fdisk command. The reader can see that Fdisk has a lot of parameters, but often use a few, if the reader skillfully grasp these parameters can be fluent in the use of Fdisk, Linux hard disk partition. We will briefly describe the meaning of each parameter, and then describe several key parameters in detail.
When the user partitions in Linux, the most commonly used parameters are D, L, M, N, p, Q, T, W, etc.

2. Partitioning with Fdisk

In the Linux partitioning process, the disk partition table information is typically displayed by the P parameter, and then the future partitions are determined based on the information. If you want to completely change the partition format of the hard disk, you can delete the existing hard disk partition by the D parameter.

such as D1,D2. After deletion, the new partition can be added by the n parameter. When "n" is pressed, we can see the new partition. Choose whether to create a new partition type, a primary or an extended partition, and then select either P or E. Their differences are explained in the above. Then the size of the partition is set. Note that if there is an extended partition on the hard disk, it can only increase the logical partition, cannot increase the expansion partition, when the partition is added, the type is the default Linux Native, if you need to change some of these partitions to other types, such as Linux Swap or FAT32, etc., Can be changed by command T, when you press "T" to change the partition type, the system will be prompted to change which partition, and change why type (if you want to know the type of partition supported by the system, type L). Linux supports the partition type number and its corresponding partition type, you can refer to table 2 (this information can be obtained with the L command). After you have changed the partition type, you can press "W" to save and exit. If you do not want to save, then you can choose "Q" to exit directly.

FDISK is a powerful disk manipulation tool from the Util-linux package, and we'll just say how he looks at the disk partition table and the partition structure; parameter-L, through the-l parameter, can get the number of all the disks in the machine, also can list all the disk partition situation;

[email protected] beinan]# fdisk-l
disk/dev/hda:80.0 GB, 80026361856 bytes
255 heads, Sectors/track, 9729 cylinders
Units = Cylinders of 16065 * 8225280 bytes

Device Boot Start End Blocks Id System
/DEV/HDA1 * 1 765 6144831 7 Hpfs/ntfs
/dev/hda2 766 2805 16386300 C W95 FAT32 (LBA)
/dev/hda3 2806 7751 39728745 5 Extended
/dev/hda5 2806 3825 8193118+-up Linux
/dev/hda6 3826 5100 10241406-Up Linux
/dev/hda7 5101 5198 787153+, Linux Swap/solaris
/dev/hda8 5199 6657 11719386-up Linux
/DEV/HDA9 6658 7751 8787523+-up Linux

In the above blocks, represents the size of the partition, blocks unit is a byte, we can convert to M, such as the first partition/dev/hda1 size if converted to m, it should be 6144831/1024=6000m, that is, about 6G, in fact, no such trouble, A cursory look at the decimal point to move forward three bits, you know how much volume;
The file system represented by system, such as/DEV/HDA1, is in NTFS format;/dev/hda2 represents a file system in FAT32 format;.

In this case, we would like to pay special attention to the/DEV/HDA3 partition, which is the extended partition; he has a logical partition under the bread, in fact, the partition is equivalent to a container, from her own hda5,hda6,hda7,hda8,hda9;

We also noticed a little, why not hda4? Why is HDA4 not included in the extended partition? A disk has a maximum of four primary partitions, the hda1-4 is the primary partition, the HDA4 cannot be included in the extended partition, and the extended partition is also the primary partition, in this case, there is no HDA4 this partition, of course, we can set one of the partitions as the primary partition, but I did not do so when the partition;

To get a closer look, let's see if this disk still has space. Hda1+hda2+hda3= actually already partitioned the volume, so we can calculate this hda1+hda2+hda3=6144831+16386300+39728745 = 62259876 (b), convert to M units, the decimal point moves three bits forward, So the partition that has been partitioned is about 62259.876 (m), in fact the most accurate calculation 62259876/1024=60800.67 (m), and this disk size is 80.0 GB (80026361856byte), In fact, the actual size is 78150.744 (M); Through our series of calculations, we can conclude that the disk currently has a space to use, about 18G unpartitioned space;

We can also specify fdisk-l to view the partition of one of the hard disks;

[email protected] beinan]# fdisk-l/DEV/SDA

disk/dev/sda:60.0 GB, 60011642880 bytes
Heads, Sectors/track, 57231 cylinders
Units = Cylinders of 2048 * 1048576 bytes

Device Boot Start End Blocks Id System
/DEV/SDA1 1 57231 58604528 Linux

As you can tell by the above, there is only one partition in the/DEV/SDA disk, and the usage is almost hundred percent;

We can also check out the/dev/hda

[email protected] beinan]# fdisk-l/dev/hda

Try it yourself?

We can also view all disks and partitions in the current machine by: cat/proc/partitions

DF Command;
DF is from the Coreutils software package, the system is installed, it comes with, we can use this command to see the disk usage and the location of the file system is mounted;

Example:

[email protected] beinan]# DF-LH

Filesystem capacity used% mount point available

/dev/hda8 11G 6.0G 4.4G 58%/
/dev/shm 236M 0 236M 0%/dev/shm
/DEV/SDA1 56G 22G 35G 39%/mnt/sda1

As we can see, the system is installed in/dev/hda8, and a 56G disk partition/dev/sda1 mounted in/mnt/sda1;

Other parameters refer to man DF

Through the above two aspects of learning, I believe that for beginners, the partition is no longer a stumbling block in the Linux advanced.

Transferred from: http://www.jb51.net/LINUXjishu/11011.html

Linux Disk partitioning detailed

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.