VMware虚拟机扩容根目录磁盘容量

1、在VMware上扩展磁盘容量,由20G扩展到30G;

VMware虚拟机扩容根目录磁盘容量_第1张图片

VMware虚拟机扩容根目录磁盘容量_第2张图片

VMware虚拟机扩容根目录磁盘容量_第3张图片

这里提示我们需要到客户端虚拟机进行分区和扩展文件系统,因此进入系统

2、开启虚拟机

3、查看磁盘信息,可以看到系统下只有一块硬盘sda;

[root@hadoop001 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  5.3G   12G  32% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M  15% /boot
tmpfs                    378M     0  378M   0% /run/user/0

发现目前依然是20G,接下来进行重新分区

4、使用fdisk分区工具给sda磁盘分区

依次运行如下命令(备注回车的直接回车即可)

[root@hadoop101 ~]# fdisk /dev/sda
p	//查看已分区数量
n	//新增加一个分区
回车	//分区类型选择主分区
回车	//选择默认即可,会有提示(有时不需要输入)
回车	//默认(起始扇区)
回车	//默认(结束扇区)
t	//修改分区类型
回车	//选择默认即可,会有提示
8e	//修改为LVM(8e就是LVM)
w	//保存刚才创建的分区
q	//完成,退出fdisk命令(有时不需要输入)

具体信息如下


[root@hadoop001 ~]# 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 //查看已分区数量

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000bb9ca

   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 //新增加一个分区
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):  //回车,这里是选择分区类型,使用默认值,也就是主分区
Using default response p
Partition number (3,4, default 3):  //回车,使用默认值即可,选择分区数量,会自己增加,如果有两个,默认就是3
First sector (41943040-62914559, default 41943040):  //回车,默认值 起始扇区
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-62914559, default 62914559):  //回车,默认值 结束扇区
Using default value 62914559
Partition 3 of type Linux and of size 10 GiB is set

Command (m for help): t  //修改分区类型
Partition number (1-3, default 3):  //回车,选择默认值
Hex code (type L to list all codes): 8e  //修改为LVM(8e就是LVM)
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.

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.

操作完上述命令后,使用命令partprobe命令或者重启机器(reboot),这是为了将分区信息记录到分区表中

[root@hadoop001 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

将sda3分区创建为文件系统

[root@hadoop001 ~]# mkfs.ext3 /dev/sda3  //注意:这里命令里面的数字3,就是刚刚默认的数字3,表示第三个分区
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
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

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

然后添加新LVM组到已有的LVM组,实现扩容

  • 运行以下命令
[root@hadoop101 ~]# lvm	//进入LVM管理
lvm> pvcreate /dev/sda3	//这是初始化刚才的分区,必须的
lvm> vgextend centos /dev/sda3	//将初始化的分区加入虚拟卷组centos(卷和卷组的名字可以通过命令vgdisplay查看)
lvm> vgdisplay -v	//查看信息
lvm> lvextend -l+2559 /dev/mapper/centos-root	//扩展已有卷的容量(2559是通过vgdisplay查看Free PE的大小)
lvm> pvdisplay	//查看卷容量,这时你会看到一个很大的卷了
lvm> quit	//退出LVM

详细如下


[root@hadoop001 ~]# lvm
lvm> 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.
lvm> vgextend centos /dev/sda3
  Volume group "centos" successfully extended
lvm> 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               28.99 GiB
  PE Size               4.00 MiB
  Total PE              7422
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       2559 / <10.00 GiB
  VG UUID               9v61W3-Drxo-eChN-R0XD-WDiW-whpZ-KBiclc

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                fgeNJN-AtOy-p9vf-J7c0-gxbs-WQUl-063gzs
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2020-09-03 17:20:37 +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                ewpcko-ikLq-8mf0-7FBd-vh1T-CeFa-0deGLM
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2020-09-03 17:20:37 +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               dBpY7w-uAnU-0op0-Va8Z-dkfW-D4Qd-gWwPTb
  PV Status             allocatable
  Total PE / Free PE    4863 / 0

  PV Name               /dev/sda3
  PV UUID               OBQaoV-uFIN-g22r-1Y3m-Gq55-ejUf-t47p6s
  PV Status             allocatable
  Total PE / Free PE    2559 / 2559

lvm> lvextend -l+2559 /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 26.99 GiB (6910 extents).
  Logical volume centos/root successfully resized.
lvm> 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               dBpY7w-uAnU-0op0-Va8Z-dkfW-D4Qd-gWwPTb

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               0
  Allocated PE          2559
  PV UUID               OBQaoV-uFIN-g22r-1Y3m-Gq55-ejUf-t47p6s

VMware虚拟机扩容根目录磁盘容量_第4张图片

lvextend -l+2559 /dev/mapper/centos-root(这里的2559数字从这获得,根据自己的更改)

  • 这里要注意以下,在命令lvm>vgextend centos /dev/sda4和lvm>lvextend -l+2559 /dev/mapper/centos-root中,不是每个虚拟机命令都是cl,这个具体要看你的虚拟机文件系统配置,如果是cl-root,可以直接使用命令,否则需要按照自己的文件系统进行一些修改

接下来将添加的硬盘,添加至根分区

[root@hadoop001 ~]# lvextend -l +100%FREE /dev/centos/root
  New size (6910 extents) matches existing size (6910 extents).

以上是完成了卷的扩容,还需要对文件系统扩容进行操作

[root@hadoop001 ~]# 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 7075840

查看一下磁盘空间

VMware虚拟机扩容根目录磁盘容量_第5张图片

你可能感兴趣的:(其他)