Linux基础管理磁盘空间

1.使用fdisk对/dev/nvme0n1剩余空间进行分区

[root@good zhangyizhe]# fdisk /dev/nvme0n1
 
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.
Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): 
 
Using default response p.
Partition number (3,4, default 3): 3
First sector (41590784-41943039, default 41590784): 
Last sector, +sectors or +size{K,M,G,T,P} (41590784-41943039, default 41943039): 
 
Created a new partition 3 of type 'Linux' and of size 172 MiB.
 
Command (m for help): p
Disk /dev/nvme0n1: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xd9a564d3
 
Device         Boot    Start      End  Sectors  Size Id Type
/dev/nvme0n1p1 *        2048  1026047  1024000  500M 83 Linux
/dev/nvme0n1p2       1026048 41590783 40564736 19.4G 8e Linux LVM
/dev/nvme0n1p3      41590784 41943039   352256  172M 83 Linux

2.新添加一块儿磁盘使用gdisk,设置gpt分区表,新建分区

在虚拟机设置添加磁盘(需要先将虚拟机关闭添加)

 可见已经添加成功

 使用gdisk管理GPT分区: gdisk命令工具默认将磁盘划分为GPT格式的分区

步骤1:执行gdisk命令→输入n指令创建新分区。

步骤2:指定分区编号(默认是未使用的最小分区编号)

步骤3:指定新分区开始的位置和结束位置。

步骤4:显示已创建的分区信息。

步骤5:输入w子命令将分区设置写入分区表→当提示最终确认时,输入“y”

步骤6: 执行partprobe命令,使操作系统内核获知新的分区表信息

使用gdisk命令

[root@good zhangyizhe]# gdisk /dev/nvme0n2
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): p
Disk /dev/nvme0n2: 2097152 sectors, 1024.0 MiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 70931192-F934-4C50-A8DA-812CF51AAE08
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 2097085 sectors (1024.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-2097118, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-2097118, default = 2097118) or {+-}size{KMGTP}: +300
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/nvme0n2: 2097152 sectors, 1024.0 MiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 70931192-F934-4C50-A8DA-812CF51AAE08
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 2096785 sectors (1023.8 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            2347   150.0 KiB   8E00  Linux LVM

Command (? for help): 

 w命令保存并退出

 3.使用parted对新添加的磁盘添加分区(交互式)

添加分区格式如下:

(parted) mkpart primary xfs 1MB 500MB

(parted) quit

4.使用parted对/dev/nvme0n1新增分区(命令式)

5.挑选任一分区,进行格式化挂载(临时挂载)

格式化

格式化的目的: 是为了形成文件系统!

命令格式: mkfs|mkfs.xfs|mkfs.ext4 [选项] 分区的设备名

常用的选项有:

-t 文件系统类型——当命令名为mkfs时,指定要创建的文件系统的类型(如:xfs、ext4、vfat等)。当命令名 为mkfs.xfs、mkfs.ext4等时,不需要该选项。

-c——建立文件系统前先检查坏块。

-V——输出建立文件系统的详细信息。

首先格式化使nvme0n2p1形成文件系统

 然后临时挂载

 6.挑选另一分区,进行格式化挂载(永久挂载)

先形成文件系统

  永久挂载需进入到 /etc/fstab

 

 reboot重启后可以看见已经自动挂载了 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值