admin管理员组

文章数量:1622289

背景:磁盘挂载的时候报错:

mount: /dev/sdb 写保护,将以只读方式挂载
mount: 文件系统类型错误、选项错误、/dev/sdb 上有坏超级块、
       缺少代码页或助手程序,或其他错误

       有些情况下在 syslog 中可以找到一些有用信息- 请尝试
       dmesg | tail  这样的命令看看。

经过判定需要对磁盘分区、格式化

一、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 磁盘分区

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
挂载成功!

本文标签: 磁盘gpt