首先在主机上将虚拟机磁盘resize到更大的值
[code]stevenMacBook-Pro:~ steven$ VBoxManage list hdds
UUID: 178e6e1d-3274-4216-bf28-a9ef2509b4c2
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/windows/xp/xp.vdi
State: created
Type: normal
Usage: xp (UUID: 47988ef8-ce64-4f52-ac9e-c0b6f9db1b49)
UUID: 030092b1-4df5-41e8-b14f-0111d0b312d3
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/windows/xp/xp2.vdi
State: created
Type: normal
Usage: xp (UUID: 47988ef8-ce64-4f52-ac9e-c0b6f9db1b49)
UUID: 11906e11-8c1b-473f-8467-c5a9341dfa3d
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/linux/RHEL/RHEL.vdi
State: created
Type: normal
Usage: RHEL (UUID: 9e1cbe3c-72b3-4104-b749-8caa7931fdca)[/code]
11906e11-8c1b-473f-8467-c5a9341dfa3d为redhat的硬盘,现在大小为15G,扩展到20g
[code]stevenMacBook-Pro:~ steven$ VBoxManage modifyhd 11906e11-8c1b-473f-8467-c5a9341dfa3d --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%[/code]
ssh连上虚拟机
[code][root@localhost ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 1958 3285292+ 5 Extended
/dev/sda5 1550 1810 2096451 82 Linux swap / Solaris
/dev/sda6 1811 1958 1188778+ 8e Linux LVM[/code]
发现扩展的磁盘空间即在/dev/sda4
删除/dev/sda4
[code][root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux[/code]
发现把swap也给删了。不过没关系后面可以自己新加
现在分区
[code]Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (1550-2610, default 1550):
Using default value 1550
Last cylinder or +size or +sizeM or +sizeK (1550-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 2610 8522482+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.[/code]
重启虚拟机,必须重启。The new table will be used at the next reboot.
[code][root@localhost ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 2610 8522482+ 83 Linux
[root@localhost ~]# mkfs.ext2 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
LABEL=/ / ext3 defaults 1 1
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1066560 inodes, 2130620 blocks
106531 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2185232384
66 block groups
32768 blocks per group, 32768 fragments per group
16160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.[/code]
将sda4挂载到本地目录
[code][root@localhost ~]# mkdir /u01
[root@localhost ~]# mount /dev/sda4 /u01
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext3 9.5G 8.6G 409M 96% /
/dev/sda3 ext3 2.0G 490M 1.4G 27% /tmp
/dev/sda1 ext3 99M 12M 83M 12% /boot
tmpfs tmpfs 506M 0 506M 0% /dev/shm
/dev/sda4 ext2 8.0G 19M 7.6G 1% /u01
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda5 swap swap defaults 0 0
/dev/sda4 /u01 ext2 defaults 0 0[/code]
[code]stevenMacBook-Pro:~ steven$ VBoxManage list hdds
UUID: 178e6e1d-3274-4216-bf28-a9ef2509b4c2
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/windows/xp/xp.vdi
State: created
Type: normal
Usage: xp (UUID: 47988ef8-ce64-4f52-ac9e-c0b6f9db1b49)
UUID: 030092b1-4df5-41e8-b14f-0111d0b312d3
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/windows/xp/xp2.vdi
State: created
Type: normal
Usage: xp (UUID: 47988ef8-ce64-4f52-ac9e-c0b6f9db1b49)
UUID: 11906e11-8c1b-473f-8467-c5a9341dfa3d
Parent UUID: base
Format: VDI
Location: /Users/steven/VirtualBox VMs/linux/RHEL/RHEL.vdi
State: created
Type: normal
Usage: RHEL (UUID: 9e1cbe3c-72b3-4104-b749-8caa7931fdca)[/code]
11906e11-8c1b-473f-8467-c5a9341dfa3d为redhat的硬盘,现在大小为15G,扩展到20g
[code]stevenMacBook-Pro:~ steven$ VBoxManage modifyhd 11906e11-8c1b-473f-8467-c5a9341dfa3d --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%[/code]
ssh连上虚拟机
[code][root@localhost ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 1958 3285292+ 5 Extended
/dev/sda5 1550 1810 2096451 82 Linux swap / Solaris
/dev/sda6 1811 1958 1188778+ 8e Linux LVM[/code]
发现扩展的磁盘空间即在/dev/sda4
删除/dev/sda4
[code][root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux[/code]
发现把swap也给删了。不过没关系后面可以自己新加
现在分区
[code]Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (1550-2610, default 1550):
Using default value 1550
Last cylinder or +size or +sizeM or +sizeK (1550-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 2610 8522482+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.[/code]
重启虚拟机,必须重启。The new table will be used at the next reboot.
[code][root@localhost ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1549 2096482+ 83 Linux
/dev/sda4 1550 2610 8522482+ 83 Linux
[root@localhost ~]# mkfs.ext2 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
LABEL=/ / ext3 defaults 1 1
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1066560 inodes, 2130620 blocks
106531 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2185232384
66 block groups
32768 blocks per group, 32768 fragments per group
16160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.[/code]
将sda4挂载到本地目录
[code][root@localhost ~]# mkdir /u01
[root@localhost ~]# mount /dev/sda4 /u01
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext3 9.5G 8.6G 409M 96% /
/dev/sda3 ext3 2.0G 490M 1.4G 27% /tmp
/dev/sda1 ext3 99M 12M 83M 12% /boot
tmpfs tmpfs 506M 0 506M 0% /dev/shm
/dev/sda4 ext2 8.0G 19M 7.6G 1% /u01
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda5 swap swap defaults 0 0
/dev/sda4 /u01 ext2 defaults 0 0[/code]
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




