1
votes

I'm writing a Chef recipe to automate setting up software RAID 1 on an existing system with. The basic procedure is:

  1. Clear partition table on new disk (/dev/sdb)
  2. Add new partitions, and set then to raid using parted (sdb1 for /boot and sdb2 with LVM for /)
  3. Create a degraded RAID with /dev/sdb using mdadm --create ... missing
  4. pvcreate /dev/md1 && vgextend VolGroup /dev/md1
  5. pvmove /dev/sda2 /dev/md1
  6. vgreduce VolGroup /dev/sda2 && pvremove /dev/sda2
  7. ...
  8. ...

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?

1

1 Answers

1
votes

I'm quite unsure chef is the right tool.

Not a definitive solution but what I would do for this case:

  1. Create a live system with a chef and a cookbook
  2. Boot on this
  3. run chef as chef-solo with the recipe doing the work (which should work as the physical disk are unmounted at first)

The best way would be to write cookbooks to be able to redo the target boxes from scratch, once it's done you can reinstall entirely the target with the correct partitionning at system install time and let chef rebuild your application stack after that.