yehao
发布于 2023-11-30 / 23 阅读
0
0

虚拟机扩展磁盘

linux扩展磁盘

容量告急

[root@yehao-pc-vm101 ~]# df -lh
文件系统                       容量  已用  可用 已用% 挂载点
devtmpfs                       1.9G     0  1.9G    0% /dev
tmpfs                          1.9G     0  1.9G    0% /dev/shm
tmpfs                          1.9G   13M  1.9G    1% /run
tmpfs                          1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/centos_yehao-root   17G   16G  1.5G   92% /
/dev/sda1                     1014M  151M  864M   15% /boot
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/b2cd1ac68f5598184196af1f94f9121b6864dfc1570d8cafcebd3ab5ce0ad690/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/e2f8063e0970474dfc05006823942cc54deed476ba7b1ac3b6334c93b602a3e9/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/c4b582c55dd7d5039efa9a74228085d4a124068ff3874988a32c829266f55276/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/5c42577432af3c39f229849d0e45b49a379e08ce278d40cd2fd416a755fb2e68/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/9be9740d809a40d24441008572e30e1898b8f47f62b3b8884e1ac4ae39b5df45/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/05dc053b96f8858574c22d15bd20316393d1c45ce2d260f89a3e83773b8a8ed9/merged
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/d7334441c2a97c3435a18a7daa173feb92f79dd9d7bb6558d823afb70b04c53d/merged
tmpfs                          378M     0  378M    0% /run/user/0
overlay                         17G   16G  1.5G   92% /var/lib/docker/overlay2/7a695e0f335a6dee978adbdeda8f759d67e55e5764f2eac0ac89c0e8207ceea7/merged

查看磁盘分区

[root@yehao-pc-vm101 ~]# fdisk -l

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

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

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


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

扩充分区

[root@yehao-pc-vm101 ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (41943040-419430399,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-419430399,默认为 419430399):
将使用默认值 419430399
分区 3 已设置为 Linux 类型,大小设为 180 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。

修改分区

[root@yehao-pc-vm101 ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
Hex 代码(输入 L 列出所有代码):L

 0  空              24  NEC DOS         81  Minix / 旧 Linu bf  Solaris        
 1  FAT12           27  隐藏的 NTFS Win 82  Linux 交换 / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 隐藏的 C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux 扩展      c7  Syrinx         
 5  扩展            41  PPC PReP Boot   86  NTFS 卷集       da  非文件系统数据 
 6  FAT16           42  SFS             87  NTFS 卷集       db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux 纯文本    de  Dell 工具      
 8  AIX             4e  QNX4.x 第2部分  8e  Linux LVM       df  BootIt         
 9  AIX 可启动      4f  QNX4.x 第3部分  93  Amoeba          e1  DOS 访问       
 a  OS/2 启动管理器 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad 休 eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 扩展 (LBA)  54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC  
11  隐藏的 FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq 诊断     5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  隐藏的 FAT16 <3 61  SpeedStor       ab  Darwin 启动     f2  DOS 次要       
16  隐藏的 FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  隐藏的 HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST 智能睡眠    65  Novell Netware  b8  BSDI swap       fd  Linux raid 自动
1b  隐藏的 W95 FAT3 70  DiskSecure 多启 bb  Boot Wizard 隐  fe  LANstep        
1c  隐藏的 W95 FAT3 75  PC/IX           be  Solaris 启动    ff  BBT            
1e  隐藏的 W95 FAT1 80  旧 Minix       
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。

格式化磁盘

[root@yehao-pc-vm101 ~]# mkfs -t ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
11796480 inodes, 47185920 blocks
2359296 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
1440 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成     

将物理磁盘转为物理卷PV,扩展VG

将物理磁盘转为物理卷PV

[root@yehao-pc-vm101 ~]# pvcreate /dev/sda3 WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y   Wiping ext3 signature on /dev/sda3.   Physical volume "/dev/sda3" successfully created.

查看分组并扩展VG


[root@yehao-pc-vm101 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_yehao
  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               cmHWbw-zoKA-Cp1M-1T9l-2IB0-hNY8-f2D9S6
   
[root@yehao-pc-vm101 ~]# vgextend centos_yehao /dev/sda3 

扩展文件系统

将所有空闲空间都加入

[root@yehao-pc-vm101 ~]#  lvextend -l +100%FREE /dev/mapper/centos_yehao-root
  Size of logical volume centos_yehao/root changed from <17.00 GiB (4351 extents) to 196.99 GiB (50430 extents).
  Logical volume centos_yehao/root successfully resized.

扩展xfs文件系统

[root@yehao-pc-vm101 ~]# xfs_growfs /dev/mapper/centos_yehao-root 
meta-data=/dev/mapper/centos_yehao-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 51640320

完成

[root@yehao-pc-vm101 ~]# df -lh
文件系统                       容量  已用  可用 已用% 挂载点
devtmpfs                       1.9G     0  1.9G    0% /dev
tmpfs                          1.9G     0  1.9G    0% /dev/shm
tmpfs                          1.9G   13M  1.9G    1% /run
tmpfs                          1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/centos_yehao-root  197G   16G  182G    8% /
/dev/sda1                     1014M  151M  864M   15% /boot
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/b2cd1ac68f5598184196af1f94f9121b6864dfc1570d8cafcebd3ab5ce0ad690/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/e2f8063e0970474dfc05006823942cc54deed476ba7b1ac3b6334c93b602a3e9/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/c4b582c55dd7d5039efa9a74228085d4a124068ff3874988a32c829266f55276/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/5c42577432af3c39f229849d0e45b49a379e08ce278d40cd2fd416a755fb2e68/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/9be9740d809a40d24441008572e30e1898b8f47f62b3b8884e1ac4ae39b5df45/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/05dc053b96f8858574c22d15bd20316393d1c45ce2d260f89a3e83773b8a8ed9/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/d7334441c2a97c3435a18a7daa173feb92f79dd9d7bb6558d823afb70b04c53d/merged
tmpfs                          378M     0  378M    0% /run/user/0
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/7a695e0f335a6dee978adbdeda8f759d67e55e5764f2eac0ac89c0e8207ceea7/merged
overlay                        197G   16G  182G    8% /var/lib/docker/overlay2/518c23d18116d5fb25d167c1837ee1182268b6d81f5ac00eddfd18addf069036/merged


评论