2018-05-16 09:38:06 
						  748 
						   0 
						   
					
					
					之前弄的centos的虚拟机硬盘只分了8G.除开tmp目录实际上只有6G多点,
现在随便装了点东西就不够了,但是virtualbox没有自动扩展硬盘...坑了。
那就手动来扩容吧>.<
一.VirtualBox使用VBoxManage新增硬盘空间
1.1使用VBoxManage
结果发现 Resize medium operation for this format is not implemented yet ,不支持vmdk格式的直接扩容.
E:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd  3fd58d10-4452-44f9-872e-8b9d7d7e59d5 --resize 40000
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage.exe: error: Resize medium operation for this format is not implemented yet!
 
 1.2 vmdk转vdi
好吧,先转vdi再来扩容.
克隆vmdk格式硬盘为vdi格式硬盘.
E:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd "E:\vm\centos1.vmdk" "E:\vm\centos1.vdi" --format vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'vdi'. UUID: 96c09f76-0bf9-4d3f-9570-25e874c09aed
 
 1.3查看新的vdi盘的。
记住新的vdi盘的uuid 值,后面需要用到.
E:\Program Files\Oracle\VirtualBox>VBoxManage.exe list hdds
UUID:           3fd58d10-4452-44f9-872e-8b9d7d7e59d5
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       E:\vm\centos1.vmdk
Storage format: VMDK
Capacity:       8192 MBytes
Encryption:     disabled
UUID:           96c09f76-0bf9-4d3f-9570-25e874c09aed
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       E:\vm\centos1.vdi
Storage format: vdi
Capacity:       8192 MBytes
Encryption:     disabled 
 1.4 使用VBoxManage 再次扩容新的vdi盘大小 为40G.
E:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd   96c09f76-0bf9-4d3f-9570-25e874c09aed  --resize 40960
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% 
 修改virtualBox虚拟机硬盘,加载新的扩容后的vdi格式的硬盘
1.5 在虚拟机的Centos中使用gparted格式化新加的空间
发现多出32G的新空间,需要先格式化后再使用
二.Centos 目录扩容,直接扩展新添加的硬盘至已有位置
2.1 在系统众使用 fdisk查看 文件系统情况
新加的/dev/sda3 磁盘空间已添加成功。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0009b69b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   8e  Linux LVM
/dev/sda3        16777216    83886079    33554432   83  Linux
 
 使用df -h查看,发现文件目录大小没变,还是8G 。
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.2G  6.2G  5.5M 100% /
devtmpfs                 1.2G     0  1.2G   0% /dev
tmpfs                    1.2G     0  1.2G   0% /dev/shm
tmpfs                    1.2G  8.5M  1.2G   1% /run
tmpfs                    1.2G     0  1.2G   0% /sys/fs/cgroup
/dev/sda1               1014M  170M  845M  17% /boot
tmpfs                    229M  8.0K  229M   1% /run/user/0
 
 
2.2 扩容物理卷
下面开始centos目录扩容, 合并新添加的/dev/sda3 至原有系统目录 /centos-root
使用vgscan 及 gextend命令.
[root@localhost ~]# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2
//查看 lvm名称-》centos
[root@localhost ~]# vgextend centos /dev/sda3
WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
  Volume group "centos" successfully extended
 
 2.3 扩容逻辑卷
使用 lvextend命令记录扩容逻辑卷.
lvextend -L ,32G, 比实际的小一点点,扩容31G。
root@localhost ~]# lvextend -L +32G /dev/mapper/centos-root 
  Insufficient free space: 8192 extents needed, but only 8191 available
[root@localhost ~]# lvextend -L +31G /dev/mapper/centos-root 
  Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to <37.20 GiB (9522 extents).
  Logical volume centos/root successfully resized.
 
 2.4 .更新xfs文件系统
使用df命令查看文件系统,发现 /目录依然没有变化,需要更新xfs文件系统.
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.2G  6.2G  5.5M 100% /
devtmpfs                 1.2G     0  1.2G   0% /dev
tmpfs                    1.2G     0  1.2G   0% /dev/shm
tmpfs                    1.2G  8.5M  1.2G   1% /run
tmpfs                    1.2G     0  1.2G   0% /sys/fs/cgroup
/dev/sda1               1014M  170M  845M  17% /boot
tmpfs                    229M  8.0K  229M   1% /run/user/0
 
 最后一步,使用 xfs_growfs
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=406016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1624064, 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 1624064 to 9750528
 
 命令成功后再次查看
[root@localhost ~]# 
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   38G  6.2G   32G  17% /
devtmpfs                 1.2G     0  1.2G   0% /dev
tmpfs                    1.2G     0  1.2G   0% /dev/shm
tmpfs                    1.2G  8.5M  1.2G   1% /run
tmpfs                    1.2G     0  1.2G   0% /sys/fs/cgroup
/dev/sda1               1014M  170M  845M  17% /boot
tmpfs                    229M  8.0K  229M   1% /run/user/0 
 
OK!, /目录成功扩容32G!
						 2018-07-14 22:56:51 
						
					
					
							     0
							 赞
							    
							 赏
							
						
					本文基于CC BY-NC-ND 4.0 许可协议发布,作者:野生的喵喵。 固定链接: 【virtualbox vmdk硬盘扩容及centos目录扩容】 转载请注明
相关文章:
		发表新的评论
	
	文章分类
文章归档
标签
					
						deb ,  
						 ,  
						蓝屏 ,  
						select ,  
						html5 ,  
						tomcat ,  
						gcc ,  
						ajax ,  
						apt-get update ,  
						选择 ,  
						js加密 ,  
						java ,  
						工作 ,  
						ocr ,  
						AngularJs ,  
						感慨 ,  
						work ,  
						click ,  
						javascript ,  
						反向代理 ,  
						ip查询 ,  
						空间查询 ,  
						word ,  
						ECS服务器 ,  
						centos ,  
						杂 ,  
						StartupWMClass ,  
						前端 ,  
						js ,  
						vmdk ,  
						感概 ,  
						select2 ,  
						virtualbox ,  
						gg代理 ,  
						share ,  
						seo ,  
						风筝 ,  
						email ,  
						ASR ,  
						转换 ,  
						cool ,  
						activiti-ui ,  
						喵小凡 ,  
						@PropertySource ,  
						ckeiditor ,  
						网站攻击 ,  
						SRILM ,  
						风景 ,  
						plugin ,  
						vdi ,  
						扩容 ,  
						chorme ,  
						阿里云 ,  
						KALDI ,  
						num ,  
						packer2 ,  
						pic ,  
						gg镜像 ,  
						win8.1 ,  
						ecs ,  
						mysql ,  
						Ubuntu ,  
						快递查询 ,  
						nginx ,  
						ubuntu ,  
						swap ,  
						maven ,  
						entropy_avail ,  
						tencent ,  
						语音识别 ,  
						prerender ,  
						xfce4 ,  
						进度条 ,  
						存储过程 ,  
						activiti ,  
						熵 ,  
						日出 ,  
						练笔 ,  
						虞美人 ,  
						nodejs ,  
						词 ,  
						demo ,  
						jquery ,  
						random ,  
						linux ,  
						cat ,  
						bootstrapValidator ,  
						angularJs ,  
						live ,  
						on ,  
						gg ,  
						雪 ,  
						婚姻 ,  
						景色 ,  
						@Autowired ,  
						pdf ,  
						emqttd ,  
						优化 ,  
						thchs30 ,  
						opencv ,