「话说嵌入式」攻克恼人的Virtualbox磁盘空间不足
nanshan 2024-11-20 19:31 27 浏览 0 评论
令人抓狂的磁盘空间
每当在编译的时候看着满屏输出的编译信息,手里拿着一杯咖啡(虽然我不喝咖啡,但我吃零食)惬意地等着虚拟机里编译完成,舒服啊。
突然!奇怪,虚拟机的编译怎么停止了啊?不对啊之前可以编译过的呀!!!
经过一翻倒腾的检查确认,发现磁盘空间不够了!一开始设定的空间完全不够用了啊!!!!好烦还得先处理一下这个问题!
相信以上都是广大程序员经常遇到的问题,比如一开始设置的虚拟机空间太小,或者直接拿的是别人的虚拟机镜像,可能随着自己的使用空间都会变得不够用,等到出问题时,又中断了正在进行的编码,影响编码时间还好,特别影响心情!好了!今天就来介绍几种解决虚拟机空间不够用的办法!
这里仅针对virtualbox进行说明。
解决办法
外扩硬盘/共享空间
嗯。这也算得上是一个解决方案吧,直接创建一个新的磁盘后再直接挂载到原来的系统上或者挂载一个共享空间到虚拟机。
可是这样有会一个问题,假设原来的编译工程很大的话,还得挪动一堆资料,相当不方便!想要更简单的解决办法?当然有!
gparted
使用这个gparted图形工具就可以准确,快速地对磁盘空间进行调整,堪比傲梅分区助手。
调整磁盘大小
在调整分区之前需要调大virtualbox磁盘的动态大小
"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyhd D:\vm\vdi\16.04.vdi --resize 160000
注意
- Virtualbox的路径要根据实际安装的位置相应的修改
- 这里的默认单位是MB,所以160000 = 160000MB = 156.25GB
安装工具
别的先不说先安装需要用到的工具
sudo apt install gparted
sudo gparted
查看一下当前的容量大小
调整磁盘大小
D:>"C:\Program Files\Oracle\VirtualBox\VBoxManage" modifyhd "E:\vdi\ubuntu 20.04.vdi" --resize 200000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
磁盘空间分配
注意到这里的未使用空间已经增大
这里需要先选择把sda1的空间调大,才能再去调分区
再来调节实际分区的大小,有多少就用多少吧
最后再df确认一下空间,确实生效了
那万一,万一我们使用的系统完全没有图形,是一个server版本,那还怎么玩??没事继续往下看
parted
让我们换一台虚拟机来试试,这里只使用命令行,因为也没有图形界面可用。
现在的系统 只有18G的空间太少了!肯定不够用!使用命令行,就没法无脑直接配置了,那就一步步来,如下
查看分区状态
root@hlk:/home/hlk# parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 19.3GB 19.3GB primary ext4 boot
2 19.3GB 21.5GB 2145MB extended
5 19.3GB 21.5GB 2145MB logical linux-swap(v1)
(parted)
我们看到有三个分区,如果要调节分区的话,还是需要先把virtualbox的分区删除后再设置,有点麻烦。在这之前还是要先把virtualbox的磁盘空间调大,参见gparted部分。
root@hlk:/home/hlk# parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 19.3GB 19.3GB primary ext4 boot
2 19.3GB 21.5GB 2145MB extended
5 19.3GB 21.5GB 2145MB logical linux-swap(v1)
(parted)
可以看到空间确实不大。
删除分区
(parted) rm 5
Warning: Partition /dev/sda5 is being used. Are you sure you want to continue?
Yes/No? yes
Error: Partition(s) 5 on /dev/sda have been written, but we have been unable to
inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before
making further changes.
Ignore/Cancel? i
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 19.3GB 19.3GB primary ext4 boot
2 19.3GB 21.5GB 2145MB extended
(parted) rm 2
Error: Partition(s) 5 on /dev/sda have been written, but we have been unable to
inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before
making further changes.
Ignore/Cancel? i
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 19.3GB 19.3GB primary ext4 boot
(parted)
调节分区大小
(parted) resizepart
Partition number? 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? y
End? [19.3GB]? 95%
Error: Error informing the kernel about modifications to partition /dev/sda1 --
Device or resource busy. This means Linux won't know about any changes you made
to /dev/sda1 until you reboot -- so you shouldn't mount it or use it in any way
before rebooting.
Ignore/Cancel? i
Error: Partition(s) 5 on /dev/sda have been written, but we have been unable to
inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before
making further changes.
Ignore/Cancel? i
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 99.6GB 99.6GB primary ext4 boot
(parted)
这里发现并没有生效,没有关系,先继续。另外分区的比例可以自己更改,不一定是95%
创建扩展分区
(parted) mkpart
Partition type? primary/extended? ext
Start? 95%
End? 100%
Error: Error informing the kernel about modifications to partition /dev/sda1 --
Device or resource busy. This means Linux won't know about any changes you made
to /dev/sda1 until you reboot -- so you shouldn't mount it or use it in any way
before rebooting.
Ignore/Cancel? i
Error: Partition(s) 5 on /dev/sda have been written, but we have been unable to
inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before
making further changes.
Ignore/Cancel? i
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 99.6GB 99.6GB primary ext4 boot
2 99.6GB 105GB 5242MB extended lba
(parted)
创建swap分区
(parted) mkpart
Partition type? primary/logical? l
File system type? [ext2]? linux-swap
Start? 95%
End? 100%
Error: Error informing the kernel about modifications to partition /dev/sda1 --
Device or resource busy. This means Linux won't know about any changes you made
to /dev/sda1 until you reboot -- so you shouldn't mount it or use it in any way
before rebooting.
Ignore/Cancel? i
Error: Partition(s) 5 on /dev/sda have been written, but we have been unable to
inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before
making further changes.
Ignore/Cancel? i
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 105GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 99.6GB 99.6GB primary ext4 boot
2 99.6GB 105GB 5242MB extended lba
5 99.6GB 105GB 5241MB logical linux-swap(v1) lba
(parted)
重启并设置swap分区
root@hlk:/home/hlk# mkswap /dev/sda5
mkswap: /dev/sda5: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4.9 GiB (5240778752 bytes)
no label, UUID=deaf6ecb-927a-4ff2-8ade-26282e9ad917
然后装UUID替换进/etc/fstb里面的swap分区
修正文件系统大小
此时再检查下实际的文件系统
root@hlk:/home/hlk# df -h
Filesystem Size Used Avail Use% Mounted on
udev 979M 0 979M 0% /dev
tmpfs 201M 3.4M 197M 2% /run
/dev/sda1 18G 14G 3.2G 82% /
tmpfs 1001M 0 1001M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1001M 0 1001M 0% /sys/fs/cgroup
tmpfs 100K 0 100K 0% /run/lxcfs/controllers
tmpfs 201M 0 201M 0% /run/user/1000
root@hlk:/home/hlk#
怎么还是不对?不着急,再进行一次resize2fs就好了
root@hlk:/home/hlk# resize2fs /dev/sda1
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 6
The filesystem on /dev/sda1 is now 24319744 (4k) blocks long.
root@hlk:/home/hlk# df -h
Filesystem Size Used Avail Use% Mounted on
udev 979M 0 979M 0% /dev
tmpfs 201M 3.4M 197M 2% /run
/dev/sda1 92G 14G 74G 16% /
tmpfs 1001M 0 1001M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1001M 0 1001M 0% /sys/fs/cgroup
tmpfs 100K 0 100K 0% /run/lxcfs/controllers
tmpfs 201M 0 201M 0% /run/user/1000
root@hlk:/home/hlk#
大功告成
看来如果有图形界面的话,是非常一件简单的事,如果没有话,还是有那么一点麻烦的~
参考链接
https://askubuntu.com/questions/966394/how-do-i-create-a-swap-partition-using-parted
https://unix.stackexchange.com/questions/481651/df-not-recognizing-partition-being-resized
相关推荐
- Linux/Unix 系统中非常常用的命令
-
Linux/Unix系统中非常常用的命令,它们是进行文件操作、文本处理、权限管理等任务的基础。下面是对这些命令的简要说明:**文件操作类:*****`ls`(list):**列出目录内容,显...
- 教你如何在Linux中删除分区(CLI篇)
-
文接上篇,继续以Ubuntu系统为例。删除分区前,急得重要数据备份!备份!备份用命令操作分区,用的最多的莫过于fdisk了,几乎所有的Linux发行版都默认带有fdisk。首先要知道的是,你想删除的分...
- 敲完就让你提桶跑路的Linux命令(敲完就让你提桶跑路的linux命令是什么)
-
不谨慎可能就会让你提桶的Linux命令!!!删除文件rm-rf该命令是删除文件或文件夹等最快的方式之一。删除后的内容很难恢复,如果删除系统文件可能会导致系统崩坏。>rm-rf/#强制...
- Log文件可以删除吗(taxukeylog文件可以删除吗)
-
Log文件(日志文件)是否可以删除取决于具体场景和文件类型。以下是详细分析和建议:一、哪些Log文件可以删除?非关键应用日志用户级应用日志:如浏览器缓存日志、游戏临时日志等,通常不影响系统运行,可定期...
- Linux 删除空目录(linux直接删除目录)
-
rmdir命令用来删除空目录。当目录不再被使用时,或者磁盘空间已到达使用限定值,就需要删除失去使用价值的目录。利用rmdir命令可以从一个目录中删除一个或多个空的子目录。该命令从一个目录中删除一个或...
- 在 Windows 11 或 10 上删除、创建和格式化分区
-
在Windows11或10上删除、创建和格式化分区假设您的现有电脑使用的是传统硬盘,但现在您想再添加一个硬盘或SSD。当然,后者将用于启动操作系统,而前者将作为纯数据存储。在成功将操作系统...
- 如何使用 Apt Clean 命令清除 APT 缓存?
-
APT(AdvancedPackageTool)是Debian系Linux发行版的包管理工具,用于处理软件包的安装、升级和依赖管理。在使用apt命令(如aptinstall、apt...
- Linux 磁盘空间不够用?5 招快速清理文件,释放 10GB 空间不是梦!
-
刚收到服务器警告:磁盘空间不足90%!装软件提示Nospaceleftondevice!连日志都写不进去,系统卡到崩溃?别慌!今天教你5个超实用的磁盘清理大招,从临时文件到无用软件一键搞定...
- Linux清空日志方法(linux怎么清理日志)
-
方法1:使用>重定向>/path/to/logfile或(需要权限时):sudosh-c'>/var/log/logfile'方法2:使用trun...
- 如何在Eclipse中搭建Zabbix源码的调试和开发环境
-
Zabbix是一款非常优秀的企业级软件,被设计用于对数万台服务器、虚拟机和网络设备的数百万个监控项进行实时监控。Zabbix是开放源码和免费的,这就意味着当出现bug时,我们可以很方便地通过调试源码来...
- Linux操作系统之常用命令(linux操作系统之常用命令有哪些)
-
Linux操作系统一、常用命令1.系统(1)系统信息arch显示机器的处理器架构uname-m显示机器的处理器架构uname-r显示正在使用的内核版本dmidecode-q显示硬件系...
- 理解linux内核的vmlinuz和initrd(linux内核原理及分析)
-
Originaladdress:http://www.chenjunlu.com/2010/11/understanding-of-vmlinuz-initrd-and-system-map/1....
- Linux纯干货知识总结|面试专用(linux面试宝典)
-
学习Linux的重要性相信不用我多说大家也明白,以下是小编总结的常用Linux基础知识以及面试常问的Linux命令,希望能帮助大家更规范地理解和使用~绝对路径和相对路径绝对路径以正斜杠开始完整的文件的...
- Linux基础知识之启动流程分析(简述linux启动流程)
-
Linux系统启动原理:1.poweron开机。2.开机自检:电脑开机后首先加载BIOS(BasicInput/OutputSystem基本输入输出系统)。BIOS程序首先检查计算机能否满足运...
- Java程序员必备——Linux的面试常见问题及面试题!你知道多少?
-
一.常用命令1.编辑相关①.awkNF:字段总数NR:第几行数据FS:分隔字符②.sed-n-i直接修改4a:在第四行后添加4i:在第四行前插入1,5csting:用sting替换1到5行...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- linux 查询端口号 (58)
- docker映射容器目录到宿主机 (66)
- 杀端口 (60)
- yum更换阿里源 (62)
- internet explorer 增强的安全配置已启用 (65)
- linux自动挂载 (56)
- 禁用selinux (55)
- sysv-rc-conf (69)
- ubuntu防火墙状态查看 (64)
- windows server 2022激活密钥 (56)
- 无法与服务器建立安全连接是什么意思 (74)
- 443/80端口被占用怎么解决 (56)
- ping无法访问目标主机怎么解决 (58)
- fdatasync (59)
- 405 not allowed (56)
- 免备案虚拟主机zxhost (55)
- linux根据pid查看进程 (60)
- dhcp工具 (62)
- mysql 1045 (57)
- 宝塔远程工具 (56)
- ssh服务器拒绝了密码 请再试一次 (56)
- ubuntu卸载docker (56)
- linux查看nginx状态 (63)
- tomcat 乱码 (76)
- 2008r2激活序列号 (65)