Sometimes an appliance has been created with a regular root partition and needs to be expanded. If it is full and needs to be expanded, it has to be moved to an LVM partition and the old partition can then be added.

Create a snapshot or backup before attempting this!

Step-by-step guide

  1. Create a new LV
    1. create new partition on expanded drive (cfdisk /dev/sda)
    2. create new boot partition on expanded drive (100-200MB)
    3. create new LV
      1. pvcreate /dev/[newly created lv-partition]
      2. vgcreate volgroupname /dev/[lvpart1-x]
      3. lvcreate -l +100%FREE -n lvname volgroupname
    4. mkfs.ext4 /dev/mapper/volgroupname-lvname
    5. mkfs.ext4 /dev/[new boot partition]
  2. Mount new partitions
    1. mount /dev/mapper/volgroupname-lvname /mnt
    2. mkdir /mnt/boot
    3. mount /dev/[new boot partition] /mnt/boot
  3. Copy everything: rsync -axHAX --exclude '/mnt' / /mnt/
  4. Mount everyting

                1. mount everything

mount -o bind /sys/mnt/sys
mount -o bind /dev/mnt/dev
mount -o bind /proc/mnt/proc
grep -v rootfs /proc/mounts/mnt/etc/mtab


                2. chroot/mnt

                3. update mtab (boot partition to correct location)

                4. update /mnt/etc/fstab (change root partition, add boot partition)

/dev/[newbootpartition] /boot ext4 defaults 0 0
/dev/mapper/vg-root  / ext4 defaults 1 1

5.  Update Grub
  1. mv /mnt/boot/grub/grub.cfg /mnt/boot/grub/grub.old
  2. grub-mkconfig -o /boot/grub
  3. grub-install /dev/[main drive]

    6.  Check /boot/grub/grub.cfg

    7.  Check /etc/fstab

    8.  Check /etc/mtab

    9.  Reboot