Help:Resize root partition of an OpenStack hosted virtual machine
Cloud Services staff will not assist you in recovering from a failed attempt at resizing the root partition of a VM!
This is not even possible with modern VMs.
Overview
This page provides instructions for resizing the root partition of an OpenStack hosted virtual machine.
Before you begin
Resizing the root partition of an OpenStack hosted virtual machine is not for the faint of heart, but it is possible.
Each VM has a disk image that contains three partitions by default:
- a 20G root partition
- a 0.5G swap partition
- the rest of the disk as an LVM container that is initially uninitialized.
The role::labs::lvm::srv
Puppet role can be used to create an LVM partition filling the entire container that is mounted at /srv. This is often the best way to utilize the disk.
There are some use cases when you really want one very large root partition. There is no GUI method to achieve this with OpenStack/Horizon/Wikitech, but it can be attempted manually.
Basic steps
- Disable current swap partition
- Edit the
/dev/vda
partition map- Delete all current partitions
- Create new larger partition 1 (Note: this new partition must start at same offset as original partition - if the new partition's start sector does not match, resizing will not work)
- Create new swap partition
- Save changes
- Reboot the VM
- Enable the new swap partition
Note: When editing the partition table, you must use fdisk -c=dos
so that the new root partition will start on the same physical boundary as the initial partition.
Alternative to rebooting
Once the partition has been resized a reboot can be avoided by doing the following:
- Scan for the new partition:
partprobe /dev/vda
- If you see the following error, your partition start sector was incorrect and the resizing will fail:
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot
- If you see the following error, your partition start sector was incorrect and the resizing will fail:
- Grow the partition to use all of the new partition:
resize2fs /dev/vda2
df
should now reflect the expanded disk.
Example session
$ ssh my-cool-instance
$ free
total used free shared buffers cached
Mem: 4048264 1900868 2147396 5848 193556 906968
-/+ buffers/cache: 800344 3247920
Swap: 499708 4 499704
$ sudo swapoff --all
$ free
total used free shared buffers cached
Mem: 4048264 1900952 2147312 5848 193564 906968
-/+ buffers/cache: 800420 3247844
Swap: 0 0 0
$ sudo fdisk -c=dos /dev/vda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (with command 'c').
Command (m for help): p
Disk /dev/vda: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders, total 83886080 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: 0x00031db0
Device Boot Start End Blocks Id System
/dev/vda1 63 37998046 18998992 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 37998592 38998015 499712 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/vda3 38998016 83886079 22444032 8e Linux LVM
Partition 3 does not end on cylinder boundary.
Command (m for help): d
Partition number (1-4): 3
Command (m for help): d
Partition number (1-4): 2
Command (m for help): d
Selected partition 1
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 (63-83886079, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-83886079, default 83886079): 82886656
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): 2
First sector (82886657-83886079, default 82886657):
Using default value 82886657
Last sector, +sectors or +size{K,M,G} (82886657-83886079, default 83886079):
Using default value 83886079
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): p
Disk /dev/vda: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders, total 83886080 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: 0x00031db0
Device Boot Start End Blocks Id System
/dev/vda1 63 82886656 41443297 83 Linux
/dev/vda2 82886657 83886079 499711+ 82 Linux swap / Solaris
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
$ sudo reboot
W: molly-guard: SSH session detected!
Please type in hostname of the machine to reboot: my-cool-instance
Broadcast message from bd808@my-cool-instance
(/dev/pts/0) at 17:34 ...
The system is going down for reboot NOW!
$ packet_write_wait: Connection to UNKNOWN: Broken pipe
$ ssh my-cool-instance
Linux mw-base 3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016 x86_64
Ubuntu 14.04.3 LTS
The last Puppet run was at Thu Apr 7 17:36:00 UTC 2016 (1 minutes ago).
Last login: Thu Apr 7 17:37:30 2016 from bastion-01.bastion.eqiad1.wikimedia.cloud
$ free
total used free shared buffers cached
Mem: 4048240 1498572 2549668 11352 53488 748044
-/+ buffers/cache: 697040 3351200
Swap: 0 0 0
$ sudo mkswap /dev/vda2
Setting up swapspace version 1, size = 499704 KiB
no label, UUID=1fac41ba-958a-4650-b72c-aedccf59452e
$ sudo swapon --all
$ free
total used free shared buffers cached
Mem: 4048240 1657788 2390452 14364 59604 802148
-/+ buffers/cache: 796036 3252204
Swap: 499704 0 499704
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 12K 2.0G 1% /dev
tmpfs 396M 396K 395M 1% /run
/dev/vda1 39G 17G 21G 44% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
none 100M 0 100M 0% /run/user
Communication and support
Support and administration of the WMCS resources is provided by the Wikimedia Foundation Cloud Services team and Wikimedia movement volunteers. Please reach out with questions and join the conversation:
- Chat in real time in the IRC channel #wikimedia-cloud connect or the bridged Telegram group
- Discuss via email after you have subscribed to the cloud@ mailing list
- Subscribe to the cloud-announce@ mailing list (all messages are also mirrored to the cloud@ list)
- Read the News wiki page
Use a subproject of the #Cloud-Services Phabricator project to track confirmed bug reports and feature requests about the Cloud Services infrastructure itself
Read the Cloud Services Blog (for the broader Wikimedia movement, see the Wikimedia Technical Blog)