问题
I created a Centos x64 VM instance with a 12GB disk using the FI-WARE cloud. I can access it with not problem and I have started installing software. However, the default created partition /dev/vda1 is only 5GB and I have already filled it. I would like to know how to extend the partition to use the full disk.
Thanks,
回答1:
I would say you have two ways. The first one which is safe and the second one which is risky. So, let's start by the safe one: You could use fdisk /dev/vda (or parted /dev/vda) in order to create a new partition. As the partition will be created in the same virtual disk where your '/' is created and mounted, you'll have to reboot your VM before using your new partition.
When you reboot your VM, you'll be able to format your new partition:
mkfs -t ext4 /dev/vda2
And mount your new partition wherever you want:
mount /dev/vda2 /mnt
In order to make this mounting persistent, you could add a new line to /etc/fstab:
/dev/vda2 /mnt ext4 defaults 1 1
The second way is extending your /dev/vda1 partition. This is risky and if you make any mistake, it is possible that your VM won't be able to boot again (alone), use this at your own risk. Anyway here it goes --
Using fdisk (parted will refuse to do this) you can change the partition --
# fdisk /dev/vda
Remove the dos partition flag and change units to 'sectors':
Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): u
Changing display/entry units to sectors
Let's take a look at the partition table:
Command (m for help): p
Disk /dev/vda: 10.7 GB, 10737418240 bytes
181 heads, 40 sectors/track, 2896 cylinders, total 20971520 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: 0x000c897f
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 10485759 5241856 83 Linux
Delete the first partition
Command (m for help): d
Selected partition 1
And create it again using the whole disk:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Next, you should set the boot flag to your first partition:
Command (m for help): a
Partition number (1-4): 1
You quit fdisk writing your changes with 'w' command and reboot the VM.
Once it reboots, you shoud resize your filesystem:
# resize2fs /dev/vda1
来源:https://stackoverflow.com/questions/23534248/how-to-extend-default-partition-after-creating-an-vm-instance