1 分区命令

fdisk :小于2T的空间,磁盘标签为dos

parted : 大于2T的空间,磁盘标签为GPT或者MBR

2 查看分区命令
查看分区信息
fdisk -l
#查看文件系统、UUID等
lsblk -f
#查看UUID
blkid
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
3 磁盘管理

一般dos标签的磁盘分区方案建议为3个主分区一个扩展分区

root@pgsql166:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0xc5faf2d4.

Command (m for help): p
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xc5faf2d4

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, default 104857599): +10g

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): p
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xc5faf2d4

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 20973567 20971520  10G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.

分区创建完成后,使用partprobe 命令 激活新创建分区表

partprobe
  • 1.

格式化磁盘(mkfs.xfs、mkfs.xfs)

mkfs.ext4 /dev/sdb1
  • 1.

挂载目录

mount /dev/sdb1 /data
  • 1.

开机自动挂载目录

RHCE 学习笔记之文件系统和磁盘管理09_unmount

umount

umount /data
#延迟卸载目录(当文件被系统占用时,使用-l参数后会等系统使用完自动卸载,且期间其他程序无法使用)
umount -l /data
  • 1.
  • 2.
  • 3.

卸载目录经常出现报错umount: /data: target is busy.

#lsof 查看哪个进程在占用此目录
lsof +d /data
  • 1.
  • 2.
4 文件系统的检查与修复

建议卸载挂载目录后修复

#ext4文件系统
fsck -p /dev/sdc2
#xfs文件系统
xfs_repair /dev/sdb1
  • 1.
  • 2.
  • 3.
  • 4.