Resize Disk Partition on Remote VM Server
I'm running Ubuntu Server 10.04 on a remote server as a VM. I only have access to the VM.
The VM is assign a disk space of 20GB, however the drive is currently only partitioned to use about 4.7GB.
I know that you can use LiveCD to repartition a drive using gparted. How would you go about doing that on a remote VM? (Since the partition is also the startup volume)
# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
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 Blocks Id System
/dev/sda1 * 1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 618 653 280577 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 618 653 280576 82 Linux swap / Solaris
Solution 1:
If you want to enlarge the system partition
First, turn off swap (swapoff /dev/sda5
), because we'll temporarily remove the swap partition.
Use GParted or cfdisk
or fdisk
to:
- Remove the logical partition
/dev/sda5
and the extended partition/dev/sda2
. - Enlarge
/dev/sda1
to span the whole disk minus what you want to allocate for the swap partition. - Re-create a partition (make it a primary partition for simplicity) for the swap.
Do not turn swap back on. Comment out the swap line in /etc/fstab
, and reboot. (If you don't reboot, the kernel keeps using obsolete data about the partitioning, which can have disastrous consequences.)
After the reboot, edit /etc/fstab
to change the name of the swap device and uncomment it. Format the swap area with mkswap
and activate it with swapon -a
.
Finally enlarge the existing filesystem to occupy all of /dev/sda1
with resize2fs /dev/sda1
.
If you want to create another partition
Use GParted to enlarge the extended partition (/dev/sda2
) and create a new logical partition /dev/sda6
on it. Tell GParted that you'll want a Linux filesystem on /dev/sda6
. Create a filesystem with mke2fs -t ext4 /dev/sda6
.
Solution 2:
That what I would try:
Many VPS hosting providers have tools to manipulate partitions in their control panels. Getting access to the control panel would be the safest option.
Do not resize the partition but create a second partition and move your "working" data to that partition. I'e. mount
/home
or wherever your data is to a separate partitionIf you still feel adventurous, try remounting the boot partition read-only and see if it's possible to resize it while mounted read-only
Something really tricky like remove swap - create a copy of your root partition at the very end of the drive - configure grub to boot from the new partition - reboot - resize your original partition - copy the data back - modify grub again - reboot - remove the temporary root partition - create a swap partition again.
I would consider the second two options really dangerous in the sense that if anything goes wrong your system just won't boot so you'd lose any access to the system.