2

I am getting tired of cleaning /boot in order to free up enough space every time a new kernel is released. I have been following the instructions below to shrink /dev/ubuntu-vg to free up space to increase the size of /boot.

How can I resize an LVM partition? (i.e: physical volume)

Running sudo pvs -v --segments /dev/sda5 yields:

PV VG Fmt Attr PSize PFree Start SSize LV Start Type PE Ranges       
/dev/sda5 ubuntu-vg lvm2 a-- 111.55g 8.55g 0 26368 root 0 linear /dev/sda5:0-26367
/dev/sda5 ubuntu-vg lvm2 a-- 111.55g 8.55g 26368 2188 0 free 

Everything appears to work until I get to:

sudo pvmove --alloc anywhere /dev/sda5:yyyy-end

I would like to free up ~500 MB to add to /boot. (I deleted my swap partition when I ran into issues thinking it would provide more memory to enable the move (which I plan to add back later)). Since the higher memory address are all free (right hand side is empty), I attempted to increase the size of /dev/sda1 (i.e., ext2 /root). However, GParted, KDE Partition Manager, nor Logical Volume Management will allow me to do so (cannot specify larger size).

Questions:

  1. If /dev/sda1 (/boot) is listed first and Ubuntu-vg (/dev/sda2, i.e., /root) is listed second, does the free space need to be on the left or right hand side of Ubuntu-vg to permit /dev/sda1 (/boot) to be extended? I.e., since all the unused space is already on the right hand side, why can't I simply extend /dev/sda1 (/boot)?

  2. Does ubuntu-vg need to be resized to not include the unused space?

  3. In my case, Ubuntu-vg has unused space on the right hand side. Do I need to shrink Ubuntu-vg so that “Unused Space” is not included in Ubuntu-vg?

  4. If the free space must be on the left side (rather than right), since I only have one data volume remaining (/dev/sda5:0-26367), I would expect to be able to move it anywhere within the volume. I have tried various versions of sudo pvmove -v --alloc anywhere, but keep getting “Insufficient free space: aaa extents needed, but only bbb available”.

    E.g., sudo pvmove -v --alloc anywhere /dev/sda5:0+26368 /dev/sda5:128+26368 Why am I getting “insufficient space” when I am just shifting a range of memory to another range of available memory?

user2514157
  • 783
  • 8
  • 19

1 Answers1

2

My recommendation is to NOT try moving the PV. Instead, try this:

  1. Shrink the PV by the amount you want your /boot partition to be in total. That is, if you want a 1GB /boot partition, reduce your PV by 1GB.
  2. Create a new 1GB /boot partition in the freed space and create whatever filesystem you want to use on it.
  3. Copy your current /boot partition's files to the new partition
  4. Adjust your boot loader configuration for the new partition (this may entail re-installing your boot loader or just adjusting configuration files).
  5. Test it all, being sure everything works with the new /boot partition. This will leave you with some wasted space where your old /boot partition is; but that's easily corrected....
  6. Mark the former /boot partition as a new PV (that is, change its partition type code).
  7. Run pvcreate on the new PV/former /boot partition.
  8. Run vgextend to extend the VG to include the new PV/former /boot partition.
  9. If desired, expand one or more LVs to make use of the extra space.

This process will be far quicker and safer than trying to move your main PV to make room for an expanded /boot partition. The drawback, of course, is that the PV will be fragmented, which will slightly degrade performance for files that may be stored in the former /boot partition. That said, the amount of space is small, so the number of files that will be affected is likely to be tiny. If the disk is an SSD, this effect will be non-existent.

Note also that the small amount of space you'd recover argues in favor of simply stopping at step #5 in the above procedure, or perhaps instead wiping or deleting the former /boot partition. That will make it available for future use should that become desirable. For instance, if you want to install a second Linux distribution on the computer or test the next Ubuntu release before upgrading, you could use the old /boot partition as a /boot partition for the new installation, in parallel with the main one.

Rod Smith
  • 44,284
  • 7
  • 63
  • 105
  • I appreciate your approach. It would cost me 240MB of a 128GB SSD (0.2%), which I consider reasonable given the alternative challenges. – user2514157 Aug 30 '17 at 15:37
  • If you re-use the current /boot partition as a PV, then my suggestion costs you next to nothing. (There may be some overhead lost in using two PVs rather than one, but that's it.) On an SSD, there will be no performance penalty, either. – Rod Smith Aug 31 '17 at 12:38