2

We have Ubuntu 14.04 server on KVM with MySQL database which is just close to fill its disk space, which is 80 GB. We have upgraded the server to 160 GB disk, but the problem is that the new disk space is there just unallocated.

I have been recommended to run GParted, so I did (please see the attached screenshot) and found out couple of tutorials on how to resize the disk, but when I click on Resize, it does not allow resizing of /dev/vda5, probably because it is outside /dev/vda2 extended partition.

gparted

What I need is to extend /dev/vda5 from 80 to 160 GB without losing data. I would like to be sure that I can't do it wrong (this is also why I did not do any experiments on my own). So if someone knows how to do step-by-step, so that it can't get wrong, I would be very grateful.

It is possible for me to run another tool too, but I guess that would be much more difficult.

Update 1: I have tried system-config-lvm, but I am in the same position, here is the pic:

lvm

Again, it does not allow resizing as there is zero remaining space.

Update 2:

# fdisk -l -s /dev/vda

Disk /dev/vda: 171.8 GB, 171798691840 bytes
16 heads, 63 sectors/track, 332881 cylinders, total 335544320 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: 0x0006f748

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      499711      248832   83  Linux
/dev/vda2          501758   167770111    83634177    5  Extended
/dev/vda5          501760   167770111    83634176   8e  Linux LVM

Update 3:

I have setup a similar machine locally in VMware. In my local setup, instead of /dev/vda* I've got /dev/sda* and the disk size is 20 GB instead of 80 GB and the new space that I want to add is 30 GB instead of 80 GB, otherwise it is the same. I can see in GParted the very same situation, it behaves exactly the same as the real server, the /dev/sda5 can't be resized. Here are my attempts with fdisk:

# fdisk -l -s /dev/sda

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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: 0x0003ce62

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758    41940991    20719617    5  Extended
/dev/sda5          501760    41940991    20719616   8e  Linux LVM

Here I can see the /dev/sda2 (local virtual machine) even starts on the same sector as /dev/vda2 (real server). Same for /dev/sda5 and /dev/vda5.

# fdisk /dev/sda

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

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

Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!)

Command (m for help): u
Changing display/entry units to sectors

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

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (503806-104857599, default 503806): 501760
Value out of range.
First sector (503806-104857599, default 503806): ^C

So this is why I guess the real server would also fail here. Note that I have used "u" command twice, because it was already in "sectors" mode.

Wapac
  • 652
  • 1
  • 5
  • 16
  • Before trying to resize any filesystem it is important to backup all of the data that is important to you. Even in the best of cases something can happen like power-loss that could make things significantly more difficult. Is it possible to add the additional space to /dev/vda2 first, then resize /dev/vda5? I have used [this guide](http://blog.oneiroi.co.uk/linux/kvm/virt-resize/RHEL/LVM/kvm-linux-expanding-a-lvm-guest-file-system-using-virt-resize/) to successfully resize a KVM guest LVM file system in the past. – Matt Jul 20 '15 at 18:34
  • Data are backed up, but the system is live and new and new data are getting into the database every second, so although we won't lose everything if the things go bad, it still would mean a serious trouble. Switching the server off before going for it would be even more trouble. I think I have tried resizing /dev/vda2 too, but will recheck to be sure about it. – Wapac Jul 20 '15 at 19:01
  • So, no, /dev/vda2 can't be resized either. In case of /dev/vda2 the right click context menu item Resize/Move is disabled. In case of /dev/vda5 it is enabled, but "Free space following (MiB)" is zero. – Wapac Jul 20 '15 at 19:03

2 Answers2

3

You are proceeding in the wrong order. Please follow these steps:

  • first, BACKUP YOUR DATA (and take a snapshot)
  • use GParted to resize /dev/vda2 first and /dev/vda5 after
  • reboot your virtual machine
  • use pvresize /dev/vda5 and lvresize to resize your physical and logical volumes, respectively.

EDIT: how to resize partition using fdisk To resize your partition, precisely follow these steps:

  • first, BACKUP YOUR DATA (and take a snapshot)
  • launch fdisk /dev/vda
  • press d (delete) and remove partition 5
  • press d (delete) and remove partition 2
  • press u to change units to sectors (should be the default, anyway)
  • press n (new) and create a new extended partition, using all the available spaces. This is a critical step. As first sector, enter 501758; as last sector, simply use the default value
  • press n (new) and create a logical partition. This is a critical step. As first sector, use the defaul (which is wrong, but we will change it later); as last sector, simply use the default value
  • press t (type), select partition n.5, and enter the code 8e (LVM)
  • press x (expert mode)
  • press b (change beginning of partition) and select partition 5
  • when asked for "new beginning of data", enter 501760
  • press r (return) to return to main fdisk menu
  • press p (print) to print partition table and triple-check that it is OK
  • press w (write to disk)
  • reboot your virtual machine
  • inside your virtual machine, issue pvresize /dev/vda5. Now, your physical volume is resized
  • you can now resize your logical volumes. Let suppose that your volume group is called vg, that your logical volume is called lv and you have an ext4 filesystem on it, you can resize it using the following command: lvresize vg/lv -l +100%FREE; resize2fs /dev/vg/lv
shodanshok
  • 47,711
  • 7
  • 111
  • 180
  • I do not know how to resize /dev/vda2. – Wapac Jul 20 '15 at 19:14
  • You can use gparted or fdisk. You can read any of the many online guide for that... – shodanshok Jul 20 '15 at 19:51
  • I have already tried resizing /dev/vda2 in GParted, but the right click context menu item Resize/Move is disabled, so I really do not know how to do it. I have already viewed tutorials on how to do the whole thing, but each scenario I've seen so far was different from our situation. – Wapac Jul 20 '15 at 20:00
  • Please show the output of `fdisk -l -s /dev/vda` – shodanshok Jul 20 '15 at 20:24
  • Please see Update 2 for the output, thank you! – Wapac Jul 21 '15 at 06:36
  • @Wapac: see my last edit – shodanshok Jul 21 '15 at 07:53
  • Please see my Update 3, I am not sure real life system would be of any difference, but if you think it might be different, I can try there (as long as I do not go with "w", it won't do anything, right?). – Wapac Jul 21 '15 at 08:44
  • @Wapac: this is due to fdisk trying to force a correct alignement. I've edited the answer to overcome it. Unless you press "w" -> enter, you should be safe (no changes are committed to disk), but when editing partition, backup is mandatory!!! – shodanshok Jul 21 '15 at 09:26
  • This looks very promising and on my local virtual machine it works, so since this need a reboot, I will wait for the weekend to do this on the real server. Thank you very much for your help. – Wapac Jul 21 '15 at 10:30
  • I've just did it on the live server and it worked! I love you :-) – Wapac Jul 25 '15 at 07:26
  • @Wapac: glad to see it worked! Working with partition in this manner is a dangerous life, but interesting, life ;) – shodanshok Jul 25 '15 at 07:32
0

First you need to extend the LVM. (well actually... first you need to backup your data :P)

Please refer to the second answer by @cao-minh-tu here.

https://askubuntu.com/questions/196125/how-can-i-resize-an-lvm-partition-i-e-physical-volume

Dylan Knoll
  • 480
  • 2
  • 9
  • In that answer, I can see that they can resize the partition, but in my case (see the newly uploaded picture) it can not be resized. – Wapac Jul 20 '15 at 19:16
  • Initialise /dev/vda under 'Uninitialized Entities' first. – Dylan Knoll Jul 20 '15 at 19:23
  • "Uninitialized Entities" contains "/dev/vda", which contains 5 items - "Partition 1" which is 0.24 GB in size (I think it is boot), "Partition 2", which is ~80GB in size and then 3x "Unpartitioned space" - first one is 80 GB, other two are 0 GB. Now if I click the first "Unpartitioned space", its "Initialize Entity" button is disabled, so I do not know how to initialize it. Only "Partition 1" has "Initialize Entity" button enabled. All others have it disabled. – Wapac Jul 20 '15 at 19:30
  • Create an 'LVM' type partition in the Unpartitioned Space first, then you should be able to initialise it. – Dylan Knoll Jul 20 '15 at 19:38
  • Using GParted or this LVM manager? Could you please be more specific on how to do that? – Wapac Jul 20 '15 at 19:40
  • Personally, I would use fdisk. – Dylan Knoll Jul 20 '15 at 19:44
  • Any pointers on that? – Wapac Jul 20 '15 at 20:02
  • http://computernetworkingnotes.com/package-management/how-to-create-lvm-partition-in-linux.html – Dylan Knoll Jul 20 '15 at 20:12
  • After creating the partition, you should be able to Initialize from system-config-lvm. – Dylan Knoll Jul 20 '15 at 20:12
  • Thanks for that link, based on that I think I should run something like "fdisk /dev/vda" and then go "n" for new, "enter" to confirm first cylinder, "enter" to confirm last cylinder, "t", but what then - I am not sure about partition number, should that be 4 or 6 or something else? And I guess that until I do not type "w" command, nothing is going to be saved, right? – Wapac Jul 21 '15 at 07:30