首页 > 其他 > 详细

虚机扩容

时间:2021-04-08 15:10:47      阅读:14      评论:0      收藏:0      [点我收藏+]
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 722M     0  722M    0% /dev
tmpfs                    739M     0  739M    0% /dev/shm
tmpfs                    739M   11M  728M    2% /run
tmpfs                    739M     0  739M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  5.6G   12G   33% /
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    148M   36K  148M    1% /run/user/0
/dev/sr0                 4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ls /dev/
agpgart          full          network_latency     sr0     tty23  tty42  tty61    vcs5
autofs           fuse          network_throughput  stderr  tty24  tty43  tty62    vcs6
block            hidraw0       null                stdin   tty25  tty44  tty63    vcsa
bsg              hpet          nvram               stdout  tty26  tty45  tty7     vcsa1
btrfs-control    hugepages     oldmem              tty     tty27  tty46  tty8     vcsa2
bus              hwrng         port                tty0    tty28  tty47  tty9     vcsa3
cdrom            initctl       ppp                 tty1    tty29  tty48  ttyS0    vcsa4
centos           input         ptmx                tty10   tty3   tty49  ttyS1    vcsa5
char             kmsg          pts                 tty11   tty30  tty5   ttyS2    vcsa6
console          log           random              tty12   tty31  tty50  ttyS3    vfio
core             loop-control  raw                 tty13   tty32  tty51  uhid     vga_arbiter
cpu              lp0           rtc                 tty14   tty33  tty52  uinput   vhci
cpu_dma_latency  lp1           rtc0                tty15   tty34  tty53  urandom  vhost-net
crash            lp2           sda                 tty16   tty35  tty54  usbmon0  vmci
disk             lp3           sda1                tty17   tty36  tty55  usbmon1  vsock
dm-0             mapper        sda2                tty18   tty37  tty56  usbmon2  zero
dm-1             mcelog        sg0                 tty19   tty38  tty57  vcs
dmmidi           mem           sg1                 tty2    tty39  tty58  vcs1
dri              midi          shm                 tty20   tty4   tty59  vcs2
fb0              mqueue        snapshot            tty21   tty40  tty6   vcs3
fd               net           snd                 tty22   tty41  tty60  vcs4
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# fdisk -l

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e1e5f

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

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):p

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e1e5f

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

命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (41943040-104857599,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-104857599,默认为 104857599):
将使用默认值 104857599
分区 3 已设置为 Linux 类型,大小设为 30 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e1e5f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   104857599    31457280   83  Linux

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 722M     0  722M    0% /dev
tmpfs                    739M     0  739M    0% /dev/shm
tmpfs                    739M   11M  728M    2% /run
tmpfs                    739M     0  739M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  5.6G   12G   33% /
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    148M   40K  148M    1% /run/user/0
/dev/sr0                 4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# fdisk -l

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e1e5f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   104857599    31457280   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost ~]#
[root@localhost ~]# reboot

──────────────────────────────────────────────────────────────────────────────────────────────────────

Session stopped
    - Press <return> to exit tab
    - Press R to restart session
    - Press S to save terminal output to file

Server unexpectedly closed network connection
     ┌────────────────────────────────────────────────────────────────────┐
     │                        ? MobaXterm 11.1 ?                          │
     │            (SSH client, X-server and networking tools)             │
     │                                                                    │
     │ ? SSH session to root@172.16.70.10                                 │
     │   ? SSH compression : ?                                            │
     │   ? SSH-browser     : ?                                            │
     │   ? X11-forwarding  : ?  (remote display is forwarded through SSH) │
     │   ? DISPLAY         : ?  (automatically set on remote server)      │
     │                                                                    │
     │ ? For more info, ctrl+click on help or visit our website           │
     └────────────────────────────────────────────────────────────────────┘

Last login: Thu Apr  8 11:23:28 2021 from 172.16.70.11
[root@localhost ~]# 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.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               Qs8BXE-eTLm-dZoH-Xc7L-XMR5-RErY-Q1di0s

[root@localhost ~]#
[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@localhost ~]#
[root@localhost ~]# 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.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               Qs8BXE-eTLm-dZoH-Xc7L-XMR5-RErY-Q1di0s

[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgextend
  No command with matching syntax recognised.  Run vgextend --help for more information.
  Correct command syntax is:
  vgextend VG PV ...

[root@localhost ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@localhost ~]#
[root@localhost ~]# 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               48.99 GiB
  PE Size               4.00 MiB
  Total PE              12542
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       7679 / <30.00 GiB
  VG UUID               Qs8BXE-eTLm-dZoH-Xc7L-XMR5-RErY-Q1di0s

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 722M     0  722M    0% /dev
tmpfs                    739M     0  739M    0% /dev/shm
tmpfs                    739M   11M  728M    2% /run
tmpfs                    739M     0  739M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  5.6G   12G   33% /
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    148M  8.0K  148M    1% /run/user/42
tmpfs                    148M     0  148M    0% /run/user/0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvextend -L +30G /dev/mapper/centos-root
  Insufficient free space: 7680 extents needed, but only 7679 available
[root@localhost ~]# lvextend -L +29G /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.00 GiB (11775 exten               ts).
  Logical volume centos/root successfully resized.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# 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               PVacQV-0nV5-yCy9-S0Se-LI3J-3BXs-o1fsxh

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               30.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              7679
  Free PE               255
  Allocated PE          7424
  PV UUID               Epgvnz-pUry-DQXI-wlLR-Ncab-SfSv-URt9sZ

[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 722M     0  722M    0% /dev
tmpfs                    739M     0  739M    0% /dev/shm
tmpfs                    739M   11M  728M    2% /run
tmpfs                    739M     0  739M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  5.6G   12G   33% /
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    148M  8.0K  148M    1% /run/user/42
tmpfs                    148M     0  148M    0% /run/user/0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mapper/centos-root 时
找不到有效的文件系统超级块.
[root@localhost ~]# 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 12057600
[root@localhost ~]#
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 722M     0  722M    0% /dev
tmpfs                    739M     0  739M    0% /dev/shm
tmpfs                    739M   11M  728M    2% /run
tmpfs                    739M     0  739M    0% /sys/fs/cgroup
/dev/mapper/centos-root   46G  5.6G   41G   13% /
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    148M  8.0K  148M    1% /run/user/42
tmpfs                    148M     0  148M    0% /run/user/0

 

虚机扩容

原文:https://www.cnblogs.com/castielangel/p/14631528.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!