Linux 新磁盘分区和挂载

junlan
6
2025-01-08

查看硬盘情况,这里要使用nvme0n2硬盘

[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 10.7G  0 rom
nvme0n1     259:0    0   20G  0 disk
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0   19G  0 part
  ├─rl-root 253:0    0   17G  0 lvm  /
  └─rl-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:3    0   30G  0 disk

创建分区

[root@localhost ~]# fdisk /dev/nvme0n2

Welcome to fdisk (util-linux 2.37.4).
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 0xcc5c9dde.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):            # 默认回车即可
First sector (2048-62914559, default 2048):      # 默认回车即可
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62914559, default 62914559):

Created a new partition 1 of type 'Linux' and of size 30 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

磁盘格式化

[root@localhost ~]# mkfs.xfs -f /dev/nvme0n2
# 创建挂载 /blog 目录
[root@localhost ~]# mkdir /blog
# 将  /dev/nvme0n2 挂载到 /blog 目录
[root@localhost ~]# mount /dev/nvme0n2 /blog/

查看磁盘挂载情况

[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
nvme0n2     259:3       0     30G  0   disk       /blog
[root@localhost ~]# df -Th
Filesystem             Type      Size   Used    Avail Use% Mounted on
/dev/nvme0n2        xfs        30G  247M   30G   1%       /blog