热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

vamwarecentos7根目录扩容

背景:源码编译软件的时候,发现原先定的磁盘容量不够了,root目录17G都用完了,不想换目录,那就需要扩展磁盘

背景:源码编译软件的时候,发现原先定的磁盘容量不够了,root目录17G都用完了,不想换目录,那就需要扩展磁盘容量,需要扩展root目录

一.扩展物理磁盘

1.先关闭虚拟机,右键虚拟机设置:点扩展
在这里插入图片描述

启动VMware环境下的Linux操作系统,需要root账号身份登陆

2、[root@localhost ~]# fdisk -l
最大分区为/dev/sda2,说明新创建的分区将会是sda3
在这里插入图片描述
3、[root@localhost ~]# fdisk /dev/sda 使用fdisk /dev/sda进入菜单项,m是列出菜单,p是列出分区表,n是增加分区,w是保存并退出

[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000ba2b5

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

Command (m for help): n

Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):p
Partition number (1-4): 3
4、有默认值的就回车使用默认值
5、Command (m for help): w 保存修改
6、[root@localhost ~]# reboot

二、虚拟机扩容
1、查看磁盘编号
[dyx@localhost ~]$ ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3

2、创建pv
[root@localhost dyx]# pvcreate /dev/sda3
Physical volume “/dev/sda3” successfully created.

3、把pv加入vg中,相当于扩充vg的大小
[root@localhost dyx]# vgs *** 先使用vgs查看vg组
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz–n- <19.00g 0

[root&#64;localhost dyx]# vgextend centos /dev/sda3 *** 扩展vg&#xff0c;使用vgextend命令
Volume group “centos” successfully extended

4、成功把vg卷扩展了&#xff0c;再用vgs查看一下
[root&#64;localhost dyx]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz–n- 19.99g <10.00g

[root&#64;localhost dyx]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <17.00g
swap centos -wi-ao---- 2.00g
虽然我们把vg扩展了&#xff0c;但是lv还没有扩展

5、扩展lv&#xff0c;使用lvextend命令
[root&#64;localhost dyx]# lvextend -L &#43;9G /dev/mapper/centos-root

6、命令使系统重新读取大小
[root&#64;localhost dyx]# xfs_growfs /dev/mapper/centos-root
meta-data&#61;/dev/mapper/centos-root isize&#61;512 agcount&#61;7, agsize&#61;1113856 blks
&#61; sectsz&#61;512 attr&#61;2, projid32bit&#61;1
&#61; crc&#61;1 finobt&#61;0 spinodes&#61;0
data &#61; bsize&#61;4096 blocks&#61;6814720, imaxpct&#61;25
&#61; sunit&#61;0 swidth&#61;0 blks
naming &#61;version 2 bsize&#61;4096 ascii-ci&#61;0 ftype&#61;1
log &#61;internal bsize&#61;4096 blocks&#61;2560, version&#61;2
&#61; sectsz&#61;512 sunit&#61;0 blks, lazy-count&#61;1
realtime &#61;none extsz&#61;4096 blocks&#61;0, rtextents&#61;0

7、再使用df -h查看
[root&#64;localhost dyx]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 26G 17G 9.1G 66% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 379M 20K 379M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
容量已经从17G扩展到26G了&#xff0c;扩容成功。


推荐阅读
author-avatar
寡妇毒_393
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有