[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Online resize of gpt+cryptsetup+lvm



I don't know where to write this up really, so let me try debian-user.

When I partioned my new netbook I left myself a reasonable amount of
space unpartitioned, in case I should ever want it.  Well, of course,
then I wanted it.  Specifically, I have: SSD nvme0n1 containing GPT
partitions; nvme0n1p6 is a LUKS volume containing my main LVM PV.

I didn't want to reboot.  I thought that it should be possible to
achieve this.  It was a bit of a palaver but I seem to have succeeded.

1. Discover that none of the "friendly" partition tools would work on
   an in-use partition table.

2. Use sfdisk:
     # sfdisk -d /dev/nvme0n1 >before
     # cp before after
     # emacs after &
   This part could be quite fiddly.  In my setup the free space
   was right after the partition I wanted to resize - by design.
   So all I had to do was change the right "size=" number.
   If any of the "start=" needed changing, this would all be MUCH
   harder.  The numbers seem to be in 512-byte sectors.

   Take a deep breath and:
     # sfdisk /dev/nvme0n1 <after
   Get an error message from sfdisk saying it refuses because the
   partition table is in use, so:
     # sfdisk --no-reread /dev/nvme0n1 <after
     # partprobe
   This worked: cat /proc/partitions showed that nvme0n1p6 was
   now bigger.

3. Search the intertubes to try to figure out whether
   `cryptsetup resize' was safe to use on a running LUKS device.
   I found some suggestions that it was, from people who looked
   like they had actually tried it.

   I ran `dmsetup table --showkeys' just in case, as if I was
   fast that might make it possible to put things back if it
   went wrong.

   So,
     # cryptsetup resize nvme0n1p6_crypt

   Another dmsetup table showed me that the 4k offset was still in
   place and indeed only the size had changed - so it had worked.

4.
     # pvresize /dev/mapper/nvme0n1p6_crypt
   We're getting onto the home straight!

5.
   Oh but I wanted to fill the new space full of random data first.
   So I made and wiped a few LVs like this
     # lvcreate -L 10G -n wipe1a vg-zealot2
     # dd if=/dev/urandom of=/dev/vg-zealot2/wipe1a &
   etc.  The idea being that when I had wiped one I could lvremove
   it and finally have some space, without having to wait for
   the whole wipe to complete.
   The final lvcreate to use up the remaining space was
     # lvcreate -l <free PEs from vgdisplay> -n wipe2 vg-zealot2

I thought about maybe filing a bug against something, complaining that
this wasn't easier.  gparted, maybe.  If someone else still wants to
do that please X-Debbugs-CC me.

Ian.

-- 
Ian Jackson <ijackson@chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.


Reply to: