磁盘挂载和格式化(GPT)
centos7.9磁盘挂载和格式化(GPT)
(GPT分区)如果你的系统是基于UEFI引导,或者你有一个大于2TB的磁盘,建议使用gdisk。这在现代硬件和操作系统中更为常见。
(MBR分区)如果你的系统是基于Legacy BIOS引导,或者使用较小容量的磁盘,fdisk可能是一个更简单的选择。
一、linux(centos7.9)下磁盘分区(MBR分区)
1、fdisk -l 查看系统中是否正常识别到新增硬盘,且确认是没有分过区的
2、fdisk /dev/sdb 使用fdisk命令位指定的硬盘(新硬盘)分区
3、新增分区
4、查看分区是否成功
5、格式化
mkfs.xxx /dev/sdb1
格式化我们的新分区(根据自我需求可将系统文件格式格成常用的ext4或者xfs)
二、linux(centos7.9)下磁盘分区(GPT分区)
1.命令:lsblk 列出本系统下的所有磁盘与磁盘内的分区信息
[root@localhost /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 1.1T 0 disk
├─sda1 8:1 1 500M 0 part /boot/efi
├─sda2 8:2 1 500M 0 part /boot
└─sda3 8:3 1 550G 0 part
├─centos-root 253:0 0 500G 0 lvm /
└─centos-swap 253:1 0 50G 0 lvm [SWAP]
sdb 8:16 1 21.8T 0 disk
2.命令:blkid 查看文件系统和UUID
[root@localhost /]# blkid
/dev/sda1: SEC_TYPE="msdos" UUID="2402-55B5" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="820f0002-7d2f-4956-a36f-8f92af332ce7"
/dev/sda2: UUID="7f294568-d820-410a-a92a-de2bb23e0f58" TYPE="ext4" PARTUUID="b268e332-2635-410c-8a10-25344faaebe6"
/dev/sda3: UUID="XJw97x-WRoL-anlF-SXMs-OasM-AGKe-kGj593" TYPE="LVM2_member" PARTUUID="09f00d9e-e132-4bb1-99ed-a6cbd557835a"
/dev/mapper/centos-root: UUID="f53f3b32-bfa6-4ce6-b491-ad63d436cc35" TYPE="ext4"
/dev/mapper/centos-swap: UUID="2265571b-9ad7-47a6-9d3e-a2f3c8584dbf" TYPE="swap"
/dev/sdb: PTTYPE="gpt" ----分区格式GPT
3.命令: parted /dev/sdb print 查看磁盘分区表类型(MBR 或者 GPT)
[root@localhost /]# parted /dev/sdb print
Model: PM8060- DefaultValue1 (scsi)
Disk /dev/sdb: 24.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt ----分区格式GPT
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 24.0TB 24.0TB ext4 Linux filesystem
4.命令:gdisk 磁盘分区
gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): p ##查看分区情况
Disk /dev/sdb: 46871341056 sectors, 21.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): E7475E5B-6B7D-483C-AFFD-E9DB10194690
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 46871341022
Partitions will be aligned on 2048-sector boundaries
Total free space is 46871340989 sectors (21.8 TiB)
Number Start (sector) End (sector) Size Code Name
Command (? for help): n ###新建分区,我这一个分区,所以回车到底
Partition number (1-128, default 1):
First sector (34-46871341022, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-46871341022, default = 46871341022) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 46871341056 sectors, 21.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): E7475E5B-6B7D-483C-AFFD-E9DB10194690
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 46871341022
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 46871341022 21.8 TiB 8300 Linux filesystem
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/sdb.
The operation has completed successfully.
解释:
n 新建分区
p 查看分区
w 保存
PS:本次操作磁盘只做了一个分区,如有多分布区需求记得划分。
5.命令;lsblk 查看分区
[root@localhost /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 1.1T 0 disk
├─sda1 8:1 1 500M 0 part /boot/efi
├─sda2 8:2 1 500M 0 part /boot
└─sda3 8:3 1 550G 0 part
├─centos-root 253:0 0 500G 0 lvm /
└─centos-swap 253:1 0 50G 0 lvm [SWAP]
sdb 8:16 1 21.8T 0 disk
└─sdb1 8:17 1 21.8T 0 part
6.命令: mkfs.ext4 /dev/sdb1 格式化分区(sdb1为分区之后的标识(盘)符)
[root@localhost /]# mkfs.ext4 /dev/sdb1
注意这里的ext4文件系统按需配置
[root@k8s-node4 /]# mkfs.
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat
mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs
[root@localhost /]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
366182400 inodes, 5858917371 blocks
292945868 blocks (5.00%) reserved for the super user
第一个数据块=0
178800 block groups
32768 blocks per group, 32768 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
2560000000, 3855122432, 5804752896
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
三、磁盘挂载(临时)
1.创建挂载目录,命令:mkdir -p /mnt/data
2.挂载,mount
[root@localhost /]# mount /dev/sdb1 /mnt/data/
[root@localhost /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 1.1T 0 disk
├─sda1 8:1 1 500M 0 part /boot/efi
├─sda2 8:2 1 500M 0 part /boot
└─sda3 8:3 1 550G 0 part
├─centos-root 253:0 0 500G 0 lvm /
└─centos-swap 253:1 0 50G 0 lvm [SWAP]
sdb 8:16 1 21.8T 0 disk
└─sdb1 8:17 1 21.8T 0 part /mnt/data
挂载成功!
四、磁盘挂载(永久)
1.编辑fstab文件
vi /etc/fstab
当我们把 挂载信息 写到 该配置文件的时候 就实现了 永久挂载~!!!
该文件是在开机的时候就会自动读取的,所以就实现了永久挂载~!!!
我们先来看看 这个 配置文件里的内容 :
上示内容就是 默认的 配置文件里已有的内容,我们将来要实现永久挂载也是写到这里的~!!!
上示编辑的内容大概分为 六个部分,上示呢 是三行,每行都是一条信息里的内容
下面对上面 每行的六个部分进行解释 :
关于上示 权限选项 ,什么 rw,suid 啥的,以下内容作为参考解释 :
示例 :
上示内容就是 我们对 /dev/nvme0n2p3 进行了永久挂载, 挂载点是 /root/mount3
然后,保存退出 ~!!
需要注意的是,我们永久挂载时, 配置文件里,配置好后,保存退出后,并不会立马生效,得重启,才
会生效配置文件 ~!!!
我们重启后,使用 mount 查看下有没有 关于 /dev/nvme0n2p3 的内容
显然,这就实现了 永久挂载~!!!