欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux 磁盘命令

程序员文章站 2022-06-04 12:31:00
...

1. fdisk -l 显示所有磁盘

[[email protected] ~]# fdisk -l

磁盘 /dev/sda:549.8 GB, 549755813888 字节,1073741824 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d7fc1

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040  1073741823   515899392   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

2 fdisk /dev/sda 分区

3 vgdisplay 查看卷组

[[email protected] ~]#  vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               5CPnC1-vu0S-0azF-DaTg-hi3u-kLRT-GeoKpV

4 . pvdisplay 物理卷

[[email protected] ~]#  pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               Z0Xemc-hA5J-afVQ-2SJc-siNF-Dzrt-5gHF0y

5.lvdisplay 逻辑卷

[[email protected] ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                T5LgWb-Ms7I-T0QN-Isdr-cda3-0Ax3-nM4Jp0
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-10-25 13:06:49 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                U41UO2-2lvo-cpY7-k8is-u4qh-SAYC-rerShQ
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-10-25 13:06:50 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

6. pvcreate /dev/sda3

创建物理卷

7.vgextend centos /dev/sda3

将物理卷/dev/sda3加入卷组centos

8. lvextend -l +10240 /dev/centos/root

为逻辑卷/dev/centos/root增加空间

9. resize2fs -f /dev/centos/root

10 xfs_growfs /dev/centos/root

11 du -h -d 1

查看目录中文件所占空间

[[email protected] ~]# du -h -d 1
26M	./.cache
8.0K	./.dbus
96K	./.config
1.5M	./.local
0	./桌面
0	./下载
0	./模板
0	./公共
0	./文档
0	./音乐
0	./图片
0	./视频
63M	./.mozilla
0	./.pki
12K	./.gnupg
8.0K	./.ssh
4.0K	./.oracle_jre_usage
0	./application
48K	./.java
8.0K	./tmp
90M	.

12 df -h

查看分区

[[email protected] ~]# df  -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 3.9G     0  3.9G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G   18M  3.9G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  8.2G  8.9G   48% /
/dev/sda1               1014M  237M  778M   24% /boot
/dev/sda3                485G  433G   28G   95% /anjj
tmpfs                    783M   12K  783M    1% /run/user/42
tmpfs                    783M     0  783M    0% /run/user/0