入门:Linux的磁盘分区

目录

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

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

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

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

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


1.使用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-8-5-0-BaseOS-x86_64
nvme0n1       259:0    0   40G  0 disk 
├─nvme0n1p1   259:1    0    2G  0 part /boot
└─nvme0n1p2   259:2    0 30.8G  0 part 
  ├─rhel-root 253:0    0 25.2G  0 lvm  /
  └─rhel-swap 253:1    0  5.6G  0 lvm  [SWAP]
[root@localhost ~]# lsscsi 
[2: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@localhost ~]# 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):       #从当前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.


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

先去添加一块SATA硬盘,然后开机查看是否加载到新的硬盘,如果检测到再进行管理操作

[root@localhost ~]# gdlsk /dev/sda 

Command (? for help): o                             #创建一个新的GPT分区表
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.


3.使用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 

...

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

[root@server ~]# 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 
...


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

[root@server ~]# 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@server ~]# mount /dev/sdb1 /mount1          #临时挂载

6.挑选另一分区,进行格式化挂载(永久挂载)
[root@localhost /]# vim /etc/fstab                       

 

入门:Linux的磁盘分区_第1张图片 

你可能感兴趣的:(服务器,linux,学习)