linux系统创建主分区、逻辑分区 、设置ext系列分区的参数以及检测分区的方法
linux对不同的磁盘设备的设备文件命名如下:
IDE: /dev/hd[a-z]
对IDE分区的命名为/dev/hda1 /dev/hda2 …..
SCSI, SATA, SAS, USB: /dev/sd[a-z]
对分区的命令为/dev/sda1 /dev/sda2 …….
主分区最多可有4个。若分区大于4个,可使用3个主分区加一个扩展分区的方式,再通过在扩展分区上划分多个逻辑分区。
常见的文件格式有ext2、ext3、ext4、vfat(兼容windows的fat32)、xfs、btrfs、jfs等。
查看linux的磁盘分区可使用fdis(分区管理命令)
fdisk /dev/sda (非IDE硬盘)
m:获取帮助
p:显示分区信息
q:不保存退出
n:新建分区
d:删除分区
q:保存退出
l:显示分区类型的ID
t:改变分区类型的ID
[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/O 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
说明:
1、Disk /dev/sda: 16.1 GB 硬盘的大小是16GB,16106127360 个字节,31457280个扇区。
2、下半部信息说明
Device 是分区名称
Boot 是否是启动分区
Start 起始的扇区
End 结束的扇区 \\ /dev/sda2结束的扇区是20971519,而硬盘总共有31457280,说明还有硬盘空间没有被用于创建分区。
Blocks以1KB为单位,显示分区的空间;
ld 为分区类型的ID号
System 为分区类型
创建分区:(下图中指定起始扇区与/dev/sda2的结束扇区能对接上)
创建逻辑分区
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e \\指定新建扩展分区
Selected partition 4
First sector (23068672-31457279, default 23068672):
Using default value 23068672
Last sector, +sectors or +size{K,M,G} (23068672-31457279, default 31457279): +1G \\指定扩展分区的大小
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号1-4已经用完,系统直接使用逻辑分区ID的范围5-15
First sector (23070720-25165823, default 23070720):
Using default value 23070720
Last sector, +sectors or +size{K,M,G} (23070720-25165823, default 25165823): 24000000 \\这里的结束扇区25165823-23070720=2095103*512/1024/1024=1022.99MB,即1GB,与指定的扩展分区大小相同
Partition 5 of type Linux and of size 453.8 MiB is set \\新建逻辑分区的大小是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{K,M,G} (24002560-25165823, default 25165823): \\这里的结束扇区ID与上述的相同
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/O 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 \\新建的逻辑分区
Command (m for help): w \\保存退出
检查linux是否已经识别出新的分区查看/rroc/paritions文件
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
8 0 15728640 sda
8 1 512000 sda1
8 2 9972736 sda2 \\新创建的/dev/sda3-6没有还没有识别出来
11 0 4228096 sr0
253 0 8880128 dm-0
253 1 1048576 dm-1
强制让内核更新分区
[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 \\已识别出新分区
11 0 4228096 sr0
253 0 8880128 dm-0
253 1 1048576 dm-1
[root@localhost ~]#
格式化新建的分区mkfs命令
把sda6、sda5格式为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
也可用 ext系列专用的格式化工具mke2fs
[root@localhost ~]# mke2fs -t ext3 -m 5 -L TEST_sda5 -b 4096 /dev/sda5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST_sda5 \\标识符为TEST_sda5
OS type: Linux
Block size=4096 (log=2) \\block为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%的空间
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
查看所有分区的属性使用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"
使用fsck命令检测分区
[root@localhost ~]# fsck.ext3 -frc /dev/sda5 \\ f是强制检测 c是提示测试进度 r进行交互式检测
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/116224 files (0.0% non-contiguous), 7837/116160 blocks
[root@localhost ~]#
相关文章

Fedora Linux 42 稳定版发布: 带来大量新功能和软件更新
Fedora 42昨日发布,这是 Red Hat 赞助开发的杰出前沿 Linux 发行版的最新版,包含大量新功能和软件更新,使其成为 2025 年上半年发布的一款出色的 Linux 操作系统之一,内2025-04-16
如何在Linux查看硬盘信息? 查看Linux硬盘大小类型和硬件信息的5种方法
使用Linux系统的过程中,查看和了解硬盘信息是非常重要的工作,尤其是对于系统管理员而言,那么在Linux系统中如何查看硬盘信息?以下是具体内容介绍2025-03-12
如何在 Linux 中查看 CPU 详细信息? 3招轻松查看CPU型号、核心数和温度
在日常运维工作中,获取 CPU 信息是系统运维管理员常见的工作内容,无论是为了性能调优、硬件升级还是仅仅满足好奇心2025-03-11
什么是 Arch Linux? 独树一帜的Arch Linux发行版分析
Arch Linux是为简化,优化,现代化,实用主义,用户中心和多功能性而创建Linux发行版,究竟是什么让 Arch 与众不同?下面我们就来简要解读2025-02-19
一直用的linux办公,想要将笔记本电脑从 Linux 系统切换回 Windows 11,我们可以制作一个win11装机u盘,详细如下2025-02-17
Rsnapshot怎么用? 基于Rsync的强大Linux备份工具使用指南
Rsnapshot 不仅可以备份本地文件,还能通过 SSH 备份远程文件,接下来详细介绍如何安装、配置和使用 Rsnapshot,包括创建每小时、每天、每周和每月的本地备份,以及如何进2025-02-06
Linux Kernel 6.13发布:附更新内容及新特性解读
Linux 内核 6.13 正式发布,新版本引入了惰性抢占支持,简化内核抢占逻辑,通过减少与调度器相关的调用次数,让内核在运行时表现更优,从而提高效率2025-01-23
五大特性引领创新! 深度操作系统 deepin 25 Preview预览版发布
今日,深度操作系统正式推出deepin 25 Preview版本,该版本集成了五大核心特性:磐石系统、全新DDE、Treeland窗口合成器、AI For OS以及Distrobox子系统2025-01-18
Linux Mint Xia 22.1重磅发布: 重要更新一览
Beta 版 Linux Mint“Xia” 22.1 发布,新版本基于 Ubuntu 24.04,内核版本为 Linux 6.8,这次更新带来了诸多优化和改进,进一步巩固了 Mint 在 Linux 桌面操作系统领域的2025-01-16
LinuxMint怎么安装? Linux Mint22下载安装图文教程
Linux Mint22发布以后,有很多新功能,很多朋友想要下载并安装,该怎么操作呢?下面我们就来看看详细安装指南2025-01-16









最新评论