fdisk分区命令
fdisk命令适合给小于2T的磁盘分区
fdisk用法:
fdisk [选项] <磁盘> 更改分区表
fdisk [选项] -l <磁盘> 列出分区表
fdisk -s <分区> 给出分区大小(块数)
选项:
-b <大小> 扇区大小(512、1024、2048或4096)
-c[=<模式>] 兼容模式:“dos”或“nondos”(默认)
-h 打印此帮助文本
-u[=<单位>] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认)
-v 打印程序版本
-C <数字> 指定柱面数
-H <数字> 指定磁头数
-S <数字> 指定每个磁道的扇区数
fdisk -l 查看系统上的硬盘
|3|[root@chenyi ~]#fdisk -l
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c8508
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 209715199 104651776 8e Linux LVM
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-root:93.4 GB, 93411344384 字节,182444032 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:3011 MB, 3011510272 字节,5881856 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/loop0:7062 MB, 7062159360 字节,13793280 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x4f3c40e6
设备 Boot Start End Blocks Id System
/dev/loop0p1 * 0 13793279 6896640 0 Empty
/dev/loop0p2 4812 17391 6290 ef EFI (FAT-12/16/32)
磁盘 /dev/loop1:3895 MB, 3895459840 字节,7608320 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x03efda4e
设备 Boot Start End Blocks Id System
/dev/loop1p1 * 0 7608319 3804160 17 Hidden HPFS/NTFS
磁盘 /dev/mapper/centos-home:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
1、分区实例(给磁盘/dev/sda分区)
|5|[root@chenyi ~]#fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xf2ddf0b9 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
命令(输入 m 获取帮助):
注释:输入m获取帮助后,每个字母的含义如下,常用的就是:d l m p q t w
d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition’s system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
注释:p为主分区,最多只能分4个,e为扩展分区,可以分出很多
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-209715199,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-209715199,默认为 209715199):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):P
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c8508
设备 Boot Start End Blocks Id System
/dev/sda1 2048 2099199 1048576 83 Linux
我们可以看见分区/dev/sda1已经分好区了
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
默认的磁盘分区类型为linux,输入t可以更改分区类型