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

How to create primary partition and logical partition in linux system

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces how to create main partition and logical partition in linux system. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Linux names the device files for different disk devices as follows:

IDE: / dev/hd [a Meiz]

The IDE partition is named / dev/hda1 / dev/hda2... ..

SCSI, SATA, SAS, USB: / dev/sd [a Murz]

The command for the partition is / dev/sda1 / dev/sda2... .

There can be up to 4 primary partitions. If there are more than 4 partitions, you can use 3 primary partitions plus an extended partition, and then divide multiple logical partitions on the extended partition.

Common file formats are ext2, ext3, ext4, vfat (fat32 compatible with windows), xfs, btrfs, jfs and so on.

To view the disk partition of linux, you can use fdis (partition management command)

Fdisk / dev/sda (non-IDE hard disk)

M: get help

P: display partition information

Q: do not save exit

N: create a new partition

D: delete partition

Q: save exit

L: displays the ID of the partition type

T: change the ID of the partition type

[root@localhost ~] # fdisk / dev/sda

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): P

Disk / dev/sda: 16.1 GB, 16106127360 bytes, 31457280 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x000a72d4

Device Boot Start End Blocks Id System

/ dev/sda1 * 2048 1026047 512000 83 Linux

/ dev/sda2 1026048 20971519 9972736 8e Linux LVM

Description:

1. Disk / dev/sda: the size of the 16.1 GB hard disk is 16GB magnets 16106127360 bytes and 31457280 sectors.

2. Description of the second half of the information

Device is the partition name

Whether Boot is a boot partition

The sector from which the Start starts

The sector at the end of End\ / dev/sda2 ends with a sector of 20971519, while the hard disk has a total of 31457280, indicating that there is still hard disk space that has not been used to create partitions.

Blocks displays the space of the zone in 1KB

Ld is the ID number of the partition type

System is the partition type

Create a partition: (the following figure specifies that the start sector can be docked with the end sector of / dev/sda2)

Create a logical partition

Command (m for help): n

Partition type:

P primary (3 primary, 0 extended, 1 free)

E extended

Select (default e): e\\ specify a new extended partition

Selected partition 4

First sector (23068672-31457279, default 23068672):

Using default value 23068672

Last sector, + sectors or + size {KMagneMJ G} (23068672-31457279, default 31457279): + 1G\\ specify the size of the extended partition

Partition 4 of type Extended and of size 1 GiB is set

Command (m for help): n

All primary partitions are in use

Adding logical partition 5\\ ID number 1-4 has been used up, the system directly uses the logical partition ID range 5-15

First sector (23070720-25165823, default 23070720):

Using default value 23070720

Last sector, + sectors or + size {KMagneMJ G} (23070720-25165823, default 25165823): 24000000\ the end sector 25165823-23070720=2095103*512/1024/1024=1022.99MB, or 1GB, here is the same size as the specified extended partition.

Partition 5 of type Linux and of size 453.8 MiB is set\\ the size of the new logical partition is 453.8MB

Command (m for help): n

All primary partitions are in use

Adding logical partition 6

First sector (24002049-25165823, default 24002560):

Using default value 24002560

Last sector, + sectors or + size {KMagneMJ G} (24002560-25165823, default 25165823):\\ the end sector ID here is the same as above.

Using default value 25165823

Partition 6 of type Linux and of size 568 MiB is set

Command (m for help): P

Disk / dev/sda: 16.1 GB, 16106127360 bytes, 31457280 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x000a72d4

Device Boot Start End Blocks Id System

/ dev/sda1 * 2048 1026047 512000 83 Linux

/ dev/sda2 1026048 20971519 9972736 8e Linux LVM

/ dev/sda3 20971520 23068671 1048576 83 Linux

/ dev/sda4 23068672 25165823 1048576 5 Extended

/ dev/sda5 23070720 24000000 464640 + 83 Linux

/ dev/sda6 24002560 25165823 581632 83 Linux\\ newly created logical partition

Command (m for help): W\\ Save exit

Check whether linux has recognized the new partition view / rroc/paritions file

[root@localhost ~] # cat / proc/partitions

Major minor # blocks name

8 0 15728640 sda

8 1 512000 sda1

8 2 9972736 sda2\\ the newly created / dev/sda3-6 is not recognized yet

11 0 4228096 sr0

253 0 8880128 dm-0

253 1 1048576 dm-1

Force the kernel to update the partition

[root@localhost] # partx-u / dev/sda

[root@localhost ~] # cat / proc/partitions

Major minor # blocks name

8 0 15728640 sda

8 1 512000 sda1

8 2 9972736 sda2

8 3 1048576 sda3

8 4 1 sda4

8 5 464640 sda5

8 6 581632 sda6\\ A new partition has been identified

11 0 4228096 sr0

253 0 8880128 dm-0

253 1 1048576 dm-1

[root@localhost ~] #

Format the newly created partition mkfs command

Format sda6 and sda5 as ext4

[root@localhost] # mkfs.ext4-L test / dev/sda6

Mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=test

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

36400 inodes, 145408 blocks

7270 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=148897792

5 block groups

32768 blocks per group, 32768 fragments per group

7280 inodes per group

Superblock backups stored on blocks:

32768, 98304

Allocating group tables: done

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

You can also use mke2fs, a special formatting tool for ext series.

[root@localhost] # mke2fs-t ext3-m 5-L TEST_sda5-b 4096 / dev/sda5

Mke2fs 1.42.9 (28-Dec-2013)

The Filesystem label=TEST_sda5\\ identifier is TEST_sda5.

OS type: Linux

Block size=4096 (log=2)\\ block is 4096

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

116224 inodes, 116160 blocks

5808 blocks (5.00%) reserved for the super user\\ 5% space reserved for administrators

First data block=0

Maximum filesystem blocks=121634816

4 block groups

32768 blocks per group, 32768 fragments per group

29056 inodes per group

Superblock backups stored on blocks:

32768, 98304

Allocating group tables: done

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

View the properties of all partitions using blkid

[root@localhost ~] # blkid

Dev/sda1: UUID= "050a347a-4a99-4e80-a6b4-a4ed0a47eaa1" TYPE= "xfs"

/ dev/sda2: UUID= "dv2Krn-BlSL-4NBt-yduR-BXax-tChJ-V2YpbM" TYPE= "LVM2_member"

Dev/sda5: LABEL= "TEST_sda5" UUID= "b5b2b12b-236d-4578-845b-a5632ca5eafa" SEC_TYPE= "ext2" TYPE= "ext3"

Dev/sda6: LABEL= "test" UUID= "a0a549a2-0aec-4ff6-bce8-f2dfdfa1539e" TYPE= "ext4"

/ dev/sr0: UUID= "2015-12-09-23-14-10-00" LABEL= "CentOS 7 x86" 64 "TYPE=" iso9660 "PTTYPE=" dos "

Dev/mapper/centos-root: UUID= "0adba78a-e1e3-4900-87c2-069105c6a1fc" TYPE= "xfs"

Dev/mapper/centos-swap: UUID= "2228d7dd-b7ed-44fb-9f68-668fc942a542" TYPE= "swap"

Use the fsck command to detect partitions

[root@localhost] # fsck.ext3-frc / dev/sda5\\ f is mandatory detection c is an indication of test progress r for interactive detection

E2fsck 1.42.9 (28-Dec-2013)

Checking for bad blocks (read-only test): done

TEST_sda5: Updating bad block inode.

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

TEST_sda5: * FILE SYSTEM WAS MODIFIED *

TEST_sda5: 11 non-contiguous 116224 files (0.0% non-contiguous), 7837Acer 116160 blocks

[root@localhost ~] #

On how to create primary partition and logical partition in the linux system is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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