fdisk管理分区

参数

                作用                                  

m

                                                       查看全部可用的参数                                                                

n

添加新的分区

d

删除某个分区信息

l

列出所有可用的分区类型

t

改变某个分区的类型

p

查看分区表信息

w

保存并退出

q

不保存直接退出

fdisk:磁盘分区,是Linux发行版本中最常用的分区工具

用法:fdisk [选项] device

常用的选项: -l 查看硬盘分区表

[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb

第二步:对sdb划分一个100M的空间

fdisk-LMLPHP
[root@ken ~]# fdisk /dev/sdb
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. Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x52997d99. Command (m for help): n #创建一个新的分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): #默认主分区,直接回车
Using default response p
Partition number (1-4, default 1): #默认为第一个分区编号,直接回车
First sector (2048-41943039, default 2048): #默认第一个扇区开始位置,直接回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +100M #选择大小,前面要使用加号
Partition 1 of type Linux and of size 100 MiB is set Command (m for help): P #查看已经分好的磁盘 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x52997d99 Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux Command (m for help): w #w退出保存,q退出不保存
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
fdisk-LMLPHP

第三步:格式化

新的磁盘分区使用之前必须先格式化

fdisk-LMLPHP
[root@ken ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729 Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
fdisk-LMLPHP

第四步:挂载使用

fdisk-LMLPHP
[root@ken ~]# mkdir /part
[root@ken ~]# mount /dev/sdb1 /part
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.2G 16G 7% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 93M 1.6M 85M 2% /part
fdisk-LMLPHP

第五步:写入到配置文件中,开机自启

[root@ken ~]# echo "/dev/sdb1 /part ext4 defaults 0 0" >> /etc/fstab 

/dev/sdb1

/sdb1

xfs

defaults

0

0

要挂载的分区设备

挂载点

文件系统类型

挂载选项

是否备份

是否检测

05-07 15:35