VM虚拟机安装CentOS7添加硬盘扩展存储空间的方法
总结过程步骤如下:

 fdisk -l
 fdisk /dev/xvdb
 p
 
 n
 p
 
 t
 8e
 w
 
reboot
fdisk -l
mkfs.ext3 /dev/xvdb1        #mkfs -t xfs   /dev/xvdb1 
lvm
pvcreate /dev/xvdb1
y
vgextend cl /dev/xvdb1
vgdisplay -v
lvextend -l+511999 /dev/mapper/cl-root
pvdisplay
quit

df -h
xfs_growfs /dev/mapper/cl-root
df -h

具体操作过程如下:

[root@node115 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   50G   17G   34G   34% /
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.7G     0  7.7G    0% /dev/shm
tmpfs                7.7G  8.5M  7.7G    1% /run
tmpfs                7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/xvda1          1014M  138M  877M   14% /boot
/dev/mapper/cl-home   62G   33M   62G    1% /home
tmpfs                1.6G     0  1.6G    0% /run/user/0
[root@node115 ~]# fdisk -l

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/xvda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009f539

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   251658239   124779520   8e  Linux LVM

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


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


磁盘 /dev/mapper/cl-home:65.8 GB, 65758298112 字节,128434176 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

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

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

Device does not contain a recognized partition table
使用磁盘标识符 0x0afb3533 创建新的 DOS 磁盘标签。

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

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0afb3533

    设备 Boot      Start         End      Blocks   Id  System

命令(输入 m 获取帮助):m
命令操作
   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)

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

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0afb3533

    设备 Boot      Start         End      Blocks   Id  System

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

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

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

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@node115 ~]# fdisk -l

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0afb3533

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvdb1            2048  4194303999  2097150976   8e  Linux LVM

磁盘 /dev/xvda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009f539

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   251658239   124779520   8e  Linux LVM

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


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


磁盘 /dev/mapper/cl-home:65.8 GB, 65758298112 字节,128434176 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

重启机子


[root@node115 ~]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.30.115) at 10:18:05.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ 

Connecting to 192.168.30.115:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu Nov 22 09:53:06 2018 from hsgpc
[root@node115 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   50G   17G   34G   33% /
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.7G     0  7.7G    0% /dev/shm
tmpfs                7.7G  8.4M  7.7G    1% /run
tmpfs                7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/xvda1          1014M  138M  877M   14% /boot
/dev/mapper/cl-home   62G   33M   62G    1% /home
tmpfs                1.6G     0  1.6G    0% /run/user/0
[root@node115 ~]# fdisk -l

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0afb3533

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvdb1            2048  4194303999  2097150976   8e  Linux LVM

磁盘 /dev/xvda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009f539

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   251658239   124779520   8e  Linux LVM

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


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


磁盘 /dev/mapper/cl-home:65.8 GB, 65758298112 字节,128434176 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@node115 ~]# vgdisplay
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               119.00 GiB
  PE Size               4.00 MiB
  Total PE              30463
  Alloc PE / Size       30462 / 118.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               PQLECv-i0Yr-sgLQ-kNGU-HswJ-dHZn-rdXjVA
   
[root@node115 ~]# mkfs.ext3 /dev/xvdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072000 inodes, 524288000 blocks
26214400 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
16000 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848, 512000000

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成       

[root@node115 ~]# lvm
lvm> vgdisplay -v
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               119.00 GiB
  PE Size               4.00 MiB
  Total PE              30463
  Alloc PE / Size       30462 / 118.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               PQLECv-i0Yr-sgLQ-kNGU-HswJ-dHZn-rdXjVA
   
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                ZvBdC9-snr8-d7yZ-Y2Lj-HTnM-84kp-SX6ny3
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 2
  LV Size                7.75 GiB
  Current LE             1984
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                E5GahN-x1E9-LeYz-Al42-IDjn-PKD4-BNZ97U
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 1
  LV Size                61.24 GiB
  Current LE             15678
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                bryF7M-XMOy-YZbe-z4Zk-7t4s-2jwX-79so4y
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/xvda2     
  PV UUID               HJjZMK-sxkD-ZKBv-4tCT-yo2d-ielX-wK5Xm3
  PV Status             allocatable
  Total PE / Free PE    30463 / 1
   
lvm> pvcreate /dev/xvdb1
WARNING: ext3 signature detected on /dev/xvdb at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/xvdb1.
  Physical volume "/dev/xvdb1" successfully created.
lvm> vgextend cl /dev/xvdb1
  Volume group "cl" successfully extended
lvm> vgdisplay -v
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               2.07 TiB
  PE Size               4.00 MiB
  Total PE              542462
  Alloc PE / Size       30462 / 118.99 GiB
  Free  PE / Size       512000 / 1.95 TiB
  VG UUID               PQLECv-i0Yr-sgLQ-kNGU-HswJ-dHZn-rdXjVA
   
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                ZvBdC9-snr8-d7yZ-Y2Lj-HTnM-84kp-SX6ny3
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 2
  LV Size                7.75 GiB
  Current LE             1984
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                E5GahN-x1E9-LeYz-Al42-IDjn-PKD4-BNZ97U
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 1
  LV Size                61.24 GiB
  Current LE             15678
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                bryF7M-XMOy-YZbe-z4Zk-7t4s-2jwX-79so4y
  LV Write Access        read/write
  LV Creation host, time node1, 2018-11-08 18:06:09 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/xvda2     
  PV UUID               HJjZMK-sxkD-ZKBv-4tCT-yo2d-ielX-wK5Xm3
  PV Status             allocatable
  Total PE / Free PE    30463 / 1
   
  PV Name               /dev/xvdb1     
  PV UUID               OPV4yv-UjWr-g1p1-8FoB-3iRS-YIYo-dRw2se
  PV Status             allocatable
  Total PE / Free PE    511999 / 511999
   
lvm> lvextend -l+511999 /dev/mapper/cl-root
  Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 2.00 TiB (524799 extents).
  Logical volume cl/root successfully resized.
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/xvda2
  VG Name               cl
  PV Size               119.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              30463
  Free PE               0
  Allocated PE          30463
  PV UUID               HJjZMK-sxkD-ZKBv-4tCT-yo2d-ielX-wK5Xm3
   
  --- Physical volume ---
  PV Name               /dev/xvdb1
  VG Name               cl
  PV Size               1.95 TiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              511999
  Free PE               1
  Allocated PE          511998
  PV UUID               OPV4yv-UjWr-g1p1-8FoB-3iRS-YIYo-dRw2se
   
lvm> quit
  Exiting.
[root@node115 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   50G   17G   34G   33% /
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.7G     0  7.7G    0% /dev/shm
tmpfs                7.7G  8.4M  7.7G    1% /run
tmpfs                7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/xvda1          1014M  138M  877M   14% /boot
/dev/mapper/cl-home   62G   33M   62G    1% /home
tmpfs                1.6G     0  1.6G    0% /run/user/0
[root@node115 ~]# fdisk -l

磁盘 /dev/xvdb:2147.5 GB, 2147483648000 字节,4194304000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/xvda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009f539

    设备 Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   251658239   124779520   8e  Linux LVM

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


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


磁盘 /dev/mapper/cl-home:65.8 GB, 65758298112 字节,128434176 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@node115 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   50G   17G   34G   33% /
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.7G     0  7.7G    0% /dev/shm
tmpfs                7.7G  8.4M  7.7G    1% /run
tmpfs                7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/xvda1          1014M  138M  877M   14% /boot
/dev/mapper/cl-home   62G   33M   62G    1% /home
tmpfs                1.6G     0  1.6G    0% /run/user/0
[root@node115 ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 537394176
[root@node115 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root  2.1T   17G  2.0T    1% /
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.7G     0  7.7G    0% /dev/shm
tmpfs                7.7G  8.4M  7.7G    1% /run
tmpfs                7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/xvda1          1014M  138M  877M   14% /boot
/dev/mapper/cl-home   62G   33M   62G    1% /home
tmpfs                1.6G     0  1.6G    0% /run/user/0
[root@node115 ~]# 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐