创建新硬盘分区命令参数:
fdisk 可以用 m 命令来看 fdisk 命令的内部命令;
a:命令指定启动分区;
d:命令删除一个存在的分区;
l:命令显示分区 ID 号的列表;
m:查看 fdisk 命令帮助;
n:命令创建一个新分区;
p:命令显示分区列表;
t:命令修改分区的类型 ID 号;
w:命令是将对分区表的修改存盘让它发生作用
[root@kiccleaf ~]# fdisk -l
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x16aee8ac
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 2097151999 2095052800 999G 8e Linux LVM
//新硬盘
Disk /dev/sdb: 1000 GiB, 1073741824000 bytes, 2097152000 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 /dev/mapper/cl-root: 50 GiB, 53687091200 bytes, 104857600 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 /dev/mapper/cl-swap: 7.9 GiB, 8468299776 bytes, 16539648 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 /dev/mapper/cl-home: 941.1 GiB, 1010508496896 bytes, 1973649408 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
[root@kiccleaf ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xa5c1ca20.
Command (m for help): n
Partition type
//输入p分为主分区
p primary (0 primary, 0 extended, 4 free)
//输入e分为逻辑分区
e extended (container for logical partitions)
Select (default p): p
//输入该主分区为第几个主分区,由于是新盘我们输入1来分第一个主分区
Partition number (1-4, default 1): 1
//First sector 是选择该分区的起始扇区,直接回车
First sector (2048-2097151999, default 2048):
//使用全部可用存储额,直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151999, default 2097151999):
Created a new partition 1 of type 'Linux' and of size 1000 GiB.
//w保存
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
//mkfs.xfs命令带-f强制格式化
[root@kiccleaf ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65535936 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=262143744, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=127999, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
//用命令blkid 查看一下已是xfs格式
[root@kiccleaf data]# blkid /dev/sdb1
/dev/sdb1: UUID="813681bd-a154-43d8-88dc-27750eacfcc1" TYPE="xfs" PARTUUID="a5c1ca20-01"
//创建挂载目录
[root@kiccleaf ~]# mkdir /data
//mount直接挂载硬盘至data
[root@kiccleaf ~]# mount /dev/sdb1 /data
//查看一下挂载的硬盘data已经有了
[root@kiccleaf ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 9.0M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/cl-root 50G 6.3G 44G 13% /
/dev/mapper/cl-home 941G 6.7G 935G 1% /home
/dev/sda1 976M 198M 711M 22% /boot
tmpfs 779M 0 779M 0% /run/user/0
/dev/sdb1 984G 77M 934G 1% /data
//系统重启自动挂载该分区对fstab进行编辑
[root@kiccleaf ~]# vim /etc/fstab
系统重启自动挂载该分区可修改 / etc/fstab 文件,在最后加入添加:/dev/sdb1 /data xfs defaults 0 0
格式说明:/dev/sdb1 代表哪个分区, /data 是挂载目录, xfs 是该分区的格式,defaults 是挂载时所要设定的参数 (只读,读写,启用 quota 等),输入 defaults 包括的参数有 (rw、dev、exec、auto、nouser、async) ,1 是使用 dump 是否要记录,0 是不要。 2 是开机时检查的顺序,是 boot 系统文件就为 1,其他文件系统都为 2,如不要检查就为 0
/dev/mapper/cl-root / xfs defaults 0 0
UUID=86a7eaa3-61db-49cd-be3d-54b724f24878 /boot ext4 defaults 1 2
/dev/mapper/cl-home /home xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/sdb1 /data xfs defaults 0 0
xfs 格式是一种非常优秀的日志文件系统,它是 SGI 公司设计的。xfs 被称为业界最先进的、最具可升级性的文件系统技术,xfs 是一个 64 位文件系统,最大支持 8EB 减 1 字节的单个文件系统,实际部署时取决于宿主操作系统的最大块限制。对于一个 32 位 Linux 系统,文件和文件系统的大小会被限制在 16TB
xfs 在很多方面确实做的比 ext4 好,ext4 受限制于磁盘结构和兼容问题,可扩展性和 scalability 确实不如 xfs。具体详细的区别请自行了解,采用 df -T 命令查看系统硬盘的格式
[root@kiccleaf ~]
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 3968364 0 3968364 0% /dev
tmpfs tmpfs 3985404 0 3985404 0% /dev/shm
tmpfs tmpfs 3985404 9176 3976228 1% /run
tmpfs tmpfs 3985404 0 3985404 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 52403200 6583040 45820160 13% /
/dev/sdb1 xfs 1048062980 7340272 1040722708 1% /data
/dev/sda1 ext4 999320 202436 728072 22% /boot
/dev/mapper/cl-home xfs 986342856 6965148 979377708 1% /home
tmpfs tmpfs 797080 0 797080 0% /run/user/0