Operation and maintenance veteran talks about the method of partitioning Linux system in production scenario


How to partition Linux system in production scenario?


When we buy a house, we will consider one room and one hall, two rooms and one hall, or three rooms and two halls…! How to choose it depends on

Money in hand and the population of the family.

In the same way, the server operating system is divided into three zones and four zones. Whether to divide them into / home / var or not depends on our business requirements, operation and maintenance specifications or the preferences of operation and maintenance leaders.

There are more points and less points. There may be some problems in different business scenarios (LVM can solve this problem, but it has its disadvantages, or some scenarios add to the cake).

Before describing this problem, let’s briefly talk about the functions of basic partition / boot partition, swap partition and / or root partition.

The role of / boot partition, swap partition and / root partition in Linux

/Boot boot partition to store boot files and Linux kernel.

Boot file: used to determine which operating system or kernel you need to boot.

Kernel: simply speaking, the bridge between program and hardware, you use the application program to control the whole computer through the kernel.

The general setting for partition: 100-200m. In the formal environment, the total size of Linux boot file and kernel is less than 100m.

/Root partition, as the root directory of the entire file system, the hard disk is divided into several zones. All documents

Will be in the root directory. In windows, we divide the hard disk into C: D: e: etc., and then

Store system, program, game, song, etc.

It’s different under Linux: no matter how many areas you divide, you have to give them a separate name.

Then use the directory with the names of / data, / music, / study to mount the partition.

Provide access to their respective directories, which are treated exactly the same as directories.

Under Linux, the hard disk looks like a partition. The root of this partition is /.

General setting for partition: after dividing the above two zones, the rest will be given to the root partition.

In the production scenario of large-scale (more than 200 servers) website operation and maintenance, the partition of ordinary servers is divided into the above three areas.

Wrong choice.

The advantages and disadvantages of / boot partition, swap partition and / (root) partition are as follows:


It is simple and easy to use. It can be installed and deployed in batches, and it will not be divided into multiple partitions. Some partitions are full.

Some partitions have a lot of space left that can not be used (LVM will not be described here first).

(in fact, it can also be used. Fdisk can delete and rebuild partitions, and then expand them, but the process is complicated.

Interested friends can communicate alone.


If the system breaks down, data backup is troublesome when the system is reinstalled because the data is in / (root partition).

If you add / usr, / home, / VAR and other partitions, the system is broken.

You can install the system directly in / (root partition) without destroying the data of other partitions. Of course, as I said just now, if it is a cluster node and there is no need to back up data, the advantages of the partition scheme in this paper are very obvious. There is no need to worry about the problem that one partition is full and other partitions cannot be used.

How to partition Linux system in production environment?

Here are my answers to the topic for your reference. It only represents the old boy’s personal views.

There are a lot of students and friends here, how to partition when installing Linux system in the production environment?

For example, the above / boot partition, swap partition and / (root) partition are basic. In addition, do you want to partition / home / var or even separate the data?

In fact, there is no fixed answer to this question. So you are not willing to give us the answer, so I will go into details.

Tip: the above partition method can be based on raid. We will talk about how to select raid for servers with different roles in the production scenario next time.

Additional: introduction to other common partition directories

/Home the home directory of ordinary users is stored by default;

/Usr is the directory where the system stores programs, such as commands, help files, etc. There are many files and directories in this directory. When we install a software package officially provided by the Linux distribution, most of it is installed here. If the server configuration file is involved, the configuration file will be installed in the / etc directory. /The usr directory includes the font directory / usr / share / fonts, help directory / usr / share / man or / usr / share / doc, and the executable directory / usr / bin or / usr / local / bin or / usr / X11R6 / bin for ordinary users, such as / usr / SBIN or / usr / X11R6 / SBIN or / usr / local / SBIN, and the program header file storage directory / usr / include.

/The content of the directory var changes frequently. As you can see from the name, it can be understood as the abbreviation of variable. There is / var / log under / VAR, which is used to store system logs. /The var / www directory defines the storage directory of Apache server site; / var / lib is used to store some library files, such as mysql, and the storage location of MySQL database;


Old boy survey collection:

How do you think it is better to partition the Linux system in the production environment? Please send me your answer by TXT (time subject name. Txt).

I’ll do a survey. Interested rookies and junior operation and maintenance friends can cooperate, and those who cooperate will be rewarded.

Reward an article: old bird talks about how to partition Linux system in production scenario? Ha-ha.

The method of dividing the collected net friends and students

(a) 20110802 Linux partition method – kanga.txt

Partition uses ext3 format

/Boot 200m forced primary partition

/1.5 to 2 times of swap memory is mandatory

/The remaining space is mainly distributed to the root

Comments of the old boy:

Generally, the partition scheme is a general partition scheme, which is suitable for general enterprise server selection. Especially

RS under load balancing.


GENERAL(511429563) 2011-8-2 9:43:04

Do you want to take / home, / usr out separately and divide it according to the purpose of the server? As the old boy said,

Your family needs two rooms and three halls. Maybe his family needs three rooms and one hall! individual opinion

Comments of the old boy:





/boot 64M

/ directory 10G

/HOME 100G

Our 3G / DOS is used for backup / directory server, of course, this partition is not used!


Not enough swap memory! Not a lot of local production data!

Comments of the old boy:

Generally speaking, it’s meaningless to separate DOS, and there’s no purpose to separate / home. No problem without swap, but once

Run out of memory and face the risk of direct hang up. It is recommended to reduce the number of points.


Invest love in hope 10:45:44

In my feeling, division, according to reality,

Generally, there are the following sections






6、 /var


The most important points are as follows

First, does the host often compile and install software?

If compiling and installing, I will put the / usr directory out separately to make a partition, and define the size myself (slightly larger according to the actual budget).

Second / var partition, log

The general log and temporary directory are all under this partition, so it is recommended to make a larger space and log separately, which is very valuable.

Third custom backup partition

Generally, / DOS is used as the backup partition, and its size is about 5g, or as the old saying goes,

The fourth / home partition,

This partition is also very important. About half of the space should be allocated to this partition. All the user data is here.

Fifthly, the partition of / swap is based on configuration. If large memory can be avoided, small memory is necessary.

Comments of the old boy:

In fact, the necessity (the reason why we have to do this) is not strong.


Saink classmate

Production environment of the company

General server (original production environment, unchanged)

/boot 100M

Swap 0 ~ 0.5 times of memory

/All the remaining space/

16g memory of Oracle server (directly managed by its own installation)

/boot 100M

swap 17G

/Remaining space

TMPFS gave 14000m manually, the original default is 8g

I think the general server

/boot 200M

Swap 1-2 times. Now the server memory is relatively large. The swap partition of a server larger than 8g is a little larger than the memory.

If the memory is small, it can be used 1.5-2 times. The swap partition can be used as little as possible. The more it is used, the performance of the system will be reduced.

All the remaining space/

Comments of the old boy:

Basically agree with the partition method of saink, but DB server is better to separate only.

As many friends have said, the division is not fixed, but how to divide it. The old man here just gives you a little experience of my many years for your reference. In actual work, you should lead according to your needs.