Resizing a LVM install of Ubuntu 13.10 for Windows 7 Dual-Boot
systemsResizing a LVM install of Ubuntu 13.10 for Windows 7 Dual-Boot
I have Ubuntu 13.10 installed on my computer. I had done a fresh install and used the LVM filesystem. I now want to install Windows 7 on the same drive. Apparently this isn’t so simple as one might think.
Here are 2 good resources on LVM:
- http://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/
- http://www.tutonics.com/2012/11/ubuntu-lvm-guide-part-1.html
Steps
-
Get Ubuntu Live CD / USB to boot from (this information can be found elsewhere online (via Windows or via Ubuntu)
-
Boot up Live OS
-
Open terminal
-
Run command
sudo lvdisplay
This should show you the layout of your logical volumes, with my install this displayed as:
--- Logical volume --- LV Path /dev/ubuntu-vg/root LV Name root VG Name ubuntu-vg ... --- Logical volume --- LV Path /dev/ubuntu-vg/swap_1 LV Name swap_1 VG Name ubuntu-vg ...
Here we can see that
/dev/ubuntu-vg/root
and/dev/ubuntu-vg/swap_1
are what I will need to resize/move first. -
Run command
sudo lvreduce --resizefs --size -250G /dev/ubuntu-vg/root
lvreduce
will shrink the root (/
) logical volume by the size specified by--size -XG
whereX
is the number of gigabytes. The size of the logical volume before was ~450 GB, so this shrinks it down to ~200 GB. -
Now we need to move the swap volume (
/dev/ubuntu-vg/swap_1
) so that is is no longer all the way at the opposite end of the physical volume. Here is a good explanation of how this (slightly) complicated process works. We run this commandlvdisplay --map
which will display the range that the logical volumes take up and it will display something like:--- Segments --- Logical extent 0 to 639: Type linear Physical volume /dev/sda5 Physical extents 0 to 639 --- Segments --- Logical extent 0 to 31: Type linear Physical volume /dev/sda5 Physical extents 1544 to 1575
-
Now run the command
pvmove --alloc anywhere /dev/sda5:1544-1575 /dev/sda5:640-671
which will move the logical volume of/dev/ubuntu-vg/swap_1
(the second segment listed) to be positioned exactly next to/dev/ubuntu-vg/root
(the first segment listed). You will want to replace the values here with the ones thatlvdisplay
shows you.These are not my values, these are pulled from the explanation linked above.
Now that you have all your logical volumes moved to be contiguous in the physical volume, you can go into GParted and resize the physical volume.
-
Open GParted and when it loads right click
/dev/sda5
and select “Deactivate”. -
Right click
/dev/sda5
and select Resize/Move. Move the right hand slider all the way to the left edge of the used space of the physical volume. Apply the changes. -
Right click
/dev/sda2
and select Resize/Move. Move the right hand slider all the way to the left edge of the used space of the physical volume. Apply the changes. -
You should now have unallocated space following
/dev/sda2
. You can now create a new NTFS partition with that space to install windows on.
You will now need to follow the steps indicated in Install Windows after Ubuntu to handle Windows overwriting the MBR/Grub.