source: trunk/scripts/pv-fixup/pv-fixup @ 2239

Last change on this file since 2239 was 2239, checked in by price, 15 years ago

script for the PV metadatasize fix

File size: 2.3 KB
Line 
1#!/bin/sh
2exit #Not actually a script.
3
4VG=xenvg
5DISK=/dev/sdb
6HALFSIZETiB=2.04
7TMPDM=tmpfoo
8TMPDEV=/dev/mapper/$TMPDM
9TMPDM2=tmpbar
10TMPDEV2=/dev/mapper/$TMPDM2
11METADATASIZE=3.5m
12
13#  - pvresize the old PV to half the space
14pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK
15
16#  - dmsetup create a device in the latter half
17dmstart=$(python -c "print int(($HALFSIZETiB + 0.01) * 1024 * 1024 * 1024 * 2)")
18dmlen=$(python -c "print int(($HALFSIZETiB - 0.02) * 1024 * 1024 * 1024 * 2)")
19#foreach host:
20dmsetup create $TMPDM --table "0 $dmlen linear $DISK $dmstart"
21#done
22
23#  - pvcreate a temporary PV on the new device
24pvcreate $TMPDEV
25
26#  - vgextend with the temporary PV
27vgextend $VG $TMPDEV
28
29#  - pvmove all the LVs to the temporary PV
30#    (something like
31#      for lv in $(LVs for running VMs on this host); do
32#        #some lvchange -a commands
33#        pvmove -n $lv <oldpv> <newpv>
34#        #possibly more lvchange -a to restore old state
35#      done)
36
37movelv () {
38  echo pvmoving $1...
39  lvchange -an $1
40  pvmove -i 10 -n $1 $2
41}
42
43#touch /etc/invirt/nocreate
44#FOREACH host:
45#machines=$(invirt-listvms | perl -lne 'print if s/^([^ ]*):.*/$1/')
46#lvs=$(echo $machines | perl -lpe "s|^|$VG/d_|; s|$|_hda|")
47for lv in $(lvs -o lv_name --noheadings $VG); do
48  movelv $VG/$lv $DISK
49done
50#done
51
52# hopefully empty:
53lvs $VG -o lv_name,devices | grep $DISK
54# if not, do some more movelv
55
56# This is possible if some LVs were used on more than one host during
57# migration.
58
59
60#  - pvremove the old PV
61vgreduce $VG $DISK
62pvremove $DISK
63
64#  - pvcreate a new PV in the old space,
65#     with --setphysicalvolumesize <half size>
66#     and with --metadatasize <huge>    (the point of this exercise)
67shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
68dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0"
69pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
70dmsetup remove $TMPDM2
71pvscan
72vgextend $VG $DISK
73
74#  - pvmove all the LVs back
75
76#FOREACH host:
77for lv in $(lvs -o lv_name --noheadings $VG); do
78  movelv $VG/$lv $TMPDEV
79done
80#done
81
82# hopefully empty:
83lvs $VG -o lv_name,devices | grep $TMPDEV
84# if not, do some more movelv
85
86#  - pvremove the temporary PV
87vgreduce $VG $TMPDEV
88pvremove $TMPDEV
89dmsetup remove $TMPDM
90
91#  - pvresize the new PV to use the whole space
92pvresize $DISK
Note: See TracBrowser for help on using the repository browser.