Excuse me! I just read your question, let me help you!
Size(VM usable memory) == Size(main partitions) + Size(extended partitions);
Size(extended partition) == Size(logical partition)s;
Size(VM disk memory) == Size(VM usable memory) + Size(free space);
So, if you want to use the free space on your VM's disk space, you need to expand the /dev/sda1
, and there are no other partitions between the main partition /dev/sda1
and the free space.
Just use sudo fdisk -l
to check your partition's usage, I guess your output just liking below:
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 62914560 sectors
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00074164
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 512M 5.2G 4902880 4.7G 83 Linux
/dev/sda2 5.2G 6.2G 580000 1G 5 Extended
/dev/sda5 5.2G 6.2G 580000 1G 82 Linux swap / Solaris
And after your main partition or usable partition up to 20GB
, your new sudo fdisk -l
:
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 62914560 sectors
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00074164
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 512M 20.5G 42162880 20G 83 Linux
/dev/sda2 20.5G 21.5G 580000 1G 5 Extended
/dev/sda5 20.5G 21.5G 580000 1G 82 Linux swap / Solaris
Solution:
0.Just log in your VM's terminal;
1.turn off your swap
permission: sudo swapoff /dev/sda5
;
And use command free -h
to check whether swapoff do matter or not, if you see the free or total space percent of swap partition is 0B
, that means successfully turn off the swap.
Others, reboot, or restart will automatically turn on the swap, using command sudo swapoff swap_partition_directory
just temporarily turn off swap.
2.Remove extended partition /dev/sda2
and logical/swap partition /dev/sda5
:
First remove logical/swap partition /dev/sda5
, then extended partition /dev/sda2
;
Just use cfdisk
to do the upstairs job, using sudo cfdisk
to enter the power of cfdisk
.
Using up
and down
direction button to choose the partition, using right
and left
direction button to choose the operation, uisng enter
button to make sure.
Choose Delete
button to remove logical/swap partition /dev/sda5
and extended partition /dev/sda2
.
3.Resize the main partition:
Also, using cfdisk
, just use Resize
button to do that, change resized size from default 21GB
into 20GB
;
4.Re-create extended partition /dev/sda2
and logical/swap partition /dev/sda5
:
Also, using cfdisk
, use New
button to create extended partition /dev/sda2
on the free space, then create logical partition /dev/sda5
, both of them use default size 1 GB
;
Now, select Quit
button to quit cfdisk
.
5.Set your logical partition /dev/sda5
's file type: sudo mkswap /dev/sda5
;
Update your new logical/swap partition /dev/sda5
's UUID
, use lsblk -f | grep "swap"
to check swap partition's UUID
, copy that, and change the UUID
of swap in /etc/fstab
via sudo vim /etc/fstab
, using i
button to edit, copy your new swap UUID
instead of the old UUID
of the former swap.
6.Set all the file types of main partition /dev/sda1
: sudo resize2fs /dev/sda1
.
7.Restart or reboot your virtual machine: sudo reboot
.
Have fun!!!:)
OVER!