Changeset 2149 in MondoRescue for devel/mindi


Ignore:
Timestamp:
Feb 16, 2009, 5:50:07 PM (15 years ago)
Author:
Bruno Cornec
Message:

Begining f devl branch coding nd preliminary organisation

Location:
devel/mindi
Files:
2 added
4 edited
10 copied
1 moved

Legend:

Unmodified
Added
Removed
  • devel/mindi/etc/mondorescue.conf

    r2003 r2149  
    7070# You may want to add ramdisk_size=1024 if on Fedora Core 5/6
    7171#
    72 mr_boot_params mindi =acpi=off apm=off devfs=nomount exec-shield=0 noresume selinux=0 barrier mindi = off
     72mr_boot_params mindi = acpi=off apm=off devfs=nomount exec-shield=0 noresume selinux=0 barrier mindi = off
    7373
    7474
     
    132132a PC whose CD-ROM drive tray would be damaged if it unexpectedly ejected.\n
    133133
     134#
     135# LVM commands and conf files
     136# Is it LSB ?
     137#
     138mr_lvmdiskscan mindi = /usr/sbin/lvmdiskscan
     139mr_lvmprocfile mindi = /proc/lvm/global
     140mr_lvmcmd mindi = /usr/sbin/lvm
     141mr_lvmpath mindi = /usr/sbin/
  • devel/mindi/lib/MondoRescue/Mindi/LVM.pm

    r2142 r2149  
    11#!/usr/bin/perl -w
    22#
    3 # Mindi subroutines brought by the MondoRescue project
     3# Mindi subroutines related to LVM brought by the MondoRescue project
    44#
    55# $Id$
     
    88# Provided under the GPL v2
    99
    10 package MandoRescue::Mindi;
     10package MondoRescue::Mindi::LVM;
    1111
    1212use strict 'vars';
    1313use Data::Dumper;
    1414use English;
    15 use File::Basename;
    16 use File::Copy;
    17 use POSIX qw(strftime);
    1815use lib qw (lib);
    1916use ProjectBuilder::Base;
     
    2825
    2926our @ISA = qw(Exporter);
    30 our @EXPORT = qw(mr_lvm_check);
     27our @EXPORT = qw(mr_lvm_check mr_lvm_analyze mr_lvm_prepare);
    3128
    3229=pod
     
    4845This function checks the usage of LVM and gets the version used
    4946It returns 2 parameters, the LVM version, and the lvm command to use if needed
     47If LVM version is null then no LVM Handling should be done.
    5048
    5149=cut
     
    5351sub mr_lvm_check {
    5452
    55 # Get them from a conf file instead
    56 my $lvmds = "/usr/sbin/lvmdiskscan";
    57 my $lvmproc = "/proc/lvm/global";
    58 my $lvmcmd = "/usr/sbin/lvm";
    59 
    60 mr_exit(1,"$lvmproc doesn't exist.") if (! -x $lvmproc) ;
     53# Get params from the conf file
     54my ($lvmds_t,$lvmproc_t,$lvmcmd_t,$lvmpath_t) = pb_conf_get("mr_lvmdiskscan","mr_lvmprocfile","mr_lvmcmd","mr_lvmpath");
     55my $lvmds = $lvmds_t->{'mindi'};
     56my $lvmproc = $lvmproc_t->{'mindi'};
     57my $lvmcmd = $lvmcmd_t->{'mindi'};
     58my $lvmpath = $lvmpath_t->{'mindi'};
     59
     60if (! -x $lvmproc) {
     61    pb_log(1,"$lvmproc doesn't exist.");
     62    return(0,undef);
     63    }
    6164
    6265# Check LVM volumes presence
    6366open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
    6467while (<LVM>) {
    65     mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
     68    if (/0 VGs 0 PVs 0 LVs/) {
     69        pb_log(1,"No LVM volumes found in $lvmproc");
     70        return(0,undef);
     71    }
    6672}
    6773close(LVM);
     
    96102if ($lvmver == 0) {
    97103    # Still not found
    98     mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmcmd version");
     104    mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmcmd");
    99105} elsif ($lvmver == 1) {
    100     $lvmcmd = "";
    101 }
     106    $lvmcmd = "$lvmpath";
     107} elsif ($lvmver == 2) {
     108    $lvmcmd .= " ";
     109} else {
     110    pb_log(0,"Unknown LVM version $lvmver");
     111}
     112# Here $lvmcmd contains a full path name
    102113pb_log(1,"Found LVM version $lvmver");
    103114return ($lvmver,$lvmcmd);
     115
     116}
     117
     118=over 4
     119
     120=item B<mr_lvm_analyze>
     121
     122This function outputs in a file descriptor the LVM analysis done
     123It returns 1 parameters, the LVM version or 0 if no LVM
     124
     125=cut
     126
     127sub mr_lvm_analyze {
     128
     129my $OUTPUT = shift;
     130
     131my ($lvmver,$lvmcmd) = mr_lvm_check();
     132return(0) if ($lvmver == 0);
     133
     134print $OUTPUT "LVM:$lvmver";
     135
     136# Analyze the existing physical volumes
     137open(LVM,$lvmcmd."pvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."pvdisplay -c");
     138while (<LVM>) {
     139        print $OUTPUT "PV:$_";
     140}
     141close(LVM);
     142
     143# Analyze the existing volume groups
     144open(LVM,$lvmcmd."vgdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."vgdisplay -c");
     145while (<LVM>) {
     146        print $OUTPUT "VG:$_";
     147}
     148close(LVM);
     149
     150# Analyze the existing logical volumes
     151open(LVM,$lvmcmd."lvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."lvdisplay -c");
     152while (<LVM>) {
     153        print $OUTPUT "LV:$_";
     154}
     155close(LVM);
     156return($lvmver);
     157}
     158
     159
     160=over 4
     161
     162=item B<mr_lvm_prepare>
     163
     164This function outputs in a file descriptor the LVM setup needed to restore LVM conf
     165It returns 1 parameters, the LVM version or 0 if no LVM
     166
     167=cut
     168
     169sub mr_lvm_prepare {
     170
     171my $INPUT = shift;
     172my $OUTPUT = shift;
     173my $mrmult = shift;
     174
     175my ($lvmver,$lvmcmd) = mr_lvm_check();
     176
     177# Generate the startup scrit needed to restore LVM conf
     178# from what is given on input
     179# Multiply by the multiplier given in input or 1 of none
     180
     181print $OUTPUT "# Desactivate Volume Groups\n";
     182print $OUTPUT $lvmcmd."vgchange -an\n";
     183print $OUTPUT "\n";
     184
     185my $firsttime = 0;
     186while (<$INPUT>) {
     187    if (/^PV:/) {
     188        my ($tag,$pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
     189        print $OUTPUT "# Creating Physical Volumes $pvname\n";
     190        print $OUTPUT $lvmcmd."pvcreate -ff -y -s ".$pesize*$mrmult." $pvname\n";
     191        print $OUTPUT "\n";
     192    } elsif (/^VG:/) {
     193        my ($tag,$vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
     194        if ($lvmver < 2) {
     195            print $OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
     196            print $OUTPUT "rm -Rf /dev/$vgname\n";
     197        }
     198        $lvmaxnum = 255 if ($lvmaxnum > 256);
     199        $pvmaxnum = 255 if ($pvmaxnum > 256);
     200        print $OUTPUT "# Create Volume Group $vgname\n";
     201        # Pb sur pesize unite ?
     202        print $OUTPUT $lvmcmd."vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum\n";
     203        print $OUTPUT "\n";
     204    } elsif (/^LV:/) {
     205        if ($firsttime eq 0) {
     206            print $OUTPUT "\n";
     207            print $OUTPUT "# Activate All Volume Groups\n";
     208            print $OUTPUT $lvmcmd."vgchange -ay\n";
     209            print $OUTPUT "\n";
     210            $firsttime = 1;
     211        }
     212        my ($tag,$lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$readahead,$major,$minor) = split(/:/);
     213        print $OUTPUT "# Create Logical Volume $lvname\n";
     214        print $OUTPUT $lvmcmd."lvcreate -n $lvname -L ".$lvsize*$mrmult." -r $readahead $vgname\n";
     215        #[ "$stripes" ]    && output="$output -i $stripes"
     216        #[ "$stripesize" ] && output="$output -I $stripesize"
     217    }
     218}
     219print $OUTPUT "\n";
     220print $OUTPUT "# Scanning again Volume Groups\n";
     221print $OUTPUT $lvmcmd."vgscan\n";
     222print $OUTPUT "\n";
    104223
    105224}
  • devel/mindi/post-install.sh

    r2142 r2149  
    1313    sublocal=$PREFIX
    1414    if [ "_$CONFDIR" != "_" ]; then
    15         conf=${HEAD}$CONFDIR/mindi
    16         subconf=$CONFDIR/mindi
     15        conf=${HEAD}$CONFDIR/PBPROJ
     16        subconf=$CONFDIR/PBPROJ
    1717    else
    1818        echo "CONFDIR should be defined if PREFIX is defined"
     
    2222    local=/usr/local
    2323    sublocal=$local
    24     if [ -f /usr/sbin/mindi ]; then
    25         echo "WARNING: /usr/sbin/mindi exists. You should probably remove the mindi package !"
     24    if [ -f /usr/bin/mindi ]; then
     25        echo "WARNING: /usr/bin/mindi exists. You should probably remove the mindi package !"
    2626    fi
    27     conf=$local/etc/mindi
     27    conf=$local/etc/PBPROJ
    2828    subconf=$conf
    29     echo $PATH | grep $local/sbin > /dev/null || echo "Warning - your PATH environmental variable is BROKEN. Please add $local/sbin to your PATH."
    3029fi
     30
     31if [ _"$CACHEDIR" = _"" ]; then
     32    CACHEDIR=$local/var/cache/mindi
     33else
     34    CACHEDIR=${HEAD}$CACHEDIR
     35fi
     36locallib=$local/share/lib
     37sublocallib="$locallib/PBPROJ"
     38
    3139
    3240if uname -a | grep Knoppix > /dev/null || [ -e "/ramdisk/usr" ] ; then
     
    4351echo "mindi ${MINDIVER}-r${MINDIREV} will be installed under $local"
    4452
    45 if [ _"$CACHEDIR" = _"" ]; then
    46     CACHEDIR=$local/var/cache/mindi
    47 else
    48     CACHEDIR=${HEAD}$CACHEDIR
    49 fi
    50 if [ _"$MANDIR" = _"" ]; then
    51     MANDIR=$local/share/man/man8
    52 else
    53     MANDIR=${HEAD}$MANDIR/man8
    54 fi
    55 if [ _"$DOCDIR" = _"" ]; then
    56     DOCDIR=$local/share/doc/mindi-$MINDIVER
    57 else
    58     DOCDIR=${HEAD}$DOCDIR/mindi-$MINDIVER
    59 fi
    60 if [ _"$LIBDIR" = _"" ]; then
    61     echo $ARCH | grep -E '^i[0-9]86$' &> /dev/null && ARCH=i386 && locallib=$local/lib
    62     echo $ARCH | grep -E '^x86_64$' &> /dev/null && locallib=$local/lib64
    63     echo $ARCH | grep -E '^ia64$' &> /dev/null && locallib=$local/lib
    64     sublocallib="$locallib/mindi"
    65 else
    66     locallib=${HEAD}$LIBDIR
    67     sublocallib="$LIBDIR/mindi"
    68 fi
    69 
    7053echo "Creating target directories ..."
    71 install -m 755 -d $conf $locallib/mindi $MANDIR $local/sbin $CACHEDIR
     54install -m 755 -d $conf $sublocallib $CACHEDIR
    7255
    7356echo "Copying files ..."
    74 cp -af rootfs $locallib/mindi
    75 chmod 755 $locallib/mindi/rootfs/sbin/*
    76 install -m 755 analyze-my-lvm $locallib/mindi
    77 install -m 644 msg-txt dev.tgz $locallib/mindi
     57cp -af rootfs $sublocallib/mindi
     58chmod 755 $sublocallib/mindi/rootfs/sbin/*
     59install -m 644 msg-txt dev.tgz $sublocallib/mindi
    7860install -m 644 deplist.txt udev.files proliant.files $conf
    7961
    8062# Substitute variables for mindi
    81 sed -e "s~^MINDI_PREFIX=XXX~MINDI_PREFIX=$sublocal~" -e "s~^MINDI_CONF=YYY~MINDI_CONF=$subconf~" -e "s~^MINDI_LIB=LLL~MINDI_LIB=$sublocallib~" mindi > $local/sbin/mindi
    82 sed -e "s~= "YYY"~= "$subconf"~" mindi-bkphw > $local/sbin/mindi-bkphw
    83 chmod 755 $local/sbin/mindi $local/sbin/mindi-bkphw
     63sed -i -e "s~^MINDI_PREFIX=XXX~MINDI_PREFIX=$sublocal~" -e "s~^MINDI_CONF=YYY~MINDI_CONF=$subconf~" -e "s~^MINDI_LIB=LLL~MINDI_LIB=$sublocallib~" $local/bin/mindi
     64sed -i -e "s~= "YYY"~= "$subconf"~" $local/bin/mindi-bkphw
    8465install -m 755 parted2fdisk.pl $local/sbin
    85 
    86 install -m 644 mindi.8 $MANDIR
    87 #install -m 644 ChangeLog COPYING README README.busybox README.ia64 README.pxe TODO INSTALL svn.log $DOCDIR
    88 
    89 if [ "_$PREFIX" = "_" ] && [ ! -f $locallib/mindi/rootfs/bin/busybox ]; then
    90         echo "WARNING: no busybox found, mindi will not work on this arch ($ARCH)"
    91 fi
    9266
    9367# Managing parted2fdisk
     
    10579
    10680if [ "$PKGBUILDMINDI" != "true" ]; then
    107     chown -R root:root $locallib/mindi $conf # $DOCDIR
    108     chown root:root $local/sbin/mindi $MANDIR/mindi.8 $locallib/mindi/analyze-my-lvm $local/sbin/parted2fdisk.pl
     81    chown -R root:root $sublocallib/mindi $conf
     82    chown root:root $local/sbin/parted2fdisk.pl
    10983    if [ "$ARCH" = "ia64" ] ; then
    11084        chown root:root $local/sbin/parted2fdisk
  • devel/mindi/sbin/mindi

    r2003 r2149  
    1818use File::Copy;
    1919use File::stat;
    20 use File::Temp qw(tempdir);
    21 use POSIX qw(strftime);
    2220use Digest::MD5 qw(md5_hex);
    2321use lib qw (lib);
     22use POSIX qw(strftime);
    2423use ProjectBuilder::Base;
    2524use ProjectBuilder::Conf;
    2625use ProjectBuilder::Distribution;
     26use ProjectBuilder::Display;
     27use MondoRescue::Mindi::LVM;
     28use MondoRescue::Base;
    2729
    2830# Global variables
     
    161163#
    162164my $MINDI_VERSION = "PBVER-rPBREV";
    163 my $MINDI_PREFIX = "PBPREFIX";
    164 my $MINDI_CONF = "PBCONF";
    165 my $MINDI_LIB = "PBLIB";
     165my $MINDI_PREFIX = "XXX";
     166my $MINDI_CONF = "YYY";
     167my $MINDI_LIB = "LLL";
    166168my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
    167169my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
     
    246248# LVM setup
    247249#
    248 my $LVM = "none";
    249 my $LVMCMD = "";
    250 if (-d "/proc/lvm") {
    251     # Version 1
    252     $LVM = "v1";
    253 } elsif (-d "/dev/mapper") {
    254     # Version 2
    255     $LVM = "v2";
    256     $LVMCMD = "lvm";
    257 }   
    258 pb_log(0,"LVM set to $LVM");
    259 pb_log(0,"-------------------------------------");
     250my ($lvmver,$lvmcmd) = mr_lvm_check();
     251
     252pb_log(0,"LVM $lvmver command set to $lvmcmd");
     253pb_log(0,"-------------------------------------");
     254mr_exit(0);
  • devel/mindi/sbin/mranalyze-lvm

    r2119 r2149  
    1515use Data::Dumper;
    1616use English;
    17 use File::Basename;
    18 use File::Copy;
    19 use File::stat;
    20 use File::Temp qw(tempdir);
    21 use POSIX qw(strftime);
    2217use lib qw (lib);
    2318use ProjectBuilder::Base;
    2419use ProjectBuilder::Distribution;
     20use MondoRescue::Base;
     21use MondoRescue::Mindi::LVM;
    2522
    2623=pod
     
    137134
    138135# -------------------------------- main -----------------------------------
    139 my ($lvmver,$lvmcmd) = mr_lvm_check();
    140 
    141136# Where to send the output
    142137my $OUTPUT = \*STDOUT;
     
    146141}
    147142
    148 print $OUTPUT "LVM:$lvmver";
     143my $ret = mr_lvm_analyze($OUTPUT);
    149144
    150 # Analyze the existing physical volumes
    151 open(LVM,"$lvmcmd pvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd pvdisplay -c");
    152 while (<LVM>) {
    153         print $OUTPUT "PV:$_";
     145if ($ret == 0) {
     146    pb_log(1,"No LVM handling")
     147} else {
     148    pb_log(1,"LVM v$lvmver Structure Analyzed")
    154149}
    155 close(LVM);
    156 
    157 # Analyze the existing volume groups
    158 open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c");
    159 while (<LVM>) {
    160         print $OUTPUT "VG:$_";
    161 }
    162 close(LVM);
    163 
    164 # Analyze the existing logical volumes
    165 open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c");
    166 while (<LVM>) {
    167         print $OUTPUT "LV:$_";
    168 }
    169 close(LVM);
    170 
     150close($OUTPUT);
    171151mr_exit(0,undef);
    172 
    173 sub mr_exit {
    174 
    175 my $code = shift;
    176 my $msg = shift;
    177 
    178 close(OUTPUT);
    179 print $msg."\n" if ((defined $msg) and ($pbdebug >= 0));
    180 die "ERROR returned\n" if ($code < 0);
    181 print "No LVM handling\n" if (($code > 0) and ($pbdebug >= 0));
    182 exit($code);
    183 }
  • devel/mindi/sbin/mrprepare-lvm

    r2135 r2149  
    1515use Data::Dumper;
    1616use English;
    17 use File::Basename;
    18 use File::Copy;
    19 use File::stat;
    20 use File::Temp qw(tempdir);
    21 use POSIX qw(strftime);
    2217use lib qw (lib);
    2318use ProjectBuilder::Base;
    2419use ProjectBuilder::Distribution;
     20use MondoRescue::Base;
     21use MondoRescue::Mindi::LVM;
    2522
    2623=pod
     
    149146
    150147# -------------------------------- main -----------------------------------
    151 my ($lvmver,$lvmcmd) = mr_lvm_check();
    152 
    153148# Where to send the output
    154149my $OUTPUT = \*STDOUT;
     
    165160}
    166161
     162mr_lvm_prepare($INPUT,$OUTPUT,$mrmult);
    167163
    168 # Generate the startup scrit needed to restore LVM conf
    169 # from what is given on input
    170 # Multiply by the multiplier given in input or 1 of none
    171 print $OUTPUT "# Desactivate Volume Groups\n";
    172 print $OUTPUT "$lvmcmd vgchange -an\n";
    173 print $OUTPUT "\n";
    174 
    175 my $firsttime = 0;
    176 while (<INPUT>) {
    177     if (/^PV:/) {
    178         my ($tag,$pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
    179         print $OUTPUT "# Creating Physical Volumes $pvname\n";
    180         print $OUTPUT "$lvmcmd pvcreate -ff -y -s ".$pesize*$mrmult." $pvname\n";
    181         print $OUTPUT "\n";
    182     } elsif (/^VG:/) {
    183         my ($tag,$vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
    184         if ($lvmver < 2) {
    185             print $OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
    186             print $OUTPUT "rm -Rf /dev/$vgname\n";
    187         }
    188         $lvmaxnum = 255 if ($lvmaxnum > 256);
    189         $pvmaxnum = 255 if ($pvmaxnum > 256);
    190         print $OUTPUT "# Create Volume Group $vgname\n";
    191         # Pb sur pesize unite ?
    192         print $OUTPUT "$lvmcmd vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum\n";
    193         print $OUTPUT "\n";
    194     } elsif (/^LV:/) {
    195         if ($firsttime eq 0) {
    196             print $OUTPUT "\n";
    197             print $OUTPUT "# Activate All Volume Groups\n";
    198             print $OUTPUT "$lvmcmd vgchange -ay\n";
    199             print $OUTPUT "\n";
    200             $firsttime = 1;
    201         }
    202         my ($tag,$lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$readahead,$major,$minor) = split(/:/);
    203         print $OUTPUT "# Create Logical Volume $lvname\n";
    204         print $OUTPUT "$lvmcmd lvcreate -n $lvname -L ".$lvsize*$mrmult." -r $readahead $vgname\n";
    205         #[ "$stripes" ]    && output="$output -i $stripes"
    206         #[ "$stripesize" ] && output="$output -I $stripesize"
    207     }
    208 }
    209 print $OUTPUT "\n";
    210 print $OUTPUT "# Scanning again Volume Groups\n";
    211 print $OUTPUT "$lvmcmd vgscan\n";
    212 print $OUTPUT "\n";
    213 
    214 
     164close($INPUT);
     165close($OUTPUT);
    215166#WriteShutdownScript
    216167mr_exit(0,"End of mrprepare-lvm");
    217 
    218 sub mr_exit {
    219 
    220 my $code = shift;
    221 my $msg = shift || "";
    222 
    223 close(OUTPUT);
    224 print $msg."\n";
    225 die "ERROR returned\n" if ($code < 0);
    226 print "No LVM handling\n" if ($code > 0);
    227 exit(0);
    228 }
Note: See TracChangeset for help on using the changeset viewer.