Centos7扩展存储空间
1.在关机状态下,在Vm里面设置系统大小到需要的数值 ;
2.使用root权限登陆linux,df -h查看系统情况;
[root@cratedb-hk-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 1.5G 49G 3% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.2G 0 3.2G 0% /dev/shm
tmpfs 3.2G 9.1M 3.2G 1% /run
tmpfs 3.2G 0 3.2G 0% /sys/fs/cgroup
/dev/xvda1 1014M 185M 830M 19% /boot
/dev/mapper/centos-home 46G 33M 46G 1% /home
tmpfs 649M 0 649M 0% /run/user/0
fdisk -l
[root@cratedb-hk-01 ~]# fdisk -l
磁盘 /dev/xvda:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009e984
设备 Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 209715199 103808000 8e Linux LVM
3.没有找到挂载点,默认是/dev/sda或/dev/xvda必须要先试用fdisk格式化,初始化挂载磁盘才可以使用
[root@cratedb-hk-01 ~]# fdisk /dev/xvda 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 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/xvda:214.7 GB, 214748364800 字节,419430400 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x0009e984 设备 Boot Start End Blocks Id System /dev/xvda1 * 2048 2099199 1048576 83 Linux /dev/xvda2 2099200 209715199 103808000 8e Linux LVM 命令(输入 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 获取帮助):n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p 分区号 (3,4,默认 3):3 起始 扇区 (209715200-419430399,默认为 209715200): 将使用默认值 209715200 Last 扇区, +扇区 or +size{K,M,G} (209715200-419430399,默认为 419430399): 将使用默认值 419430399 分区 3 已设置为 Linux 类型,大小设为 100 GiB 命令(输入 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 获取帮助):t 分区号 (1-3,默认 3):3 Hex 代码(输入 L 列出所有代码):8e 已将分区“Linux”的类型更改为“Linux LVM” 命令(输入 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 获取帮助):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) 正在同步磁盘。
4:重启服务器
reboot
[root@cratedb-hk-01 ~]# fdisk -l
磁盘 /dev/xvda:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009e984
设备 Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 209715199 103808000 8e Linux LVM
/dev/xvda3 209715200 419430399 104857600 8e Linux LVM
5:格式化分区,mkfs.ext3 /dev/xvda3一直挂载的分区是xvda3;
[root@cratedb-hk-01 ~]# mkfs.ext3 /dev/xvda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
800 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
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6:输入以下指令:
[root@cratedb-hk-01 ~]# lvm
lvm> pvcreate /dev/xvda3
WARNING: ext3 signature detected on /dev/xvda3 at offset 1080. Wipe it? [y/n]: y
Wiping ext3 signature on /dev/xvda3.
Physical volume "/dev/xvda3" successfully created.
lvm> vgextend centos /dev/xvda3
Volume group "centos" successfully extended
lvm> vgdisplay -v
--- Volume group ---
VG Name centos
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 198.99 GiB
PE Size 4.00 MiB
Total PE 50942
Alloc PE / Size 25342 / 98.99 GiB
Free PE / Size 25600 / 100.00 GiB
VG UUID Sa8iIa-EBdf-F0Zz-IJ3z-Xozx-L0Ob-ThRrNk
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 807WWG-hzhk-ichE-AEO2-HKaU-yCe4-rd8lob
LV Write Access read/write
LV Creation host, time localhost, 2019-01-18 15:47:56 +0800
LV Status available
# open 2
LV Size <3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID Lhl3gA-NKbL-8mod-hAiR-TE7G-9ZUC-PsfGG9
LV Write Access read/write
LV Creation host, time localhost, 2019-01-18 15:47:56 +0800
LV Status available
# open 1
LV Size <45.12 GiB
Current LE 11550
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID fOFhxK-gwNY-zuht-W64P-dQ5H-hTUJ-qXTSRk
LV Write Access read/write
LV Creation host, time localhost, 2019-01-18 15:47:56 +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 ZItt1Y-FCC3-IxP9-Pw7C-0aJi-Yee4-WG3005
PV Status allocatable
Total PE / Free PE 25343 / 1
PV Name /dev/xvda3
PV UUID i3nEKb-grlP-cY7S-ayUf-WErf-d0dn-PMLRv3
PV Status allocatable
Total PE / Free PE 25599 / 25599
lvm> lvextend -l +25599 /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <150.00 GiB (38399 extents).
Logical volume centos/root successfully resized.
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/xvda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25343
Free PE 0
Allocated PE 25343
PV UUID ZItt1Y-FCC3-IxP9-Pw7C-0aJi-Yee4-WG3005
--- Physical volume ---
PV Name /dev/xvda3
VG Name centos
PV Size 100.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 1
Allocated PE 25598
PV UUID i3nEKb-grlP-cY7S-ayUf-WErf-d0dn-PMLRv3
lvm> quit
Exiting.
7:扩展容量:
[root@cratedb-hk-01 ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-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 39320576
8:使用df -h查看
[root@cratedb-hk-01 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 150G 1.5G 149G 1% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs 2.4G 9.0M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/xvda1 1014M 185M 830M 19% /boot /dev/mapper/centos-home 46G 33M 46G 1% /home tmpfs 484M 0 484M 0% /run/user/0 [root@cratedb-hk-01 ~]#
感谢:
https://www.cnblogs.com/panghaohan/p/6477517.html