RHCSA(八)

本文详细介绍了在Linux系统中使用fdisk、gdisk、parted工具对磁盘进行MBR和GPT分区,创建新分区,并进行格式化及临时和永久挂载的操作步骤。涉及的命令包括lsblk、lsscsi、mkfs、mount等。
摘要由CSDN通过智能技术生成

一、使用fdisk对/dev/nvme0n1剩余空间进行分区

MBR分区:支持的分区数量: 4 个主分区或者 3 个主分区 1 个扩展分区

[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10.2G 0 rom /run/media/root/RHEL-
nvme0n1 259:0 0 30G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 29G 0 part
├─rhel-root 253:0 0 15G 0 lvm /
├─rhel-swap 253:1 0 2G 0 lvm [SWAP]
└─rhel-home 253:2 0 12G 0 lvm /home
[root@localhost ~]# lsscsi
[3:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
[N:0:0:1] disk VMware Virtual NVMe Disk__1 /dev/nvme0n1
[root@server ~]# fdisk /dev/nvme0n1
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):
First sector (68675584-83886079, default 68675584):
Last sector, +sectors or +size{K,M,G,T,P} (68675584-83886079, default 83886079): +500M
Created a new partition 3 of type ‘Linux’ and of size 500 MiB.
Command (m for help): n
Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e):
Using default response e.
Selected partition 4
First sector (69699584-83886079, default 69699584): +500M
First sector (69699584-83886079, default 69699584):
Last sector, +sectors or +size{K,M,G,T,P} (69699584-83886079, default 83886079): +500M
Created a new partition 4 of type ‘Extended’ and of size 500 MiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

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

[root@localhost ~]# gdlsk /dev/sda
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-2097118, default = 2048) or {±}size{KMGTP}:
Last sector (2048-2097118, default = 2097118) or {±}size{KMGTP}: +500M
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): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

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

[root@localhost ~]# parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart part1 10M 510M
(parted) quit
Information: You may need to update /etc/fstab.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1G 0 disk
├─sda1 8:1 0 500M 0 part
└─sda2 8:2 0 300M 0 part
sdb 8:16 0 1G 0 disk
└─sdb1 8:17 0 476M 0 part

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

[root@localhost ~]# parted /dev/sdb mkpart part2 511M 1011M
Information: You may need to update /etc/fstab.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1G 0 disk
├─sda1 8:1 0 500M 0 part
└─sda2 8:2 0 300M 0 part
sdb 8:16 0 1G 0 disk
├─sdb1 8:17 0 476M 0 part
└─sdb2 8:18 0 477M 0 part

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

[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 487424 1k blocks and 121920 inodes
Filesystem UUID: 1ac915fe-2ba2-4bc4-8da4-fe6deeb68fba
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mount /dev/sdb1 /mount1

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

[root@localhost ~]# vim /etc/fstab

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值