VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)

磁盘扩展

一、Centos 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”

VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)
image
VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)
image
VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)
image

登录系统

二、启动客户机操作系统 Centos,在操作系统内部对磁盘重新分区和扩容

1、fdisk -l

Disk /dev/loop0: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM

Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000

2、其中,可以看到现在的分区情况如下

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM

3、创建分区 sda3 fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It s strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n           # 输入 n 表示创建新分区
Command action
   e   extended
   p   primary partition (1-4)
   p                                            # 默认输入P
Partition number (1-4): 3   # 输入 3 表示sda3,因为前面已经有两个了
First cylinder (1306-4568, default 1306):     # 回车,按默认值
Using default value 1306
Last cylinder, +cylinders or +size{K,M,G} (1306-4568, default 4568):   # 回车,按默认值
Using default value 4568

Command (m for help): w     # 输入 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.

再次查看分区情况 fdisk -l

Disk /dev/loop0: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM
/dev/sda3            1306        4568    26206700   83  Linux

Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000

其中,分区已变为 3 个(/dev/sda1,/dev/sda2,/dev/sda3)了,但这时还没挂载,还不能用,

4、重启操作系统

reboot

5、格式化新分区为 ext3


[root@shuang ~]# 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
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

6、将物理硬盘分区初始化为物理卷,以便被 LVM 使用,输入指令

[root@shuang ~]# lvs
  LV   VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_shuang -wi-ao---- <17.00g
  swap centos_shuang -wi-ao----   2.00g
[root@shuang ~]# lvs
pvcreate /dev/sda3  LV   VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_shuang -wi-ao---- <17.00g
  swap centos_shuang -wi-ao----   2.00g
[root@shuang ~]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]:
  WARNING: Invalid input ''.
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: ^H^H^Hy
  WARNING: Invalid input 'y'.
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.


7、向卷组中添加物理卷来增加卷组的容量

要查询Volume Group(卷组)的信息,在CentOS系统中,可以使用以下命令:

1. **使用vgs命令**:`vgs`命令用于显示系统中所有卷组的状态、大小和可用空间等相关信息。这是一个快速查看卷组概览的方法。
2. **使用vgdisplay命令**:如果您想要获取某个具体卷组的详细信息,包括其挂载的文件系统、使用的格式以及空间使用情况,可以执行`vgdisplay`命令。通过这个命令,您可以得到更详细的卷组信息。

此外,您还可以使用`pvs`命令来查看卷组中的Physical Volumes(物理卷),以及`lvs`命令来查看Logical Volumes(逻辑卷)。

总的来说,这些命令都是LVM(逻辑卷管理)工具集中的一部分,它们可以帮助您管理和监控CentOS系统中的逻辑卷和卷组。在使用这些命令时,请确保您具有足够的权限,通常需要root用户或者通过sudo命令来执行。
[root@shuang ~]#  df -h
文件系统                        容量  已用  可用 已用% 挂载点
devtmpfs                        1.2G     0  1.2G    0% /dev
tmpfs                           1.2G     0  1.2G    0% /dev/shm
tmpfs                           1.2G  9.9M  1.2G    1% /run
tmpfs                           1.2G     0  1.2G    0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root   17G  6.4G   11G   38% /
/dev/sda1                      1014M  184M  831M   19% /boot
tmpfs                           229M     0  229M    0% /run/user/0

其中 centos_shuang 是组名

[root@shuang ~]# vgextend centos_shuang-root  /dev/sda3
  Volume group "centos_shuang-root" not found
  Cannot process volume group centos_shuang-root
[root@shuang ~]# vgextend centos_shuang  /dev/sda3
  Volume group "centos_shuang" successfully extended

8、查看可扩展的空间大小

vgdisplay

 vgdisplay
  --- Volume group ---
  VG Name               centos_shuang
  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               B8mmPl-Nyh8-N9yN-7OQf-in8I-neL7-zFrK2P

其中 Free PE / Size 就是可供分配的自由空间,最多有 19G,在扩展时输入小于该值

9、扩充磁盘空间

lvextend -L+19G /dev/mapper/centos_shuang-root /dev/sda3

lvextend -L+19G  /dev/mapper/centos_shuang-root     /dev/sda3
  Size of logical volume centos_shuang/root changed from <17.00 GiB (4351 extents) to <36.00 GiB (9215 extents).
  Logical volume centos_shuang/root successfully resized.

10、使用 e2fsck 指令检查文件系统错误

e2fsck -a /dev/mapper/centos_shuang-root

e2fsck -a /dev/mapper/centos_shuang-root
/dev/mapper/centos_shuang-root is mounted.
e2fsck: 无法继续, 中止.

查看 lv 空间是否扩充成功

lvdisplay

[root@shuang ~]#  lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_shuang/swap
  LV Name                swap
  VG Name                centos_shuang
  LV UUID                bc72KO-b6hy-IvVN-MXSk-OUKM-7JTV-EcPJ2E
  LV Write Access        read/write
  LV Creation host, time shuang, 2020-01-09 13:54:14 +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_shuang/root
  LV Name                root
  VG Name                centos_shuang
  LV UUID                j37rXa-Ug0E-Y2sE-hz6m-QpEw-LX1X-LLCgTo
  LV Write Access        read/write
  LV Creation host, time shuang, 2020-01-09 13:54:15 +0800
  LV Status              available
  # open                 1
  LV Size                <36.00 GiB
  Current LE             9215
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

11、使用 Centeros7 指令 xfs_growfs /dev/mapper/centos_shuang-root 将 LV 空间同步到文件系统根目录中

 xfs_growfs    /dev/mapper/centos_shuang-root
meta-data=/dev/mapper/centos_shuang-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 9436160

12 验证查看是否同步成功

在 CenterOS7 系列中 xfs 同步要用下面这个命令xfs_growfs

[root@shuang ~]# df -h
文件系统                        容量  已用  可用 已用% 挂载点
devtmpfs                        1.2G     0  1.2G    0% /dev
tmpfs                           1.2G     0  1.2G    0% /dev/shm
tmpfs                           1.2G  9.9M  1.2G    1% /run
tmpfs                           1.2G     0  1.2G    0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root   36G  6.4G   30G   18% /
/dev/sda1                      1014M  184M  831M   19% /boot
tmpfs                           229M     0  229M    0% /run/user/0

根目录 36G,扩容成功!


原文始发于微信公众号(有追求的开发者):VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/256941.html

(0)
李, 若俞的头像李, 若俞

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!