expand-root-storage-in-virtualbox

wordpresshexeract.wordpress.com/2012/04/30/how-to-expand-the-root-filesystem-of-a-11-10-ubuntu-running-inside-vmware-player
imcczyimcczy.com/how-to-expand-the-root-filesystem-in-vmware.html
csdnblog.csdn.net/ouyang_peng/article/details/53261599

查看需要修改的硬盘

cmdVirtualBox的安装目录

1
2
cd VirtualBox
VBoxManage list hdds

转换成vdi格式

已是vdi格式的则略过。

1
VBoxManage clonehd D:\Softwares\...\src.vmdk D:\Softwares\...\dst.vdi --format VDI
1
VBoxManage clonehd D:\Softwares\...\src.vdi D:\Softwares\...\dst.vmdk --format VMDK

修改硬盘镜像文件

1
2
3
VBoxManage modifyhd D:\Softwares\...\dst.vdi --resize 92160
# D:\Softwares\...\dst.vdi 即为要扩容的镜像。
# 92160 以MB为单位,即90G。

改完后重开下virtualbox即可看到对应镜像容量增大。

分区

查看文件系统

1
2
3
4
5
6
7
8
9
10
root@~ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 11G 7.6G 58% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 487M 4.0K 487M 1% /dev
tmpfs 100M 1.1M 99M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 498M 0 498M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda3 28G 21G 5.7G 79% /home/work

查看磁盘分区表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@~ fdisk -l /dev/sda

Disk /dev/sda: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders, total 188743680 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 identifier: 0x00077822

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 39847934 41940991 1046529 5 Extended
/dev/sda3 41940992 100661247 29360128 83 Linux
/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

记住此处的分区表起始位置为2048

开始分区:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
root@~ fdisk /dev/sda

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/sda: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders, total 188743680 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 identifier: 0x00077822

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 39847934 41940991 1046529 5 Extended
/dev/sda3 41940992 100661247 29360128 83 Linux
/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

delete a partition删除所有分区后,直接add a new partition,不要退出fdisk

记得创建交换分区,change a partition's system id可以将分区改为交换分区。

最后write table to disk and exit保存并退出fdisk

修改fstab

记得修改/etc/fstab文件挂载选项,比如UUID改变后,需要改下。否则会无法重启。

重启虚拟机

1
root@~ reboot

调整分区大小

1
root@~ resize2fs /dev/sda1