Vmware centos 虚拟机扩容
  q1aWAeXI3uNc 2023年11月02日 55 0


文章目录

  • ​​虚拟机硬盘容量扩展​​
  • ​​初始化硬盘并合并​​

虚拟机硬盘容量扩展

虚拟机设置->硬盘->扩展

Vmware centos 虚拟机扩容_虚拟机

修改要扩展到的容量 点击扩展

Vmware centos 虚拟机扩容_Centos_02

然后重启虚拟机

初始化硬盘并合并

进入 刚才扩展空间的的虚拟机
查看磁盘总容量并分区
对系统磁盘扩容后,我们需要查看当前磁盘的容量,当前磁盘默认会在/dev/sda路径下。此时可以使用命令进行查

[root@host11 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p --输入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: 0x0009e458

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

Command (m for help): n --新建分区命令:n

Partition type: --(直接回车,默认为主分区(primary);分区号,起始扇区,结束扇区都用默认,一路回车,直到提示继续输入Fdisk命令的位置。)
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set
--为分区设置分区格式,在Fdisk命令处输入:t
Command (m for help): t
Partition number (1-3, default 3): --分区号用默认,直接回车,
Hex code (type L to list all codes): 8e --Hex代码输入:8e。代表适用Linux LVM分区类型。
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w --最后写入分区表,在Fdisk命令位置输入: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.



[root@host11 ~]# fdisk -l ---查看磁盘分区到了一个 sda3

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: 0x0009e458

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

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

格式化新分区
重启系统

[root@host11 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@host11 ~]# mkfs.ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

然后合并分区
合并操作我们需要在LVM中进行操作。 直接输入如下命令

[root@host11 ~]# lvm
lvm> pvcreate /dev/sda3 -- 对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.
// lvm 中执行 或者 不在lvm 中执行也可以 将新分区添加进系统默认的Volume group
//,centOS的默认Volume group为centos
[root@host11 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@host11 ~]# vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 38.99 GiB
PE Size 4.00 MiB
Total PE 9982
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID DSYDbO-xeu1-kOdN-3DXb-Q3xH-LVsE-1vz1IL

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID bIDcdG-1zD5-p7vC-OFZ3-27iR-PvxV-oh5YPL
LV Write Access read/write
LV Creation host, time localhost, 2021-04-06 19:40:07 +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 RCwYgj-CujI-sO4k-b6KH-E55s-VDkf-WYJc0d
LV Write Access read/write
LV Creation host, time localhost, 2021-04-06 19:40:07 +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

--- Physical volumes ---
PV Name /dev/sda2
PV UUID wsD0Bk-9Fpo-cLiE-ycfz-Ec8u-ckzo-YXdSxB
PV Status allocatable
Total PE / Free PE 4863 / 0

PV Name /dev/sda3 //我们看到 多了一个 硬盘
PV UUID LEXAzk-MCoo-gFMz-r6Kn-uSLc-6CLc-DL9yRL
PV Status allocatable
Total PE / Free PE 5119 / 5119

[root@host11 ~]# lvextend -l+5119 /dev/mapper/centos-root //将sda三的剩余容量合并到 系统盘 /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 36.99 GiB (9470 extents).
Logical volume centos/root successfully resized.
You have new mail in /var/spool/mail/root

验证结果

[root@host12 ~]# fdisk -l

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: 0x0009e458

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

Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4koL3J55wyKx   2023年11月13日   38   0   0 icogitCentOS
  9E2BTpjt8nym   2023年12月06日   37   0   0 WindowsgitCentOS
q1aWAeXI3uNc