I'm writing a Chef recipe to automate setting up software RAID 1 on an existing system with. The basic procedure is:
- Clear partition table on new disk (/dev/sdb)
- Add new partitions, and set then to raid using parted (sdb1 for /boot and sdb2 with LVM for /)
- Create a degraded RAID with /dev/sdb using mdadm --create ... missing
- pvcreate /dev/md1 && vgextend VolGroup /dev/md1
- pvmove /dev/sda2 /dev/md1
- vgreduce VolGroup /dev/sda2 && pvremove /dev/sda2
- ...
- ...
I'm stuck on no. 5. With 2 disks of the same size I always get an error:
Insufficient free space: 10114 extents needed, but only 10106 available
Unable to allocate mirror extents for pvmove0.
Failed to convert pvmove LV to mirrored
I think it's because when I do the mdadm --create, it adds extra information to the disk so it has slightly less physical extents.
To remedy the issue, one would normally reboot the system off a live distro and:
- e2fsck -f /dev/VolGroup/lv_root
- lvreduce -L -0.5G --resizefs ...
- pvresize --setphysicalvolumesize ...G /dev/sda2
- etc etc
- reboot
and continue with step no. 5 above.
I can't do that with Chef as it can't handle the rebooting onto a live distro and continuing where it left off. I understand that this obviously wouldn't be idempotent.
So my requirements are to be able to lvreduce (somehow) on the live system without using a live distro cd.
Anyone out there have any ideas on how this can be accomplished?
Maybe?:
- Mount a remote filesystem as root and remount current root elsewhere
- Remount the root filesystem as read-only (but I don't know how that's possible as you can't unmount the live system in the first place).
- Or another solution to somehow reboot into a live distro, script the resize and reboot back and continue the Chef run (Not sure if this is even popssible
Ideas?