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