VM虚拟机扩容

文章目录

  • 一、配置
  • 二、原因
  • 三、开始扩容
    • 3.1、扩充虚拟机硬盘大小
    • 3.2、扩充虚拟机的分区
    • 3.3、真正分配资源
    • 3.4、查看结果看是否扩充成功(之前是98%现在是62%)

一、配置

CentOs-7
vm15

二、原因

df -hl查看虚拟机内存的时候,空间不足,导致好多操作不行

Linux查看文件大小的简单指令
VM虚拟机扩容_第1张图片

三、开始扩容

3.1、扩充虚拟机硬盘大小

VM虚拟机扩容_第2张图片
VM虚拟机扩容_第3张图片
VM虚拟机扩容_第4张图片

3.2、扩充虚拟机的分区

# 1、查看当前虚拟机的分区
fdisk /dev/sda
# 2、输入 p  (查看已有分区)
Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a6a34

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

# 3、创建分区
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
# 4、确认创建
Select (default p): p
# 5、输入要分区的序号
Partition number (3,4, default 3): 4
# 6、回车
First sector (41943040-83886079, default 41943040):
Using default value 41943040
# 7、回车
Last sector, +sectors or +size{
     K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 4 of type Linux and of size 20 GiB is set
# 8、再用 p查看是否新建出分区
Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a6a34

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda4        41943040    83886079    20971520   83  Linux
# 9、保存结果
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.
# 10、重启虚拟机后生效

3.3、真正分配资源

[root@node132 /root]#pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created.
[root@node132 /root]#df -hl
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G   17G  536M  97% /
devtmpfs                 473M     0  473M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  7.2M  482M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1               1014M  161M  854M  16% /boot
tmpfs                     98M  8.0K   98M   1% /run/user/42
tmpfs                     98M     0   98M   0% /run/user/0
[root@node132 /root]#vgextend /dev/mapper/centos /dev/sda4
  Volume group "centos" successfully extended
 # 这块20G报错了
[root@node132 /root]#vextend -L +20G /dev/mapper/centos-root
bash: vextend: command not found...
[root@node132 /root]#lvextend -L +20G /dev/mapper/centos-root
  Insufficient free space: 5120 extents needed, but only 5119 available
# 所以我又执行的10G
[root@node132 /root]#lvextend -L +10G /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <27.00 GiB (6911 extents).
  Logical volume centos/root successfully resized.

执行这一步的话可能会报错(Bad magic)

[root@node132 /root]#resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

解决方法

# 1、确认文件系统是xfs:
[root@node132 /etc]#cat /etc/fstab
/dev/mapper/centos-root /                       xfs     defaults        0 0

# 2、xfs用以下命令来扩磁盘空间:
[root@node132 /etc]#xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-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 7076864

3.4、查看结果看是否扩充成功(之前是98%现在是62%)

[root@node132 /etc]#df -hl
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   27G   17G   11G  62% /
devtmpfs                 473M     0  473M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  7.2M  482M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1               1014M  161M  854M  16% /boot
tmpfs                     98M   12K   98M   1% /run/user/42
tmpfs                     98M     0   98M   0% /run/user/0

你可能感兴趣的:(#,新增知识,linux,centos)