linux 磁盘分区

1、 列出系统上所有磁盘列表

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 931.5G  0 disk 
├─sda1            8:1    0   200M  0 part /boot/efi
├─sda2            8:2    0   500M  0 part /boot
└─sda3            8:3    0 930.8G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0   873G  0 lvm  /home
sr0              11:0    1  1024M  0 rom  

 

2、列出所有磁盘的UUID

[root@localhost ~]# blkid
/dev/sda1: SEC_TYPE="msdos" UUID="60B7-9F11" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="9adf58e9-3570-428d-a58a-2f7ff893a7f0" 
/dev/sda2: UUID="dc643138-a2ff-4eab-84eb-d71af7c1f74d" TYPE="xfs" PARTUUID="c9c6c0e2-00ca-49fc-b152-7e90c0dec9f0" 
/dev/sda3: UUID="JO0bNb-6Haq-CiyW-QZof-ZRRU-7tm3-Rd4x7t" TYPE="LVM2_member" PARTUUID="2fb2663a-345a-4f7b-8516-1e5d7102e166" 
/dev/mapper/centos-root: UUID="0d5c41a3-bab1-4551-8cfb-5527fa4ad4bc" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="0ff3dece-11d7-4dfd-b08f-c8426cf851ca" TYPE="swap" 
/dev/mapper/centos-home: UUID="2c2770ec-3653-4b4a-8e7b-a4a897f87275" TYPE="xfs" 

 

3、列出某个磁盘的分区类型与分区信息

[root@localhost ~]# parted /dev/sda print
Model: ATA WDC WD10EZEX-60W (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size   File system  Name                  标志
 1      1049kB  211MB   210MB  fat16        EFI System Partition  启动
 2      211MB   735MB   524MB  xfs
 3      735MB   1000GB  999GB                                     lvm

注:上面表示是gpt分区类型;

 

4、磁盘分区 gdisk、fdisk

MBR分区类型使用 fdisk 进行磁盘分区,GPT分区类型使用 gdisk 进行磁盘分区;

查看分区:

[root@localhost ~]# gdisk /dev/sda -l
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 7D235CA9-AAC3-4F15-A580-23E3E8482CF2
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 3437 sectors (1.7 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          411647   200.0 MiB   EF00  EFI System Partition
   2          411648         1435647   500.0 MiB   0700  
   3         1435648      1953523711   930.8 GiB   8E00  

进入分区操作:

[root@localhost ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6

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 # 将gpt分区数据备份到文件
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) # 创建新的空guid分区表(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

 

5、格式化磁盘

[root@localhost ~]# mkfs.xfs /dev/sda2 # 格式化为xfs文件系统

[root@localhost ~]# mkfs.ext4 /dev/sda2 # 格式化为ext4文件系统

 

6、查看某个磁盘的所有信息

[root@localhost ~]# dumpe2fs -h /dev/vda1

 

7、文件系统检验

xfs 文件系统:

xfs_repair /dev/sda2

-d 通常在单用户维护模式下,针对"/"目录进行修复检验。很危险!!!

xfs_repair 可以检验/修复 xfs 文件系统,但检验的文件系统不能被挂载!

ext4 文件系统:

fsck.ext4 /dev/sda2

 

8、挂载

mount、umount

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值