VM虚拟机安装CentOS7扩展存储空间的方法

VM虚拟机安装CentOS7扩展存储空间的方法
1.在关机状态下,在Vm里面设置系统大小到需要的数值 60G;
2.使用root权限登陆linux,df -h查看系统情况;

# fdisk -l

3.没有找到挂载点,默认是/dev/sda必须要先试用fdisk格式化,初始化挂载磁盘才可以使用

# fdisk /dev/sda

具体如下所示:

[root@code ~]# fdisk -l

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

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

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


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

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

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


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

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

   设备 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):3
起始 扇区 (41943040-125829119,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-125829119,默认为 125829119):
将使用默认值 125829119
分区 3 已设置为 Linux 类型,大小设为 40 GiB

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

命令(输入 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@code ~]# 

4.重启机器;

[root@code ~]# fdisk -l

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

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

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


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

5.格式化分区,mkfs.ext3 /dev/sda3一直挂载的分区是sda3;

[root@code ~]# mkfs.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
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
320 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

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

6.输入以下指令:

lvm    //进入lvm管理
lvm>pvcreate /dev/sda3   
lvm>vgextend cl /dev/sda3  //将初始化过的分区加入到虚拟卷组centos
lvm>vgdisplay -v
lvm>lvextend -l+10239 /dev/mapper/cl-root
lvm>pvdisplay   //查看卷容量
lvm>quit   

具体如下操作:

[root@code ~]# 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 cl /dev/sda3
  Volume group "cl" successfully extended
lvm> vgdisplay -v
  --- Volume group ---
  VG Name               cl
  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               58.99 GiB
  PE Size               4.00 MiB
  Total PE              15102
  Alloc PE / Size       4863 / 19.00 GiB
  Free  PE / Size       10239 / 40.00 GiB
  VG UUID               on4380-dNuw-urE1-TJDY-35tA-4vfc-GpyR2G
   
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                ZsoXDE-3M6U-G8y4-ciui-t4ZU-369P-LGDrfW
  LV Write Access        read/write
  LV Creation host, time code, 2018-08-28 22:25:06 +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/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                6uJJVw-T2Ki-XTRF-ARJA-EkVl-3qz0-l86XMp
  LV Write Access        read/write
  LV Creation host, time code, 2018-08-28 22:25:06 +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               iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
  PV Name               /dev/sda3     
  PV UUID               WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
  PV Status             allocatable
  Total PE / Free PE    10239 / 10239
   
lvm> lvextend -l+1298 /dev/mapper/cl-root
  Size of logical volume cl/root changed from 17.00 GiB (4351 extents) to 22.07 GiB (5649 extents).
  Logical volume cl/root successfully resized.
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                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               58.99 GiB
  PE Size               4.00 MiB
  Total PE              15102
  Alloc PE / Size       6161 / 24.07 GiB
  Free  PE / Size       8941 / 34.93 GiB
  VG UUID               on4380-dNuw-urE1-TJDY-35tA-4vfc-GpyR2G
   
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                ZsoXDE-3M6U-G8y4-ciui-t4ZU-369P-LGDrfW
  LV Write Access        read/write
  LV Creation host, time code, 2018-08-28 22:25:06 +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/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                6uJJVw-T2Ki-XTRF-ARJA-EkVl-3qz0-l86XMp
  LV Write Access        read/write
  LV Creation host, time code, 2018-08-28 22:25:06 +0800
  LV Status              available
  # open                 1
  LV Size                22.07 GiB
  Current LE             5649
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
  PV Name               /dev/sda3     
  PV UUID               WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
  PV Status             allocatable
  Total PE / Free PE    10239 / 8941
   
lvm> lvextend -l+8941 /dev/mapper/cl-root
  Size of logical volume cl/root changed from 22.07 GiB (5649 extents) to 56.99 GiB (14590 extents).
  Logical volume cl/root successfully resized.
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  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               iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               cl
  PV Size               40.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10239
  Free PE               0
  Allocated PE          10239
  PV UUID               WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
lvm> quit
  Exiting.
[root@code ~]# 

7.使用命令xfs_growfs /dev/mapper/cl-root扩展容量。
8.使用df -h可以看到扩展成功。

[root@code ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-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 14940160
[root@code ~]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root   57G  4.8G   53G    9% /
devtmpfs             902M     0  902M    0% /dev
tmpfs                912M     0  912M    0% /dev/shm
tmpfs                912M  8.6M  904M    1% /run
tmpfs                912M     0  912M    0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M   14% /boot
tmpfs                183M     0  183M    0% /run/user/0
[root@code ~]# 

—the–end—

猜你喜欢

转载自blog.csdn.net/hsg77/article/details/84138221