一直以来都是以vagrant+docker作为开发环境,可是久而久之,原Box自带的8G容量就捉襟见肘了。时不时需要手动删除一些东西。
Virtualbox 本身只支持vdi硬盘文件格式的扩容,对vmdk 格式的却不支持。但是却提供vmdk到vdi格式的转化,正好可以利用这一功能进行扩容。
因为要用到VBoxManage,所以要把D:\Program Files\Oracle\VirtualBox
这个加入path。
- 关闭虚拟机, 从Virtualbox页面查看硬盘文件地址(选中虚拟机->右键->设置->存储)(如:C:\Users\Administrator\VirtualBox VMs\vagrant_default_1493690319341_4755)。进到文件所在目录后执行:
$ VBoxManage clonehd box-disk1.vmdk box-disk1.vdi –format VDI
- 给vdi格式硬盘文件扩容
$ VBoxManage modifyhd box-disk1.vdi –resize 40960
从Virutalbox存储界面删除原硬盘文件,然后再加入新的VDI格式硬盘文件
vagrant up启动虚拟机,然后vagrant ssh进入
利用cfdisk工具创建主分区,谨记选择格式为Linux LVM (8e)
$ sudo cfdisk /dev/sda
cfdisk
这里的具体操作如下:
# vagrant ssh
# sudo su -
Find the name of the logical volume mapping the file-system is on (ie. /dev/mapper/VolGroupOS-lv_root).
# df
Find the name of the physical volume (or device) that all the partitions are created on (ie. /dev/sda).
# fdisk -l
Create a new primary partition for use as a Linux LVM
# fdisk /dev/sda
Press p to print the partition table to identify the number of partitions. By default there are two - sda1 and sda2.
Press n to create a new primary partition.
Press p for primary.
Press 3 for the partition number, depending the output of the partition table print.
Press Enter two times to accept the default First and Last cylinder.
Press t to change the system's partition ID
Press 3 to select the newly creation partition
Type 8e to change the Hex Code of the partition for Linux LVM
Press w to write the changes to the partition table.
Reboot the machine, then ssh back in when it is up again and switch to the root user once more.
# reboot
# vagrant ssh
# sudo su -
- 利用pvcreate命令给新的分区创建物理卷
$ sudo pvcreate /dev/sda3
successfully created
- 查看VG Name,我自己的VG Name是centos
$ sudo pvdisplay | grep "VG Name"
VG Name centos
- 将新分区扩展到centos这个组
$ vgextend centos /dev/sda3
Volume group "centos" sucessfully extended
- 扩展逻辑分区
$ lvextend /dev/mapper/centos-root /dev/sda3
- resize并且生效
在centos 7下,这一步会出错$ resize2fs /dev/mapper/centos-root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/debian-605/root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/debian-605/root to 4937728 (4k) blocks.
The filesystem on /dev/debian-605/root is now 4937728 blocks long.
这时,只需要使用xfs_growfs命令替换就行了resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
resize2fs
至此,大分告成。vagrant reload重启虚拟机查看效果xfs_growfs /dev/mapper/centos-root
于是乎,妈妈再也不用担心我的虚拟机磁盘没容量了。df -h
参考:https://www.madcoder.cn/vagrant-box-resize.html
https://gist.github.com/christopher-hopper/9755310
搜索
标签
study
ab
amap
apache
apahe
awk
aws
bat
centos
CFS
chrome
cmd
cnpm
composer
consul
crontab
css
curl
cygwin
devops
di
docker
docker,docker-compose
ethereum
excel
fiddler
fluentd
framework
front-end
git
gitgui
github
glide
go
golang
gorm
grafana
gzip
ioc
item2
iterm2
javascript
jenkins
jsonp
kafka
laradock
laravel
larval
linux
liunux
log
mac
mac, wi-fi
macos
magento
mariaDB
minikube
mongoDB
msp
mysql
netbeans
nginx
nodejs
nohup
npm
nsq
php
php-fpm
php7
phpstorm
php扩展
Protobuf
python
redis
scp
server
shell
soap
socket
socket5
sql
sre
ssdb
ssh
ssl
study
sublime
swift
system
td-agent
uml
v2ray
vagrant
vagrnat
vim
vpn
vue
vue.js
webpack
webrtc
websocket
webtatic
windows
windows7
word
wps
xdebug
yarn
yii2
yum
zookeeper
世界国家
互联网
以太坊
分类
前端
小程序
打印机
排序算法
搞笑
权限
粤语
缓存
网络
虚拟机
视频
设计模式
项目管理
热门文章
友情链接