XenServer

From Network Security Wiki

Increasing free disk space in Ubuntu VM

Source: vmotionhost.com

Increase disk size under Storage section in XenCenter.

Boot up the VM & log into it.

Verify Disk Space:

df -h

Check the partition layout

sudo fdisk -l /dev/xvda

To create new partitions, all old partiotions have to be deleted. To be able to delete the swap partitions the swap has to be turned off.

Verify Swap usage:

free -m

Turn off Swap disk

sudo swapoff -a

Now delete all partitions

sudo fdisk /dev/xvda
Command (m for help): d
Partition number (1-5): 1

Command (m for help): d
Partition number (1-5): 2

Now Create new partition and the Swap partition:

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): 30410751

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2):
Using default value 2
First sector (30410752-31457279, default 30410752):
Using default value 30410752
Last sector, +sectors or +size{K,M,G} (30410752-31457279, default 31457279):
Using default value 31457279


The primary partition is now correct but the swap partition is not. The type of the partition should not be “83” but “82” (marking it as a partition for the Linux swap)

Command (m for help): p

Device Boot          Start         End      Blocks   Id  System
/dev/xvda1            2048    30410751    15204352   83  Linux
/dev/xvda2        30410752    31457279      523264   83  Linux
 
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
 
Command (m for help): w
The partition table has been altered!

Now reboot the VM:

shutdown -r now

The swap partition will be mounted using an UUID identifier. After creating a new partition for swap the UUID will not match and upon reboot, no swap will be available.

awk '/swap/ { print $1 }' /etc/fstab

UUID=8bb62351-4436-47df-92fe-af2865f03461 root@ubuntu:~# swapoff -a root@ubuntu:~# free -m total used free shared buffers cached Mem: 992 695 296 0 23 325 -/+ buffers/cache: 346 645 Swap: 0 0 0

To make sure that there is no data (usable by the kernel) at the beginning of the partition

root@ubuntu:~# dd if=/dev/zero of=/dev/xvda2
dd: writing to `/dev/xvda2': No space left on device

root@ubuntu:~# mkswap -U 8bb62351-4436-47df-92fe-af2865f03461 /dev/xvda2 Setting up swapspace version 1, size = 523260 KiB no label, UUID=8bb62351-4436-47df-92fe-af2865f03461 root@ubuntu:~# swapon -a root@ubuntu:~# free -m total used free shared buffers cached Mem: 992 693 298 0 23 325 -/+ buffers/cache: 345 646 Swap: 510 7 503 root@ubuntu:~#

Now The final and easiest step is to resize the filesystem

root@ubuntu:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 9.0G 2.8G 5.8G 33% / udev 488M 4.0K 488M 1% /dev tmpfs 199M 788K 198M 1% /run none 5.0M 0 5.0M 0% /run/lock none 497M 200K 496M 1% /run/shm

root@ubuntu:~# resize2fs /dev/xvda1 resize2fs 1.42 (29-Nov-2011)

root@ubuntu:~# df -h