使用GParted对VMWare虚拟硬盘调整分区大小
最近一直在玩Red Hat 9 Linux虚拟机,虽然版本老了点,但是对于初学者还是不错的选择,而且它是Red Hat发行的最后一个免费版本,有点纪念意义哟~
由于开始安装Red Hat 9时,没有手动分区,结果Red Hat 9自动产生了3个分区,如下[root@localhost root]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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 1240 9855877+ 83 Linux /dev/sda3 1241 1305 522112+ 82 Linux swap [root@localhost root]# [root@localhost root]# fdisk /dev/sda The number of cylinders for this disk is set to 1305. 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): 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): n Command action e extended p primary partition (1-4) p Selected partition 4 No free sectors available Command (m for help):可以看到磁盘的全部空间都分区了,如果这时还想增加一个分区,就有点麻烦了。好在我发现了GParted分区工具,它支持以下分区格式:(来自官方网站的截图)
现在开始调整分区吧。
(1)在http://gparted.sourceforge.net/download.php这个网址里,找到你需要的版本,我用的是gparted-live-0.12.0-5.iso。将这个iso文件放入虚拟机的CD-ROM中,并在启动虚拟机时进入BootMenu(应该是按Esc,在启动虚拟机时下面会有信息提示)
(2)根据命令行界面一步步选择键盘类型、语言,然后选择进入图形界面并启动GParted,这样就进入GParted的操作界面。
(3)对于有过分区经验的朋友来说,GParted很好用的,方便又直观,这里我不用赘述怎么用GParted了。截个正在调整分区的图吧。 (4)我只调整/dev/sda2分区的大小,以为这个过程会很长,结果很快GParted提示操作失败。赶忙启动Red Hat 9,看看系统是否正常启动,人品突然好了,顺利进入虚拟机,再次查看下磁盘的分区,如下
[root@localhost root]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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 1113 8832000 83 Linux /dev/sda3 1241 1305 522112+ 82 Linux swap [root@localhost root]#
咋一看,居然没有调整成功和原来一样。仔细看下,才发现/dev/sda2的End与/dev/sda3的Start之间空余了1113至1240个cylinders。
(5)进入Hardware Broweser确认下,磁盘的分区情况,果然调整分区成功。(6)接下来就对这个1000M的未使用空间创建新分区了。
[root@localhost root]# fdisk /dev/sda The number of cylinders for this disk is set to 1305. 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): n Command action e extended p primary partition (1-4) p Selected partition 4 First cylinder (1113-1305, default 1113): Using default value 1113 Last cylinder or +size or +sizeM or +sizeK (1113-1240, default 1240): Using default value 1240 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. [root@localhost root]# partprobe Warning: Unable to align partition properly. This probably means that another partitioning tool generated an incorrect partition table, because it didn't have the correct BIOS geometry. It is safe to ignore,but ignoring may cause (fixable) problems with some boot loaders. [root@localhost root]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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 1113 8832000 83 Linux /dev/sda3 1241 1305 522112+ 82 Linux swap /dev/sda4 1113 1240 1023877+ 83 Linux Partition table entries are not in disk order [root@localhost root]#
可以看到/dev/sda4就是新创建的主分区,这样就完成了由系统原来3个分区变成4个分区的过程。
(7)解决“Partitiontable entries are not in disk order”问题
细心的朋友,会看到打印分区列表时有这么一行信息“Partition table entries are not in disk order”,这是因为刚才把/dev/sda2分区切割成两个分区,即/dev/sda2和/dev/sda4所致。接下来,就修复这个问题。
[root@localhost root]# fdisk /dev/sda The number of cylinders for this disk is set to 1305. 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): 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): x Expert command (m for help): m Command action b move beginning of data in a partition c change number of cylinders d print the raw data in the partition table e list extended partitions f fix partition order g create an IRIX (SGI) partition table h change number of heads m print this menu p print the partition table q quit without saving changes r return to main menu s change number of sectors/track v verify the partition table w write table to disk and exit Expert command (m for help): f Done. Expert command (m for help): r Command (m for help): p Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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 1113 8832000 83 Linux /dev/sda3 1113 1240 1023877+ 83 Linux /dev/sda4 1241 1305 522112+ 82 Linux swap 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. [root@localhost root]# partprobe Warning: Unable to align partition properly. This probably means that another partitioning tool generated an incorrect partition table, because it didn't have the correct BIOS geometry. It is safe to ignore,but ignoring may cause (fixable) problems with some boot loaders. Error: Error informing the kernel about modifications to partition /dev/sda4 - Device or resource busy. This means Linux won't know about any changes you made to /dev/sda4 until you reboot - so you shouldn't mount it or use it in any way before rebooting. Error: Error adding partition 4: Device or resource busy [root@localhost root]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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 1113 8832000 83 Linux /dev/sda3 1113 1240 1023877+ 83 Linux /dev/sda4 1241 1305 522112+ 82 Linux swap [root@localhost root]#
这下一切OK了,多亏有了GParted工具,学习了更多的分区知识和动手能力O(∩_∩)O。
参考资料:http://hi.baidu.com/opensourebyxu/blog/item/44f6bb0c6fe695c47bcbe19f.html