关键命令
# 查看可用块
lsblk -f
# 硬盘分区工具,对/dev/nvme0n1硬盘执行分区操作,执行: [n] [p] [1] [] [] [w]
fdisk /dev/nvme0n1
# 格式化分区的文件系统为xfs
mkfs.xfs /dev/nvme0n1p1
# 修改分区的目录挂载(系统启动时会自动加载这个文件挂载)
vim /etc/fstab
# 刷新挂载数据
mount -a
# 查看挂载成果
df -h
一、检查挂载盘
(1)执行 df -h 发现里面没有申请的nvme盘
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 24G 0 24G 0% /dev
tmpfs 24G 0 24G 0% /dev/shm
tmpfs 24G 25M 24G 1% /run
tmpfs 24G 0 24G 0% /sys/fs/cgroup
/dev/vda1 40G 1.9G 39G 5% /
tmpfs 4.8G 0 4.8G 0% /run/user/2388
tmpfs 4.8G 0 4.8G 0% /run/user/603
tmpfs 4.8G 0 4.8G 0% /run/user/0
(2)执行命令 lsblk -f 查看磁盘信息
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 xfs 35d52bf6-2196-4519-a1c7-79117ef0106b /
nvme0n1 xfs 36059d76-d2c5-4b41-89ad-08f6e26e6265
其中vda1是默认已挂载的磁盘,nvme0n1是新的磁盘,还没有MOUNTPOINT
(3)命令 fdisk -l 查看磁盘信息
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000cbc9d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux
Disk /dev/nvme0n1: 1600.3 GB, 1600321314816 bytes, 3125627568 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
二、开始操作
(1)命令行输入 fdisk /dev/nvme0n1 ,开始对磁盘进行设置。
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 0x5ddea492.
Command (m for help): m
Command action
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)
输入n添加一个新分区,再输入p为主分区,再输入1,再输入2048(直接回车默认也是2048),再输入3125627567(或者直接回车),然后w保存退出
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3125627567, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-3125627567, default 3125627567): 3125627567
Partition 1 of type Linux and of size 1.5 TiB is set
Command (m for help): w
The partition table has been altered!
再次查看:lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 xfs 35d52bf6-2196-4519-a1c7-79117ef0106b /
nvme0n1
└─nvme0n1p1
格式化分区,指定为xfs文件系统: mkfs -t xfs /dev/nvme0n1p1 命令等同于 mkfs.xfs /dev/nvme0n1p1
Discarding blocks...Done.
meta-data=/dev/nvme0n1p1 isize=512 agcount=4, agsize=97675798 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=390703190, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=190773, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
查看是否成功:lsblk -f , 成功格式化后会生成UUID
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 xfs 35d52bf6-2196-4519-a1c7-79117ef0106b /
nvme0n1
└─nvme0n1p1 xfs 56f6d5b6-83c2-4f87-9397-7c69bb8660b4
新增永久生效的挂载:vim /etc/fstab 增加一行记录:
UUID=35d52bf6-2196-4519-a1c7-79117ef0106b / xfs defaults 0 0
UUID=56f6d5b6-83c2-4f87-9397-7c69bb8660b4 /opt/push xfs defaults 0 0
刷新挂载信息
mount -a
执行 df -h 查看一下,也能看到了
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 25M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 40G 1.9G 39G 5% /
tmpfs 3.2G 0 3.2G 0% /run/user/2388
/dev/nvme0n1p1 1.5T 33M 1.5T 1% /opt/push