VirtualBox 虚拟机 Ubuntu 磁盘扩容技术
本文将讲解在 Mac OS X 下如何为 VirtualBox 虚拟机系统 Ubuntu 扩大磁盘容量。
我第一次使用 VirtualBox 装虚拟机的时候,由于分区的时候没有注意,主分区才给了 4 个 G,导致后面越来越麻烦,软件都没法装了,最后还是删除掉重装了个系统。分区的时候需要特别留意,主分区最好要给到足够多的空间,最好是 40G 左右,虽然知道有办法可以解决这个问题,但是会很麻烦。后期如果在使用过程中,空间不够了,可以再次创建存储然后挂载到系统其他目录上。
在 VirtualBox 的菜单栏中,设置->存储->控制器:SATA 处点击添加,此操作要求虚拟机为关机状态才可以添加,如下图所示。
创建存储后,通过 fdisk 命令查看,发现新的存储 sdb 没有分区。
rhett@ubuntu-may:~/Workspace$ sudo fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: dos Disk identifier: 0x9941d8ab Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux /dev/sda2 501758 41940991 41439234 19.8G 5 Extended /dev/sda3 499712 501757 2046 1023K 83 Linux /dev/sda4 41940992 41943039 2048 1M 83 Linux /dev/sda5 501760 41940991 41439232 19.8G 8e Linux LVM Partition table entries are not in disk order. Disk /dev/sdb: 41.9 GiB, 44955238400 bytes, 87803200 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 /dev/mapper/ubuntu--may--vg-root: 3.2 GiB, 3460300800 bytes, 6758400 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 /dev/mapper/ubuntu--may--vg-swap_1: 508 MiB, 532676608 bytes, 1040384 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
在新增加的硬盘空间里增加分区,如下命令:
rhett@ubuntu-may:~/Workspace$ sudo fdisk /dev/sdb
执行上面的命令后,会进入输入模式,分别选择 n ,p, ....中间默认,最后别忘了输入 w 保存分区。
磁盘分区成功后,再次使用 fdisk 命令查看,可以看到多了一个 SDB1 磁盘分区。
rhett@ubuntu-may:~/Workspace$ sudo fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: dos Disk identifier: 0x9941d8ab Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux /dev/sda2 501758 41940991 41439234 19.8G 5 Extended /dev/sda3 499712 501757 2046 1023K 83 Linux /dev/sda4 41940992 41943039 2048 1M 83 Linux /dev/sda5 501760 41940991 41439232 19.8G 8e Linux LVM Partition table entries are not in disk order. Disk /dev/sdb: 41.9 GiB, 44955238400 bytes, 87803200 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 Disklabel type: dos Disk identifier: 0x0ed64142 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 87803199 87801152 41.9G 83 Linux Disk /dev/mapper/ubuntu--may--vg-root: 3.2 GiB, 3460300800 bytes, 6758400 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 /dev/mapper/ubuntu--may--vg-swap_1: 508 MiB, 532676608 bytes, 1040384 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
格式化磁盘 sdb1 分区为 ext4 格式,如下命令所示:
rhett@ubuntu-may:~/Workspace$ sudo mkfs -t ext4 /dev/sdb1 mke2fs 1.42.10 (18-May-2014) Creating filesystem with 10975144 4k blocks and 2744320 inodes Filesystem UUID: 29ed7b70-2b0a-46fa-808d-f4203b3ff4c0 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
将新的磁盘存储空间挂载到一个空目录下,最好是新建的空目录,不然原来目录上的文件会消失。
rhett@ubuntu-may:~/Workspace$ sudo mount /dev/sdb1 /home/rhett/
最后,通过 $du -sh /home/rhett 命令查看,发现新挂载的目录有足够大的空间了。
相关文章
暂无