Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Disk partitions that function for linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

The role of linux disk partition, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

In the process of learning Linux, installing Linux is the first threshold for every beginner. In the process, the biggest confusion is partitioning the hard drive. Although various distributions of Linux have provided a friendly graphical interface, many people still feel that they don't know how to start. The main reason for this is that we are not clear about the partition rules of Linux and the use of Fdisk, the most effective partition tool under it.

First of all, we need to have some preliminary understanding of the basic concept of hard disk partition. Hard disk partition is mainly divided into basic partition (primary partion) and extended partition (extension partion). The sum of the number of basic partition and extended partition can not be more than four. And the basic partition can be used immediately but can no longer be partitioned. The extended partition must be partitioned again before it can be used, that is to say, it must also be partitioned twice. So what is further divided by the extended partition? It is a logical partion, and there is no limit to the number of logical partitions.

For users accustomed to using dos or windows, there are several drives for every partition, and each partition gets a letter identifier, and then you can choose this letter to specify files and directories on that partition. Their file structures are independent and easy to understand. But for these new red hat linux users, it can be a little annoying. Because for red hat linux users, no matter how many partitions are assigned to which directory to use, it boils down to only one root directory, a separate and unique file structure. Each partition in red hat linux is used to form part of the entire file system because it uses a method called "load". Its entire file system contains a complete set of files and directories, and associates a partition with a directory. At this point, a partition to be loaded will make its storage space available in a directory.

For windows users, the operating system must be installed in the same partition, it is commercial software! So you have no choice! For red hat linux, you have a large choice, you can divide the system files into several sections (you must specify the load point), or you can install them in the same partition (the load point is "/").

Let's start with these two aspects to explain the problem that bothers you.

Zoning rules for Linux

1. Equipment management

In Linux, every hardware device is mapped to a system file, and IDE or SCSI devices such as hard drives and optical drives are no exception. Linux assigns a file of hd prefixes to various IDE devices, and a file of sd prefixes to various SCSI devices.

For ide hard drives, the drive identifier is "hdx~", where "hd" indicates the type of device in which the partition is located, and here refers to the ide hard disk. "x" is the disk number (an is the basic disk, b is the basic slave disk, c is the secondary master disk, d is the secondary slave disk), and "~" represents the partition. The first four partitions are represented by the numbers 1 to 4. They are primary or extended partitions and have been logical partitions since 5. For 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. For scsi hard drives are marked as "sdx~", scsi hard drives use "sd" to indicate the type of device where the partition is located, and the rest are represented in the same way as ide hard drives.

For example, the first IDE device, Linux is defined as hda;, the second IDE device is defined as hdb;, and so on. The SCSI devices should be sda, sdb, sdc and so on.

two。 Number of partitions

To partition, you have to operate for each hardware device, which could be an IDE hard drive or a SCSI hard drive. For each hard disk (IDE or SCSI) device, Linux is assigned a serial number from 1 to 16, which represents the partition number on the hard disk.

For example, the first partition of the first IDE hard disk is mapped to hda1 under Linux, and the second partition is called hda2. For SCSI hard drives are sda1, sdb1, etc.

3. The role of each division

In Linux, each hard disk device can have up to four primary partitions (including extended partitions), and any extended partition must occupy a primary partition number, that is, in a hard disk, there are up to four primary and extended partitions.

For earlier DOS and Windows (versions prior to Windows 2000), only one primary partition was recognized, and the partition could be further refined by adding a logical drive letter (logical partition) to the extended partition.

The role of the primary partition is for the computer to boot the operating system, so the boot of each operating system, or bootstrap, should be stored on the primary partition.

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

When we specify the bootloader that installs the boot Linux, it should be specified on the primary partition, which is the best example.

Linux specifies that the primary partition (or extended partition) occupies the first four numbers from 1 to 16. Take the first IDE hard disk as an example, the primary partition (or extended partition) occupies hda1, hda2, hda3, hda4, while the logical partition occupies 12 numbers from hda5 to hda16.

Therefore, each hard drive under Linux has a total of up to 16 partitions.

For logical partitions, Linux states that they must be built on extended partitions (as well as on DOS and Windows systems), not primary partitions.

Therefore, we can see that extended partitions can provide a more flexible partition mode, but cannot be used as a boot for the operating system. Apart from the differences in the various partitions above, we can simply treat them equally.

4. Zoning index

For each Linux partition, the size and type of partition are the most important indicators. The size of capacity is easy for readers to understand, but the type of partition 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 the familiar FAT32, FAT16, NTFS, HP-UX, and various Linux-specific Linux Native and Linux Swap partition types.

In Linux systems, these different types of partitions can be distinguished by partition type numbers. Various types of numbers will be introduced when introducing how to use Fdisk.

5 commonly used partitions

/ boot partition, which contains the kernel of the operating system and the files used to boot the system, it is necessary to build this partition, because most PCs are currently limited by bios, and if there is a separate / boot boot partition, the computer can still boot even if there is a problem with the main root partition. The size of this partition is about between 50mb-100mb. But if you want to boot the red hat linux system with lilo, the partition with / boot must be completely below cylinder 1023. And because the data after 8gb cannot be read by lilo, red hat linux should be installed within the area of 8gb.

/ usr partition, which is the place where the red hat linux system stores software, should be allocated the maximum space if possible.

The / home partition, which is where the user's home directory is located, depends on how many users there are. If multiple users share a computer, this partition is absolutely necessary, and root users can also well control the use of computers by ordinary users, such as limiting the use of hard drives to users or user groups. restrict which files Putong users can access, etc. In fact, it is necessary for a single user to establish this partition, because without this partition, you can only log in to the system as the root user, which is dangerous because the root user has absolute right to use the system. But once you misoperate the system, trouble will come.

/ var/log partition, is the system log partition, if you set up this separate partition, so that even if there is a problem with the system's log files, they will not affect the primary partition of the operating system.

/ tmp partition to store temporary files. This is necessary for multi-user systems or web servers. In this way, even if a large number of temporary files are generated while the program is running, or even if the user makes the wrong operation on the system, the rest of the file system is still safe. Because this part of the file system still suffers from reading and writing, it usually causes problems faster than other parts.

/ bin partition, which holds standard system utilities.

/ dev partition to store device files.

/ opt partition to store optional installed software.

/ sbin partition, which stores standard system management files.

Several commonly used partitions are described above. Generally speaking, 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 and one / partition.

Detailed explanation of Fdisk usage

Here's how to use Fdisk to consolidate what you've learned about Linux partitioning.

Fdisk, the most commonly used partitioning tool in various Linux distributions, is defined as an Expert-level partitioning tool, which is a bit prohibitive to beginners.

1. Fdisk parameter description

When you run Fdisk, the first thing that catches your eye is the welcome interface, in which users manipulate Fdisk by entering command parameters. The user can display a description of each parameter of the Fdisk command by prompting for "m". Readers can see that Fdisk has many parameters, but only a few are often used. If readers are proficient in these parameters, they can use Fdisk fluently to partition Linux's hard disk. We first briefly introduce the meaning of each parameter, and then explain several key parameters in detail.

When users partition in Linux, the most commonly used parameters are d, l, m, n, p, Q, t, w and so on.

two。 Partition with Fdisk

In the process of Linux partitioning, the information of the hard disk partition table is first displayed through the p parameter, and then the future partition is determined according to the information. If you want to completely change the partition format of the hard disk, you can delete the existing hard disk partitions one by one with the d parameter.

For example, D1 and D2. Once deleted, the new partition can be added with the n parameter. When we press "n", we can see the new partition. Here you want to select the new partition type, whether it is a primary partition or an extended partition, and then select p or e. The difference between them has been explained above. Then set the size of the partition. It should be noted that if there are extended partitions on the hard disk, you can only add logical partitions, not extended partitions. When adding partitions, 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, you can change them with the command t. When you press "t" to change the partition type, the system will prompt which partition to change. And change the type (if you want to know the partition types supported by the system, type l). For the partition type numbers supported by Linux and their corresponding partition types, refer to Table 2 (this information can be obtained with the l command). After changing the partition type, you can press "w" to save and exit. If you don't want to save, you can choose "Q" to exit directly.

Fdisk is a powerful disk operation tool, from the util-linux software package, we only say here how to view the disk partition table and partition structure; parameter-l, through the-l parameter, you can get the number of all disks in the machine, and also list all disk partitions.

The code is as follows:

[root@localhost beinan] # fdisk-l

Disk / dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device BootStartEndBlocksId System

/ dev/hda1* 1765 6144831 7 HPFS/NTFS

/ dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)

/ dev/hda32806 7751 39728745 5 Extended

/ dev/hda52806 3825 8193118 + 83 Linux

/ dev/hda63826 5100 1024140683 Linux

/ dev/hda75101 5198787153 + 82 Linux swap / Solaris

/ dev/hda85199 6657 1171938683 Linux

/ dev/hda96658 7751 8787523 + 83 Linux

In the above Blocks, it represents the size of the partition. The unit of Blocks is byte, and we can convert it to M. For example, if the size of the first partition / dev/hda1 is converted to M, it should be 6144831 1024mm 6000m, that is, about 6G. In fact, it is not so troublesome. Take a rough look at moving the decimal point forward three places, you will know how big the approximate volume is.

System represents a file system, such as / dev/hda1 is in NTFS format; / dev/hda2 is a file system in fat32 format;.

In this case, we should pay special attention to the / dev/hda3 partition, which is an extended partition; it contains a logical partition, which is actually equivalent to a container; her subordinate is hda5,hda6,hda7,hda8,hda9

We also noticed that there is no hda4. Why is hda4 not included in the extended partition? A disk has at most four primary partitions; hda1-4 counts as the primary partition; hda4 cannot be included in the extended partition, and the extended partition is also counted as the primary partition; in this case, there is no hda4 partition, of course, we can set one of the partitions as the primary partition, but I didn't do it at that time.

Let's take a closer look at the statistics and see if there is still room on this disk. Hda1+hda2+hda3= actually has the volume of the partition, so we can calculate hda1+hda2+hda3=6144831+16386300+39728745 = 62259876 (b), converted into M units, and the decimal point moves forward three places, so the partition that has been divided so far occupies a volume of about 62259.876 (M), in fact, the most accurate calculation is 62259876 GB (M); and the disk size is 80.0 GB (80026361856byte), in fact, the actual size is 78150.744 (M). Through a series of calculations, we can conclude that there is still room for use on this hard disk; there is still about 18G of unpartitioned space.

We can also specify fdisk-l to see the partition of one of the hard drives

The code is as follows:

[root@localhost beinan] # fdisk-l / dev/sda

Disk / dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Device BootStartEndBlocksId System

/ dev/sda11 57231 5860452883 Linux

As you can see from the above, there is only one partition on the / dev/sda disk; the usage is almost 100%.

We can also check / dev/hda 's

The code is as follows:

[root@localhost beinan] # fdisk-l / dev/hda

Try it yourself?

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

Df command

Df comes from the coreutils software package and comes with it when the system is installed. We can check the disk usage and the location where the file system is mounted through this command.

For example:

The code is as follows:

[root@localhost beinan] # df-lh

Filesystem capacity used available used mount point

/ dev/hda8 11G 6.0G 4.4G 58% /

/ dev/shm 236M0 236M0% / dev/shm

/ dev/sda1 56G22G35G 39% / mnt/sda1

We can see that the system is installed in / dev/hda8; there is also a 56g disk partition / dev/sda1 mounted in / mnt/sda1

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report