《Linux实践技能》学习笔记 day11

2023-01-25  本文已影响0人  陈卧虫

Linux 虚拟机 virtualbox 磁盘扩容

  1. 首先在虚拟机中模拟磁盘挂载,先关机,扩容磁盘大小


    image.png
  2. 启动虚拟机,执行 df -h会发现容量并没有变化,因为新扩容的磁盘没有创建分区并使用
[root@10 corey]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  6.8M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root  6.2G  3.8G  2.5G  61% /
/dev/sda1               1014M  138M  877M  14% /boot
tmpfs                    100M     0  100M   0% /run/user/1000
  1. 为新磁盘创建分区
  1. 重启linux: reboot
  2. 重启后,使用 fdisk -l 查看虚拟机的分区情况,此时多了分区 sda3
[root@10 corey]# fdisk -l

Disk /dev/sda: 32.3 GB, 32319209472 bytes, 63123456 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: 0x000be498

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   8e  Linux LVM
/dev/sda3        16777216    63123455    23173120   83  Linux

...
  1. 将新的分区创建为物理卷(pv) ,并添加到已有的卷组中(vgs),最后扩容逻辑卷大小
# 1. 进入lvm管理
lvm

# 2. 初始化刚才的分区3(sda3)
lvm>pvcreate /dev/sda3

# 3. 将初始化过的分区,加入到虚拟卷组centos (卷和卷组的命令可以通过 vgdisplay)
lvm>vgextend centos /dev/sda3

# 4. 查看free PE /Site
lvm>vgdisplay -v
  --- Volume group ---
  VG Name               centos
  ...
  Total PE              7448
  Alloc PE / Size       1791 / <7.00 GiB
  Free  PE / Size       5657 / <22.10 GiB
  VG UUID               i5Ewma-pfyh-WP9b-Q62x-qeCR-51ew-mERXA6
   
  --- Logical volume ---
  ...
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               yfEMCF-0U2f-P1wl-BfzN-QqGh-BzHS-0tR6JH
  PV Status             allocatable
  Total PE / Free PE    1791 / 0
   
  PV Name               /dev/sda3     
  PV UUID               m0ki25-suL5-BOmO-1L4c-Dlfh-VzLz-2irGf3
  PV Status             allocatable
  Total PE / Free PE    5657 / 5657

# 5. 扩展原始逻辑卷的容量 (5657 是通过vgdisplay 或者vgdisplay -v 命令,查看Total PE / Free PE或者free PE / Size 的大小)
lvm>lvextend -l +5657  /dev/mapper/centos-root

# 6. 再次查看是否已经扩容成功
lvm>vgdisplay -v
  ...
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               yfEMCF-0U2f-P1wl-BfzN-QqGh-BzHS-0tR6JH
  PV Status             allocatable
  Total PE / Free PE    1791 / 0
   
  PV Name               /dev/sda3     
  PV UUID               m0ki25-suL5-BOmO-1L4c-Dlfh-VzLz-2irGf3
  PV Status             allocatable
  Total PE / Free PE    5657 / 0

# 7. 退出
lvm>quit
  1. 逻辑卷扩容成功,接下来做 文件系统的扩容
# centos7执行:
xfs_growfs /dev/mapper/centos-root
# centos6执行:
resize2fs /dev/mapper/centos-root

# 注意:/dev/mapper/centos-root 是执行 df -h 时,根目录的挂载点。
  1. 使用df -h查看是否扩容成功
[root@10 corey]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  6.8M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root   29G  3.8G   25G  14% /
/dev/sda1               1014M  138M  877M  14% /boot
tmpfs                    100M     0  100M   0% /run/user/1000
上一篇下一篇

猜你喜欢

热点阅读