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

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

pv-fixup: tweaks

File size: 2.0 KB
Line 
1#!/bin/sh
2exit #Not actually a script.
3
4VG=xenvg
5DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
6HALFSIZETiB=5.23
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.03) * 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
31movelv () {
32  echo pvmoving $1...
33  lvchange -an $1
34  pvmove -i 10 -n $1 $2
35  lvchange -ay $1
36}
37
38#FOREACH host:
39for lv in $(lvs -o lv_name --noheadings $VG); do
40  movelv $VG/$lv $DISK
41done
42#done
43
44# hopefully empty:
45lvs $VG -o lv_name,devices | grep $DISK
46# if not, do some more movelv
47
48# This is possible if some LVs were used on more than one host during
49# migration.
50
51
52#  - pvremove the old PV
53vgreduce $VG $DISK
54pvremove $DISK
55
56#  - pvcreate a new PV in the old space,
57#     with --setphysicalvolumesize <half size>
58#     and with --metadatasize <huge>    (the point of this exercise)
59shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
60dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0"
61pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
62dmsetup remove $TMPDM2
63pvscan
64vgextend $VG $DISK
65
66#  - pvmove all the LVs back
67
68#FOREACH host:
69for lv in $(lvs -o lv_name --noheadings $VG); do
70  movelv $VG/$lv $TMPDEV
71done
72#done
73
74# hopefully empty:
75lvs $VG -o lv_name,devices | grep $TMPDEV
76# if not, do some more movelv
77
78#  - pvremove the temporary PV
79vgreduce $VG $TMPDEV
80pvremove $TMPDEV
81dmsetup remove $TMPDM
82
83#  - pvresize the new PV to use the whole space
84pvresize $DISK
Note: See TracBrowser for help on using the repository browser.