Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have resized lvm partitions in the past, but after the resize there is space at the end of the partition. What I want to achive is to have the space at the beginning of the partition instead.

The reason for this is that I want to use grub2, but the size of the grub image is bigger than the size of the MBR, so I want to move my partition a little bit to give it more space.

Here is my configuration:

fdisk:

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 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: 0xa2f2ca9b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63   125949599    62974768+  8e  Linux LVM
/dev/sda2   *   125949600   230436359    52243380    7  HPFS/NTFS/exFAT
/dev/sda3       230436360   234436544     2000092+  82  Linux swap / Solaris

pvdisplay:

  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               vg1
  PV Size               60.00 GiB / not usable 832.00 KiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              15360
  Free PE               0
  Allocated PE          15360
  PV UUID               6O3e7e-0ofs-mqpW-QyKM-H8yL-CwFf-zBkNES

vgdisplay:

  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               60.00 GiB
  PE Size               4.00 MiB
  Total PE              15360
  Alloc PE / Size       15360 / 60.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               RhdcOf-b1xm-QNQT-7cou-ctNA-eO4b-5p2nmq

lvdisplay:

  --- Logical volume ---
  LV Name                /dev/vg1/lvroot
  VG Name                vg1
  LV UUID                xKbY2T-kyat-Ane0-guYy-ub2a-i8Gh-cUdSgZ
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:3

  --- Logical volume ---
  LV Name                /dev/vg1/lvhome
  VG Name                vg1
  LV UUID                3PPBuA-iCpW-BXVG-F00F-VO6P-oUOB-Nct4Sc
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:4

What I want to do is resize lvroot by a little bit ... 1MB will be sufficient in this case, then shrink it at the beginning, then shrink the pv, delete the partition and recreated at a new start location with the same end location.

share|improve this question
    
You don't need to; your partition already starts on sector 63, which is typical and grub2 is quite happy with that. –  psusi May 7 '12 at 14:29
    
@psusi, yes it is typical to start @ 63, but no, grub2 isn't always happy with that. It really depends on the modules it has to include. In my case, 32K is not enough, in other cases it may be –  Rado May 7 '12 at 17:48
    
is your root fs btrfs? It seems that module is a little too large to fit, but ext[234] should work fine. I've got ext4 on lvm on raid5 and that almost fits in 62 sectors. You might try making an ext4 /boot partition to get around the btrfs problem. –  psusi May 7 '12 at 19:05
    
@psusi all my linux partitions are actually ext4. I did fix my problem by splitting my swap partition and creating a small boot partition to run grub from, but I still want to find out if there is an easy way to shift a partition a bit. –  Rado May 7 '12 at 22:04
add comment

3 Answers 3

gparted 0.14.0 now supports moving/resizing lvm physical volumes.

share|improve this answer
add comment

This link has a bunch of info on this problem.

You need to move the physical partition (/dev/sda1). lvm2 can't do this. You need parted.

Some versions of parted let you specify the amount of space preceding the partition as part of a resize operation. Those that don't should let you resize in one step and then move in the next step. You may need to shrink the underlying filesystem first.

share|improve this answer
2  
parted no longer ( since v3 ) has move/resize support, and didn't handle LVM partitions when it did. –  psusi May 7 '12 at 14:33
2  
as @psusi said, moving has been deprecated and it never supported moving to overlapping location (i.e. can't just nudge the partition a bit, have to move the whole partition to an empty space, then move it back) –  Rado May 7 '12 at 17:52
add comment

I see no real reason why your grub2 should reside before the first partition. As far as I read it must reside within the first 2 TB - you are fine with your "small" harddisk. So Instead:

  1. Reduce the filesystem on the LV you created last (LV home?)
  2. lvresize the LV to make it smaller
  3. pvresize the PV to make it smaller
  4. Reset the end of sda1 to something smaller (possibly a little bit bigger than your PV)
  5. pvresize - the PV should get a bit bigger - if not go back to 4.
  6. now create a sda4 primary partition and make that your bootable grub2-partiton
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.