2 exit 1 #Not actually a script.
5 DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
8 TMPDEV=/dev/mapper/$TMPDM
10 TMPDEV2=/dev/mapper/$TMPDM2
13 # - pvresize the old PV to half the space
14 pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK
16 # - dmsetup create a device in the latter half
17 dmstart=$(python -c "print int(($HALFSIZETiB + 0.01) * 1024 * 1024 * 1024 * 2)")
18 dmlen=$(python -c "print int(($HALFSIZETiB - 0.03) * 1024 * 1024 * 1024 * 2)")
20 dmsetup create $TMPDM --table "0 $dmlen linear $DISK $dmstart"
23 # - pvcreate a temporary PV on the new device
26 # - vgextend with the temporary PV
29 # - pvmove all the LVs to the temporary PV
34 mm = yaml.load(sys.stdin.read())
35 for m in sorted(mm.iterkeys()): print m'
39 lvs -o name,devices xenvg \
40 | perl -lane "print \$F[0] if (\$F[1] =~ m|$DISK|)"
44 perl -pe 's/^/d_/;s/$/_hda/'
48 # handy for estimating time; output in GiB; pipe in a list of LVs
49 perl -pe 's.^.xenvg/.' \
50 | xargs lvs -o size --units=g \
51 | perl -lne '$total += $_; END { print $total; }'
59 ssh root@xvm remctl remote web listvms \
62 LVM_SYSTEM_DIR=/root/lvm lvsleft \
64 | grep -v -xf <(vmstolvs <runningvms) \
66 for lv in $(offvmlvs); do
67 LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
70 for lv in $(invirt-listvms | yamlkeys | vmstolvs); do
71 LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
75 ssh root@xvm remctl remote web listvms \
76 | perl -lne 'print if (s/^ cdrom: //)' \
78 LVM_SYSTEM_DIR=/root/lvm lvsleft \
80 | grep -v -xf <(perl -pe "s|/dev/$VG/||" usedcdroms) \
82 for lv in $(offcdlvs); do
83 LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
86 # deal with $(cat usedcdroms)
88 # deal with any remaining $(lvsleft)
93 # - pvremove the old PV
97 # - pvcreate a new PV in the old space,
98 # with --setphysicalvolumesize <half size>
99 # and with --metadatasize <huge> (the point of this exercise)
100 shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
101 dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0"
102 pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
103 dmsetup remove $TMPDM2
107 # - pvmove all the LVs back
110 for lv in $(lvs -o lv_name --noheadings $VG); do
111 movelv $VG/$lv $TMPDEV
116 lvs $VG -o lv_name,devices | grep $TMPDEV
117 # if not, do some more movelv
119 # - pvremove the temporary PV
122 dmsetup remove $TMPDM
124 # - pvresize the new PV to use the whole space