mirror of https://github.com/tLDP/LDP
LVM changes.
This commit is contained in:
parent
a64914cbff
commit
dc6473cc19
|
@ -5,7 +5,7 @@
|
|||
# only option is -c, which forces bad block checking during formatting
|
||||
# of the partitions.
|
||||
|
||||
# Time-stamp: <2005-09-01 07:35:16 root first.stage>
|
||||
# Time-stamp: <2006-04-05 20:35:39 ccurley first.stage>
|
||||
|
||||
# Copyright 2002 through the last date of modification Charles Curley.
|
||||
|
||||
|
@ -42,22 +42,39 @@ then
|
|||
fi
|
||||
|
||||
for drive in $( ls make.dev.* ); do
|
||||
echo $drive$'\a'
|
||||
sleep 2
|
||||
./$drive $blockcheck;
|
||||
done
|
||||
|
||||
# If there are any LVM volumes, now is the time to restore them.
|
||||
|
||||
if [ -e LVM.backs ] && [ -e make.lvs ] && [ -e mount.lvs ]
|
||||
then
|
||||
echo make.lvs$'\a'
|
||||
sleep 2
|
||||
./make.lvs
|
||||
|
||||
echo mount.lvs$'\a'
|
||||
./mount.lvs
|
||||
fi
|
||||
|
||||
|
||||
# WARNING: If your Linux system mount partitions across hard drive
|
||||
# boundaries, you will have multiple "mount.dev.* scripts. You must
|
||||
# ensure that they run in the proper order, which the loop below may
|
||||
# not do. The root partition should be mounted first, then the rest in
|
||||
# the order they cascade. If they cross mount, you'll have to handle
|
||||
# that manually.
|
||||
# that manually. If you have LVMs to deal with, that's a whole 'nother
|
||||
# kettle of fish.
|
||||
|
||||
# The "ls -tr" will list the scripts in the order they are created, so
|
||||
# it might be a good idea to create them (in the script save.metadata)
|
||||
# in the order in which you should run them.
|
||||
|
||||
for drive in $( ls -tr mount.dev.* ); do
|
||||
echo $drive$'\a'
|
||||
sleep 2
|
||||
./$drive;
|
||||
done
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# run at restore time to rebuild hard drive x, prior to running
|
||||
# restore.metadata. dev.x is the input file for fdisk.
|
||||
|
||||
# Time-stamp: <2005-10-29 10:03:39 ccurley make.fdisk>
|
||||
# Time-stamp: <2006-04-05 20:36:21 ccurley make.fdisk>
|
||||
|
||||
# Copyright 2001 through the last date of modification Charles Curley
|
||||
# except for the subroutine cut2fmt.
|
||||
|
@ -51,6 +51,13 @@
|
|||
|
||||
# Changes:
|
||||
|
||||
# 2006-03-28: We have a problem if swap partitions have
|
||||
# labels. There's no way to retrieve the label from a swap
|
||||
# partition. If we have one & only one swap partition, then we can
|
||||
# pull it out of /etc/fstab. Otherwise the user is on her own. We scan
|
||||
# fstab for swap mount points that have labels for their devices. If
|
||||
# there is one and only one, we assume that's it, otherwise pass.
|
||||
|
||||
# 2005-10-29: We now provide the geometry as an argument to fdisk
|
||||
# (which does not work on tomsrtbt). We also save data for sfdisk, and
|
||||
# write out make.dev.xxx so that it will use sfdisk if it finds it.
|
||||
|
@ -175,6 +182,7 @@
|
|||
# For more information contact the author, Charles Curley, at
|
||||
# http://www.charlescurley.com/.
|
||||
|
||||
use File::Copy;
|
||||
|
||||
# cut2fmt figures out the format string for the unpack function we use
|
||||
# to slice and dice the output from fdisk. From Christiansen and
|
||||
|
@ -199,10 +207,12 @@ sub cut2fmt {
|
|||
# to the current output file.
|
||||
|
||||
sub gpl {
|
||||
my $FILE = shift;
|
||||
my $year = shift;
|
||||
|
||||
print OUTPUT <<FINIS;
|
||||
print $FILE <<FINIS;
|
||||
|
||||
# Copyright 2001 through the last date of modification Charles Curley.
|
||||
# Copyright $year through the last date of modification Charles Curley.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
|
@ -235,8 +245,162 @@ sub getBootSector {
|
|||
system ($systemcmd);
|
||||
}
|
||||
|
||||
# Begin main line code.
|
||||
|
||||
# If we have one & only one swap partition, then this must be
|
||||
# it. Otherwise the user is on her own. We scan fstab for swap mount
|
||||
# points that have labels for their devices. If there is one and only
|
||||
# one, we assume that's it, otherwise pass.
|
||||
|
||||
sub getswaplabel {
|
||||
my $dev = $_[0];
|
||||
|
||||
$fstabpid = open (FSTAB, "< /etc/fstab")
|
||||
or die "Couldn't fork: $!\n";
|
||||
while (defined (my $line = <FSTAB>)) {
|
||||
chop ($line);
|
||||
@fstabs = split (" ", $line);
|
||||
if (@fstabs[1] eq "swap") {
|
||||
$swaplabel = @fstabs[0];
|
||||
if ($swaplabel =~ /LABEL/) {
|
||||
$swaps++;
|
||||
$sl = substr ($swaplabel, 6);
|
||||
}
|
||||
# print ("\"@fstabs[0]\", \"@fstabs[1]\", \"$sl\", $swaps.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
close (FSTAB);
|
||||
|
||||
# print "label is $sl.\n";
|
||||
|
||||
if ($swaps == 1) {
|
||||
$ret = "mkswap \$blockcheck -L $sl";
|
||||
$ret .= " $dev\n\n";
|
||||
} else {
|
||||
$ret = "mkswap \$blockcheck $dev\n\n";
|
||||
}
|
||||
|
||||
# print ("Returning :$ret\n");
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
# dolvm is a subroutine to handle LVM partitions. This is
|
||||
# experimental....
|
||||
|
||||
sub dolvm {
|
||||
my $dev = $_[0];
|
||||
|
||||
print ("In dolvm ()...\n");
|
||||
|
||||
# back up the LVM's lvm details. Get the config files.
|
||||
system ("vgcfgbackup -f LVM.backs");
|
||||
|
||||
# Scan /etc/fstab for the logical volumes and write a script to
|
||||
# make file systems on them and another to mount 'em later on.
|
||||
|
||||
$mklvs = open (MKLVS, "> make.lvs")
|
||||
or die "Couldn't fork: $!\n";
|
||||
|
||||
print MKLVS <<FINIS;
|
||||
#! /bin/sh
|
||||
|
||||
# A script to create file systems on logical volumes. Created at bare
|
||||
# metal backup time by the Perl script make.fdisk.
|
||||
FINIS
|
||||
|
||||
&gpl (*MKLVS, "2006");
|
||||
|
||||
|
||||
print MKLVS <<FINIS;
|
||||
|
||||
export blockcheck=\$1;
|
||||
|
||||
if [ "\$blockcheck" != "-c" ] && [ -n "\$blockcheck" ]
|
||||
then
|
||||
echo "\${0}: Build file systems on logical volumes."
|
||||
echo "\${0}: -c: block check during file system making."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
export LVM_SYSTEM_DIR=\$(pwd)/lvm.cfg
|
||||
|
||||
FINIS
|
||||
|
||||
$mtlvs = open (MTLVS, "> mount.lvs")
|
||||
or die "Couldn't fork: $!\n";
|
||||
|
||||
print MTLVS <<FINIS;
|
||||
#! /bin/sh
|
||||
|
||||
# A script to mount file systems on logical volumes. Created at bare
|
||||
# metal backup time by the Perl script make.fdisk.
|
||||
FINIS
|
||||
|
||||
&gpl (*MTLVS, "2006");
|
||||
|
||||
|
||||
# Now cycle through all the known logical volumes & set them
|
||||
# up. N.B.: This has been tested on a machine with only one
|
||||
# LV. But it *should* work.
|
||||
|
||||
$pvdisp = open (PVDISP, "pvdisplay -c |")
|
||||
or die ("Can't open LVM display.\n");
|
||||
while (defined (my $pv = <PVDISP>)) {
|
||||
chop ($pv);
|
||||
print ("$pv\n");
|
||||
@pv = split (":", $pv);
|
||||
$uid = @pv[11];
|
||||
$pvname = @pv[1];
|
||||
$phv = @pv[0];
|
||||
print ("pv $pvname has uid $uid.\n");
|
||||
|
||||
print (MKLVS "echo \"y\\n\" | pvcreate -ff --uuid \"$uid\" --restorefile lvm.cfg/archive/${pvname}_*.vg $phv\n");
|
||||
print (MKLVS "vgcfgrestore --file LVM.backs $pvname\n\n");
|
||||
}
|
||||
|
||||
print (MKLVS "# Hideously disty dependent!\nif [ -e /etc/init.d/lvm ] ; then\n /etc/init.d/lvm start\nfi\n\n");
|
||||
|
||||
$fstabpid = open (FSTAB, "< /etc/fstab")
|
||||
or die "Couldn't fork: $!\n";
|
||||
while (defined (my $line = <FSTAB>)) {
|
||||
chop ($line);
|
||||
@fstabs = split (" ", $line);
|
||||
if (@fstabs[0] =~ /VolGroup/ ) {
|
||||
# print ("$line\n");
|
||||
if (@fstabs[2] eq "swap") {
|
||||
print (MKLVS "echo\necho making LV @fstabs[0] a swap partition.\n");
|
||||
print (MKLVS "mkswap \$blockcheck @fstabs[0]\n\n");
|
||||
} elsif (@fstabs[2] == "ext3") {
|
||||
print (MKLVS "echo\necho making LV @fstabs[0] an ext3 partition.\n");
|
||||
print (MKLVS "mke2fs -j \$blockcheck @fstabs[0]\n\n");
|
||||
|
||||
print (MTLVS "mkdir -p /target$fstabs[1]\n");
|
||||
print (MTLVS "mount @fstabs[0] /target$fstabs[1]\n\n");
|
||||
} elsif (@fstabs[2] == "ext2") {
|
||||
print (MKLVS "echo\necho making LV @fstabs[0] an ext2 partition.\n");
|
||||
print (MKLVS "mke2fs \$blockcheck @fstabs[0]\n\n");
|
||||
|
||||
print (MTLVS "mkdir -p /target$fstabs[1]\n");
|
||||
print (MTLVS "mount @fstabs[0] /target$fstabs[1]\n\n");
|
||||
} else {
|
||||
print ("Opps, unknown type of logical volume, @fstabs[0]\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
print (MTLVS "\nmount | grep -i \"/target\"\n");
|
||||
|
||||
close (FSTAB);
|
||||
close (MKLVS);
|
||||
close (MTLVS);
|
||||
|
||||
print ("Leaving dolvm ()...\n");
|
||||
|
||||
return ($ret);
|
||||
}
|
||||
|
||||
|
||||
# Begin main line code.
|
||||
|
||||
# Provide a default device.
|
||||
|
||||
|
@ -444,16 +608,17 @@ while (<FDISK>) {
|
|||
print OUTPUT "@_[$lastcyl]\n";
|
||||
}
|
||||
$typechanges .= "t\n$partnumber\n82\n";
|
||||
$format .= "echo Making @_[$dev] a swap partition.\n";
|
||||
$format .= "echo\necho Making @_[$dev] a swap partition.\n";
|
||||
if ($labels{@_[$dev]}) { # do we have a label?
|
||||
$format .= "mkswap \$blockcheck -L $labels{@_[$dev]}";
|
||||
$format .= " @_[$dev]\n\n";
|
||||
} else {
|
||||
$format .= "mkswap \$blockcheck @_[$dev]\n\n";
|
||||
$format .= getswaplabel (@_[$dev]);
|
||||
}
|
||||
|
||||
# Primary mess-dos partition. We don't handle hidden
|
||||
# partitions.
|
||||
|
||||
} elsif ( @_[$parttype] == 1 || @_[$parttype] == 4 || @_[$parttype] == 6
|
||||
|| @_[$parttype] eq "b" || @_[$parttype] eq "c"
|
||||
|| @_[$parttype] eq "e" ) {
|
||||
|
@ -479,6 +644,8 @@ while (<FDISK>) {
|
|||
$format .= "dd if=$outputfilename$partnumber";
|
||||
$format .= " of=@_[$dev] bs=512 count=1\n\n";
|
||||
|
||||
} elsif ( @_[$parttype] == "8e") {
|
||||
$format .= dolvm ($_[$dev]);
|
||||
} else {
|
||||
# anything else partition
|
||||
print OUTPUT "p\n@_[$firstcyl]\n";
|
||||
|
@ -532,12 +699,12 @@ while (<FDISK>) {
|
|||
print OUTPUT "@_[$lastcyl]\n";
|
||||
}
|
||||
$typechanges .= "t\n$partnumber\n82\n";
|
||||
$format .= "echo Making @_[$dev] a swap partition.\n";
|
||||
$format .= "echo\necho Making @_[$dev] a swap partition.\n";
|
||||
if ($labels{@_[$dev]}) { # do we have a label?
|
||||
$format .= "mkswap \$blockcheck -L $labels{@_[$dev]}";
|
||||
$format .= " @_[$dev]\n\n";
|
||||
} else {
|
||||
$format .= "mkswap \$blockcheck @_[$dev]\n\n";
|
||||
$format .= getswaplabel (@_[$dev]);
|
||||
}
|
||||
|
||||
# Logical mess-dos partition. We don't handle hidden
|
||||
|
@ -567,6 +734,8 @@ while (<FDISK>) {
|
|||
$format .= "dd if=$outputfilename$partnumber";
|
||||
$format .= " of=@_[$dev] bs=512 count=1\n\n";
|
||||
|
||||
} elsif ( @_[$parttype] == "8e") {
|
||||
$format .= dolvm ($_[$dev]);
|
||||
} else {
|
||||
# anything else partition
|
||||
print OUTPUT "l\n@_[$firstcyl]\n";
|
||||
|
@ -575,7 +744,6 @@ while (<FDISK>) {
|
|||
}
|
||||
$typechanges .= "t\n$partnumber\n@_[$parttype]\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# handle bootable partitions
|
||||
|
@ -593,7 +761,7 @@ while (<FDISK>) {
|
|||
# print $_; # again, for grins.
|
||||
chop;
|
||||
@geometry = split (/ /, $_);
|
||||
$geometry = " -H $geometry[0] -S $geometry[2] -C $geometry[4]";
|
||||
$geometry = "-H $geometry[0] -S $geometry[2] -C $geometry[4]";
|
||||
# print $geometry;
|
||||
}
|
||||
}
|
||||
|
@ -619,10 +787,16 @@ print OUTPUT <<FINIS;
|
|||
# make.fdisk.
|
||||
FINIS
|
||||
|
||||
&gpl;
|
||||
&gpl (*OUTPUT, "2001");
|
||||
|
||||
print OUTPUT <<FINIS;
|
||||
|
||||
swapoff -a
|
||||
# Hideously disty dependent!
|
||||
if [ -e /etc/init.d/lvm ] ; then
|
||||
/etc/init.d/lvm stop
|
||||
fi
|
||||
|
||||
export blockcheck=\$1;
|
||||
|
||||
if [ "\$blockcheck" != "-c" ] && [ -n "\$blockcheck" ]
|
||||
|
@ -637,7 +811,7 @@ FINIS
|
|||
# Clean the old partition table out. Turn off swap in case we're using
|
||||
# it.
|
||||
|
||||
print OUTPUT "dd if=/dev/zero of=$device bs=512 count=2\n\nswapoff -a\nsync\n\n";
|
||||
print OUTPUT "dd if=/dev/zero of=$device bs=512 count=2\n\nsync\n\n";
|
||||
|
||||
|
||||
# command for fdisk
|
||||
|
@ -673,7 +847,7 @@ print OUTPUT <<FINIS;
|
|||
# the Perl script make.fdisk.
|
||||
FINIS
|
||||
|
||||
&gpl;
|
||||
&gpl (*OUTPUT, "2001");
|
||||
|
||||
print OUTPUT <<FINIS;
|
||||
|
||||
|
@ -700,16 +874,17 @@ FINIS
|
|||
foreach $point ( sort keys %mountpoints) {
|
||||
print OUTPUT "\n# $point is the mountpoint for";
|
||||
print OUTPUT " tomsrtbt device $mountpoints{$point}.\n";
|
||||
print OUTPUT "mkdir $target$point\n";
|
||||
print OUTPUT "mkdir -p $target$point\n";
|
||||
print OUTPUT "mount $mountpoints{$point} $target$point\n";
|
||||
}
|
||||
|
||||
print OUTPUT "\nmount | grep -i \"$device\"\n";
|
||||
print OUTPUT "\nmount | grep -i \"/target\"\n";
|
||||
|
||||
close (OUTPUT);
|
||||
|
||||
# These scripts are dangerous & should only be visible to root.
|
||||
|
||||
chmod 0700, "${outputfilepath}make.$outputfilename";
|
||||
chmod 0700, "${outputfilepath}make.lvs";
|
||||
chmod 0700, "${outputfilepath}mount.$outputfilename";
|
||||
chmod 0600, "${outputfilepath}${outputfilename}*";
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# and mounted. It also assumes the ZIP disk has already been
|
||||
# mounted. Mounting the ZIP disk read only is probably a good idea.
|
||||
|
||||
# Time-stamp: <2005-10-11 08:45:19 root restore.metadata>
|
||||
# Time-stamp: <2006-04-05 20:36:49 ccurley restore.metadata>
|
||||
|
||||
# Copyright 2000 through the last date of modification Charles Curley.
|
||||
|
||||
|
@ -45,11 +45,11 @@
|
|||
|
||||
umask 0000
|
||||
|
||||
cd .. # Assume we are in root.bin
|
||||
zip=$(pwd); # Where we mount the zip drive.
|
||||
target="/target"; # Where the hard drive to restore is mounted.
|
||||
cd .. # Assume we are in root.bin
|
||||
zip=$(pwd); # Where we mount the zip drive.
|
||||
target="/target"; # Where the hard drive to restore is mounted.
|
||||
|
||||
ls -lt $zip/*.bz2 # Warm fuzzies for the user.
|
||||
ls -lt $zip/*.bz2 # Warm fuzzies for the user.
|
||||
|
||||
cd $target
|
||||
|
||||
|
@ -68,7 +68,7 @@ done
|
|||
# xfs font server.
|
||||
|
||||
for dir in mnt/dosc mnt/zip mnt/imports mnt/nfs proc initrd tmp/.font-unix\
|
||||
var/empty/sshd var/log back selinux sys /var/cache/yum; do
|
||||
var/empty/sshd var/log back selinux sys /var/cache/yum /var/lock; do
|
||||
mkdir -p $target/$dir
|
||||
done
|
||||
|
||||
|
@ -76,7 +76,38 @@ for dir in mnt usr usr/share $(ls -d var/*) selinux usr/lib var var/cache/yum; d
|
|||
chmod go-w $target/$dir
|
||||
done
|
||||
|
||||
# chmod a-w $target/proc # Restore /proc's read-only permissions
|
||||
chown root:lock /var/lock
|
||||
chmod 775 /var/lock
|
||||
|
||||
# [root@jhereg /]# ll -d mnt usr usr/share $(ls -d var/*) selinux usr/lib var var/cache/yum
|
||||
# drwxr-xr-x 4 root root 4096 Oct 10 08:55 mnt
|
||||
# drwxr-xr-x 2 root root 4096 Oct 10 08:41 selinux
|
||||
# drwxr-xr-x 14 root root 4096 Oct 10 08:46 usr
|
||||
# drwxr-xr-x 40 root root 12288 Oct 10 10:40 usr/lib
|
||||
# drwxr-xr-x 63 root root 4096 Oct 10 11:11 usr/share
|
||||
# drwxr-xr-x 20 root root 4096 Oct 10 08:52 var
|
||||
# drwxr-xr-x 2 root root 4096 Oct 10 08:51 var/account
|
||||
# drwxr-xr-x 4 root root 4096 Oct 10 08:53 var/cache
|
||||
# drwxr-xr-x 4 root root 4096 Oct 10 10:44 var/cache/yum
|
||||
# drwxr-xr-x 3 netdump netdump 4096 Aug 22 13:13 var/crash
|
||||
# drwxr-xr-x 3 root root 4096 Oct 10 08:51 var/db
|
||||
# drwxr-xr-x 3 root root 4096 Oct 10 08:52 var/empty
|
||||
# drwxr-xr-x 13 root root 4096 Oct 10 11:11 var/lib
|
||||
# drwxr-xr-x 2 root root 4096 May 22 22:28 var/local
|
||||
# drwxrwxr-x 4 root lock 4096 Sep 1 08:37 var/lock
|
||||
# drwxr-xr-x 7 root root 4096 Oct 10 11:14 var/log
|
||||
# lrwxrwxrwx 1 root root 10 Oct 10 08:42 var/mail -> spool/mail
|
||||
# drwxr-x--- 4 root named 4096 Aug 22 14:33 var/named
|
||||
# drwxr-xr-x 2 root root 4096 May 22 22:28 var/nis
|
||||
# drwxr-xr-x 2 root root 4096 May 22 22:28 var/opt
|
||||
# drwxr-xr-x 2 root root 4096 May 22 22:28 var/preserve
|
||||
# drwxr-xr-x 2 root root 4096 Mar 28 2005 var/racoon
|
||||
# drwxr-xr-x 13 root root 4096 Oct 10 11:14 var/run
|
||||
# drwxr-xr-x 13 root root 4096 Oct 10 08:53 var/spool
|
||||
# drwxrwxrwt 2 root root 4096 Oct 10 11:14 var/tmp
|
||||
# drwxr-xr-x 3 root root 4096 Oct 10 08:53 var/yp
|
||||
|
||||
# chmod a-w $target/proc # Restore /proc's read-only permissions
|
||||
|
||||
# Set modes
|
||||
chmod 0111 $target/var/empty/sshd
|
||||
|
|
Loading…
Reference in New Issue