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 ~]#