VMware中对系统盘的拓展

背景

我开始创建虚拟机的时候就是按照系统默认的给了20g现在不够用了,所以要扩展Linux的系统盘

在VMware上增加磁盘这个步骤请参照我上一篇文章这里不多加说明

https://blog.csdn.net/qq_21451945/article/details/102785446
这里我贴下我实现的步骤,我会把注释的部分加上表情(CSDN不能添加颜色)

添加的磁盘的分区成系统盘

😂#这个是我原始系统盘的大小
[root@node01 mnt]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G   17G  1.4G  93% /
devtmpfs                 2.9G     0  2.9G   0% /dev
tmpfs                    2.9G     0  2.9G   0% /dev/shm
tmpfs                    2.9G  8.8M  2.9G   1% /run
tmpfs                    2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/sda3                 79G   11G   65G  14% /mnt
/dev/sda1                497M  125M  372M  26% /boot
tmpfs                    580M     0  580M   0% /run/user/996
tmpfs                    580M     0  580M   0% /run/user/0
😂#查看在VMware中添加的磁盘
[root@node01 mnt]# fdisk -l
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00044228

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
/dev/sda3        41943040   209715199    83886080   83  Linux

Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 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

😂#通过上面查询我们知道添加的是sdb,接下我们对它进行分区
[root@node01 mnt]# fdisk /dev/sdb 
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd824defb.

Command (m for help): m  😂#这个可以不用执行,这个是查看命令用的
Command action
   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)

Command (m for help): n 😂#添加分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p  😂#把它划分为主分区
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048):  😂#直接回车(默认起始扇区和最后扇区)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): 😂#直接回车(默认起始扇区和最后扇区)
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set

Command (m for help): t 😂#由于我们上面分区的默认是Linux格式的,系统盘是Linux LVM格式的,因此转换格式
Selected partition 1
Hex code (type L to list all codes): 8e 😂#我们就选用8e的格式
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w  😂#保存我们的分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

挂载系统盘

😂#如下我们能看到我们添加的50G的磁盘已经成为Linux LVM的系统盘格式了
[root@node01 mnt]# fdisk -l
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xd824defb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   104857599    52427776   8e  Linux LVM

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00044228

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
/dev/sda3        41943040   209715199    83886080   83  Linux

Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 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@node01 mnt]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
 😂#查看物理卷组
[root@node01 mnt]# 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.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4984 / 19.47 GiB
  Free  PE / Size       10 / 40.00 MiB
  VG UUID               pHOcHG-qLyN-lTXE-bWLY-uc1X-og0y-cciCzv 
😂#把我们创建的物理卷加入到物理卷组中
[root@node01 mnt]# vgextend /dev/centos  /dev/sdb1 
  Volume group "centos" successfully extended
😂#再次查看,可以发现VG Size已经变成了69.5GiB了,说明成功了
[root@node01 mnt]# vgdisplay
  --- 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               69.50 GiB
  PE Size               4.00 MiB
  Total PE              17793
  Alloc PE / Size       4984 / 19.47 GiB
  Free  PE / Size       12809 / 50.04 GiB
  VG UUID               pHOcHG-qLyN-lTXE-bWLY-uc1X-og0y-cciCzv
😂#查看我们的根目录“/”对应的系统目录映射为/dev/mapper/centos-root
[root@node01 mnt]# df -lh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G   17G  1.4G  93% /
devtmpfs                 2.9G     0  2.9G   0% /dev
tmpfs                    2.9G     0  2.9G   0% /dev/shm
tmpfs                    2.9G  8.8M  2.9G   1% /run
tmpfs                    2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/sda3                 79G   11G   65G  14% /mnt
/dev/sda1                497M  125M  372M  26% /boot
tmpfs                    580M     0  580M   0% /run/user/996
tmpfs                    580M     0  580M   0% /run/user/0
😂#把物理卷组挂载到系统盘的/目录下
[root@node01 mnt]# lvextend -L +51200M /dev/centos/root 
  Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 67.47 GiB (17272 extents).
  Logical volume root successfully resized.
😂#重置根分区的容量,发现如下的错误,请用下面的解决方案
[root@node01 mnt]# resize2fs /dev/centos/root 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.
😂#上面错误的解决方案
[root@node01 mnt]# mount |grep root
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
[root@node01 mnt]# xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1144832 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=4579328, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 4579328 to 17686528
😂#到此为止,系统盘已经从18G扩充到68G了
[root@node01 mnt]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   68G   17G   52G  24% /
devtmpfs                 2.9G     0  2.9G   0% /dev
tmpfs                    2.9G     0  2.9G   0% /dev/shm
tmpfs                    2.9G  8.8M  2.9G   1% /run
tmpfs                    2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/sda3                 79G   11G   65G  14% /mnt
/dev/sda1                497M  125M  372M  26% /boot
tmpfs                    580M     0  580M   0% /run/user/996
tmpfs                    580M     0  580M   0% /run/user/0

有任何问题,欢迎加扫码咨询(备注好对应的技术呦)
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值