Table of Contents
1. Common sense you should know about Linux system partition
Home Operation and Maintenance Linux Operation and Maintenance Which Linux partition is the primary partition?

Which Linux partition is the primary partition?

Mar 09, 2023 am 09:43 AM
linux

The number "hda1-4" in Linux is the primary partition; the primary partition is mainly used to start the operating system. It mainly stores the startup or boot program of the operating system. The "/boot" partition It is best to put it on the main partition.

Which Linux partition is the primary partition?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Which is the primary partition in Linux?

linux system disk management (primary partition and logical partition)

Summary: Linux system disk management primary partition and logical partition


1. Common sense you should know about Linux system partition

  • Hard disk partition is essentially the A format of the hard disk before the hard disk can be used to save various information. When creating a partition, the physical parameters of the hard disk have been set and the hard disk master boot record (Master Boot Record, generally referred to as MBR) has been specified. and the storage location of the boot record backup.
  • MBR Overview: The full name is Master Boot Record, which is the master boot record of the hard disk; it is a boot section located at the front of the disk. (Loader) code. It is responsible for determining the legality of partitions and locating partition boot information when the disk operating system (DOS) reads and writes the disk. It is generated by the disk operating system (DOS) when initializing the hard disk.
    -The master boot program is the master boot record (MBR) (occupies 446 bytes)
    can be found in the FDISK program. It is used to transfer system control to the user-specified file when the hard disk starts and is stored in the partition table. A registered operating system.
    -Disk partition table entry (DPT, Disk Partition Table)
    consists of four partition table entries (16 bytes each).
    is responsible for describing the partition situation on the disk. Its content is determined by the disk media and the user when using FDISK to define the partition. (Details omitted)
    -End mark (occupies 2 bytes) (magic number)
    The value is AA55. When stored, the low byte is first and the high byte is last, that is, it looks like 55AA (hexadecimal ).
  • Partition number: primary partition 1-4, logical partition 5...
    ## LINUX regulations: Logical partitions must be built on extended partitions, not on primary partitions
##Partition functions:
    ①Primary partition: Mainly It is used to start the operating system. It mainly stores the startup or boot program of the operating system. The /boot partition is best placed on the main partition;
  • ② The extended partition cannot be used, it is only used as a container for logical partitions If it exists, first create an extended partition and create a logical partition on top of the extended partition;
    ③ What we actually store data is the primary partition and the logical partition, and a large amount of data is placed in the logical partition.

Note: Use the partition tool fdisk to operate, partition and format the disk (key points)

Note:
The primary partition can only have a maximum of 4 extended partitions.

The extended partition can be 0, and the maximum is 1.
The extended partition cannot be used directly. The extended partition must first be created as a logical partition before it can be used.
The logical partition can be 0 and 1 more

2. Disk management command

fdisk: Linux partition table operation tool software
n: Add a new partition

p : View partition information
w: Save and exit
q: Exit without saving
d: Delete partition
t: Change partition type

3. View disk command
ls  /dev/sd*     #查看磁盘
Copy after login

Among them: a-z represents the serial number of the device, such as sda represents the first scsi hard disk, sdb is the second one...
n represents the disk partition number divided on each disk



4. Create a primary partition demonstration:

The working environment is the English environment, which is convenient for everyone to read and demonstrate in the Mandarin environment

#第一步:添加磁盘创建主分区

╭─root@localhost.localdomain ~  
╰─➤  ls /dev/sd*     #查看磁盘
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdc  /dev/sdd  /dev/sde
╭─root@localhost.localdomain ~  
╰─➤  fdisk /dev/sdb     #管理分区                                                        
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x9fccbf7c 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n   #新建分区
Partition type:       #分区类型
   p   primary (0 primary, 0 extended, 4 free)     #p--->主分区
   e   extended       #e  --->   扩展分区
Select (default p): p     #选择主分区
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048): #分区磁盘的起始位,默认值,回车就好!
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+5G   #磁盘大小选择,加号不能省略,回车即可
分区 1 已设置为 Linux 类型,大小设为 5 GiB

命令(输入 m 获取帮助):P   #查询分区是否创建成功

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x9fccbf7c

   设备 Boot        Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux    #sdb1

命令(输入 m 获取帮助):w    #保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

#第二步:查看磁盘

╭─root@localhost.localdomain ~  
╰─➤  ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdd  /dev/sde

#第三步:格式化成xfs文件系统

╭─root@localhost.localdomain ~  
╰─➤  mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

#第四步:挂载至本地目录

╭─root@localhost.localdomain ~  
╰─➤  mkdir /xfs_du   #创建本地目录          
╭─root@localhost.localdomain ~  
╰─➤  mount /dev/sdb1 /xfs_du   #使用mount挂载   mount 磁盘 目录

#第五步:查看挂载信息

╭─root@localhost.localdomain ~  
╰─➤  df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   17G  4.7G   13G   28% /
devtmpfs             473M     0  473M    0% /dev
tmpfs                489M   88K  489M    1% /dev/shm
tmpfs                489M  7.1M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1           1014M  173M  842M   18% /boot
tmpfs                 98M  8.0K   98M    1% /run/user/0
/dev/sr0             4.1G  4.1G     0  100% /run/media/root/CentOS 7 x86_64
/dev/sdb1            5.0G   33M  5.0G    1% /xfs_du

#第六步:开机自动挂载

╭─root@localhost.localdomain ~  
╰─➤  echo "/dev/sdb1/xfs_du xfs defaults 0 0" >> /etc/fstab

#开机自动挂载方法2:

echo “mount /dev/sdb1 /xfs_du” >> /etc/rc.local
chmod +x /etc/rc.d/rc.local   #给个执行权限


# /etc/rc.local 
   是使用者自订开机启动程序的文件,把需要开机自动运行的程序写在这个脚本里
Copy after login

fdisk Partition Demonstration – Creating Logical Partitions

# 第一步:fdisk添加扩展分区

╭─root@du ~  
╰─➤ fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n    #添加新分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e     #选择扩展分区
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G    #5G大小
Partition 2 of type Extended and of size 5 GiB is set

Command (m for help): P   #查看分区

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe140b235

Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 5 Extended

Command (m for help): w   #保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#第二步:创建逻辑分区

╭─root@du ~  
╰─➤ fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l    #创建逻辑分区
Adding logical partition 5
First sector (10489856-20973567, default 10489856):
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +10G   #逻辑分区大小不能超过扩展分区大小
Value out of range.
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2g
Unsupported suffix: ‘g’.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
2^N: K (KibiByte), M (MebiByte), G (GibiByte)
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2G
Partition 5 of type Linux and of size 2 GiB is set

Command (m for help): P

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe140b235

Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 5 Extended
/dev/sdb5 10489856 14684159 2097152 83 Linux

Command (m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#第三步:创建文件系统

╭─root@du ~  
╰─➤ ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5
╭─root@du ~  
╰─➤ mkfs.xfs /dev/sdb5
meta-data=/dev/sdb5 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

#第四步:开机自动挂载

╭─root@du ~  
╰─➤ echo “mount /dev/sdb5 /xfs_du” >> /etc/rc.local
Copy after login


Local Directory Creating Swap Partition

Step 1: Create Directory

mkdir /swap
Copy after login

Step 2: Create an empty file

dd if=/dev/zero of=/swap/swap bs=2M count=2014
Copy after login

Step 3: Format to swap format

mkswap /swap/swap
Copy after login

Step 4: Write the file /etc/fstab and boot Automatically mount

echo "/swap/swap swap swap defaults 0 0" >> /etc/fstab
Copy after login

Step 5: Modify permissions and mount

chmod 0600 /swap/swap

mount -a
Copy after login

Step 6: Enable swap

swapon -a
Copy after login
[root@node1 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           976M        321M         60M        9.5M        594M        466M
Swap:          5.9G        221M        5.7G
Copy after login

Finally: Close swap

swapoff -a
Copy after login

Related recommendations: "

Linux Video Tutorial

"

The above is the detailed content of Which Linux partition is the primary partition?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1667
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles