~ubuntu-branches/ubuntu/quantal/partman-lvm/quantal

« back to all changes in this revision

Viewing changes to lib/lvm-remove.sh

  • Committer: Bazaar Package Importer
  • Author(s): Frans Pop, Updated translations
  • Date: 2008-03-31 19:02:14 UTC
  • Revision ID: james.westby@ubuntu.com-20080331190214-4751jdqxaejbp3pi
Tags: 60
* Do not only exclude /dev/md/X devices, but also /dev/mdX devices for LVM
  sync flag handling. Probably solves #470374.

[ Updated translations ]
* Amharic (am.po) by tegegne tefera
* Arabic (ar.po) by Ossama M. Khayat
* Basque (eu.po) by Piarres Beobide
* Panjabi (pa.po) by Amanpreet Singh Alam
* Portuguese (pt.po) by Miguel Figueiredo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
. /lib/partman/lib/lvm-base.sh
2
2
 
 
3
# List PVs to be removed to initialize a device
 
4
remove_lvm_find_vgs() {
 
5
        local realdev vg pvs
 
6
        realdev="$1"
 
7
 
 
8
        # Check all VGs to see which PV needs removing
 
9
        # BUGME: the greps in this loop should be properly bounded so they
 
10
        #        do not match on partial matches!
 
11
        #        Except that we want partial matches for disks...
 
12
        for vg in $(vg_list); do
 
13
                pvs="$(vg_list_pvs $vg)"
 
14
 
 
15
                if ! $(echo "$pvs" | grep -q "$realdev"); then
 
16
                        continue
 
17
                fi
 
18
 
 
19
                # Make sure the VG doesn't span any other disks
 
20
                if $(echo -n "$pvs" | grep -q -v "$realdev"); then
 
21
                        log-output -t partman-lvm vgs
 
22
                        db_input critical partman-lvm/device_remove_lvm_span || true
 
23
                        db_go || true
 
24
                        return 1
 
25
                fi
 
26
                echo "$vg"
 
27
        done
 
28
}
 
29
 
3
30
# Wipes any traces of LVM from a disk
4
31
# Normally called from a function that initializes a device
 
32
# Note: if the device contains an empty PV, it will not be removed
5
33
device_remove_lvm() {
6
 
        local dev realdev vg pvs pv lv tmpdev restart
 
34
        local dev realdev tmpdev restart
 
35
        local pvs pv vgs vg lvs lv pvtext vgtext lvtext
7
36
        dev="$1"
8
37
        cd $dev
9
38
 
13
42
                return 0
14
43
        fi
15
44
 
16
 
        # Ask for permission to erase LVM volumes 
 
45
        vgs="$(remove_lvm_find_vgs $realdev)" || return 1
 
46
        [ "$vgs" ] || return 0
 
47
 
 
48
        pvs=""
 
49
        lvs=""
 
50
        for vg in $vgs; do
 
51
                pvs="${pvs:+$pvs$NL}$(vg_list_pvs $vg)"
 
52
                lvs="${lvs:+$lvs$NL}$(vg_list_lvs $vg)"
 
53
        done
 
54
 
 
55
        # Ask for permission to erase LVM volumes
 
56
        lvtext=""
 
57
        for lv in $lvs; do
 
58
                lvtext="${lvtext:+$lvtext, }$lv"
 
59
        done
 
60
        vgtext=""
 
61
        for vg in $vgs; do
 
62
                vgtext="${vgtext:+$vgtext, }$vg"
 
63
        done
 
64
        pvtext=""
 
65
        for pv in $pvs; do
 
66
                pvtext="${pvtext:+$pvtext, }$pv"
 
67
        done
 
68
 
 
69
        db_subst partman-lvm/device_remove_lvm LVTARGETS "$lvtext"
 
70
        db_subst partman-lvm/device_remove_lvm VGTARGETS "$vgtext"
 
71
        db_subst partman-lvm/device_remove_lvm PVTARGETS "$pvtext"
17
72
        db_input critical partman-lvm/device_remove_lvm
18
73
        db_go || return 1
19
74
        db_get partman-lvm/device_remove_lvm
21
76
                return 1
22
77
        fi
23
78
 
24
 
        # We need devicemapper support
 
79
        # We need devicemapper support here
25
80
        modprobe dm-mod >/dev/null 2>&1
26
81
 
27
 
        # Check all VG's
28
 
        # BUGME: the greps in this loop should be properly bounded so they
29
 
        #        do not match on partial matches!
30
 
        #        Except that we want partial matches for disks...
31
 
        for vg in $(vg_list); do
32
 
                pvs=$(vg_list_pvs $vg)
33
 
                
34
 
                # Only deal with VG's on the selected disk
35
 
                if ! $(echo "$pvs" | grep -q "$realdev"); then
36
 
                        continue
37
 
                fi
38
 
 
39
 
                # Make sure the VG don't span any other disks
40
 
                if $(echo -n "$pvs" | grep -q -v "$realdev"); then
41
 
                        log-output -t partman-lvm vgs
42
 
                        db_input critical partman-lvm/device_remove_lvm_span || true
43
 
                        db_go || true
44
 
                        return 1
45
 
                fi
46
 
 
47
 
                # Remove LV's from the VG
 
82
        for vg in $vgs; do
 
83
                # Remove LVs from the VG
48
84
                for lv in $(vg_list_lvs $vg); do
49
85
                        lv_delete $vg $lv
50
86
                done
51
87
 
52
 
                # Remove the VG and its PV's 
 
88
                # Remove the VG
53
89
                vg_delete $vg
54
 
                for pv in $pvs; do
55
 
                        pv_delete $pv
56
 
                done
 
90
        done
 
91
        # Remove the PVs and unlock the devices
 
92
        for pv in $pvs; do
 
93
                pv_delete $pv
 
94
                partman_unlock_unit $pv
57
95
        done
58
96
 
59
97
        # Make sure that parted has no stale LVM info