misc:create-chroot
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
misc:create-chroot [2008/10/18 15:56] – external edit 127.0.0.1 | misc:create-chroot [2009/01/05 22:06] (current) – old revision restored siretart | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code perl> | ||
+ | # | ||
+ | use Getopt:: | ||
+ | use strict; | ||
+ | use Term:: | ||
+ | use File::Copy; | ||
+ | |||
+ | my %OPTS; | ||
+ | |||
+ | if ( !getopts(" | ||
+ | pod2usage(2); | ||
+ | } | ||
+ | |||
+ | die "Must run as root, sorry\n" | ||
+ | |||
+ | my $LVS; | ||
+ | my $LV = @ARGV[0]; | ||
+ | my $VG = $OPTS{g}; | ||
+ | |||
+ | my %MIRRORS = ( | ||
+ | gutsy => " | ||
+ | sid => " | ||
+ | ); | ||
+ | |||
+ | |||
+ | print "using mirror $MIRRORS{$LV} for $LV" if $MIRRORS{$LV} or die " | ||
+ | |||
+ | my $mountpoint = "/ | ||
+ | |||
+ | if ( ! $VG ) { | ||
+ | my $i = 0; | ||
+ | open(my $VGS, "/ | ||
+ | < | ||
+ | while (< | ||
+ | $i = $i + 1; | ||
+ | m/ | ||
+ | $VG = $1; | ||
+ | } | ||
+ | die " | ||
+ | } | ||
+ | |||
+ | print "using volume group $VG\n"; | ||
+ | my $device = "/ | ||
+ | |||
+ | # check for filesystem mounted... | ||
+ | open (my $MOUNTS, "/ | ||
+ | while (< | ||
+ | # example output: | ||
+ | #/ | ||
+ | if (m/^(\S+) (\S+)/) { | ||
+ | |||
+ | die " | ||
+ | die " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | print " | ||
+ | open ($LVS, "/ | ||
+ | < | ||
+ | while (< | ||
+ | if (m/ | ||
+ | my $VG = $2; | ||
+ | my $remove = undef; | ||
+ | if (! $OPTS{f}) { | ||
+ | $remove = prompt (" | ||
+ | } else { | ||
+ | $remove = 1; | ||
+ | } | ||
+ | if ($remove) { | ||
+ | print " | ||
+ | system (" | ||
+ | or die "could not remove $device: $?"; | ||
+ | } | ||
+ | last; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | my $size = $OPTS{L}; | ||
+ | if ( ! $size ) { | ||
+ | $size = " | ||
+ | } | ||
+ | |||
+ | print " | ||
+ | system("/ | ||
+ | or die "could not create $LV: $?"; | ||
+ | system("/ | ||
+ | or die " | ||
+ | system("/ | ||
+ | or die " | ||
+ | |||
+ | if (system("/ | ||
+ | system("/ | ||
+ | die " | ||
+ | } | ||
+ | |||
+ | copy("/ | ||
+ | copy("/ | ||
+ | |||
+ | system("/ | ||
+ | or die " | ||
+ | |||
+ | =head1 NAME | ||
+ | |||
+ | create-chroot | ||
+ | |||
+ | =head1 SYNOPSIS | ||
+ | |||
+ | create-chroot [-g VG] [-f] [-L size] distname | ||
+ | |||
+ | -g name of Volume group if several on this system | ||
+ | -f force removal of existing volume group | ||
+ | -L size of the logical volume. defaults to 3GB. | ||
+ | |||
+ | distname name of the distribution you want to bootstrap | ||
+ | |||
+ | =head1 DESCRIPTION | ||
+ | |||
+ | B< | ||
+ | ready for use with schroot. If the distribution already exists, the | ||
+ | existing logical volume will be removed. It checks if a volumegroup | ||
+ | named like the dist you want to install is already on the system. If | ||
+ | there isn't, then it will create a logical volume, make a filesystem and | ||
+ | bootstrap the selected system on it. It then copies the files | ||
+ | C</ | ||
+ | |||
+ | After setting it up, make sure you have the chroot added correctly to | ||
+ | C</ | ||
+ | |||
+ | =head1 AUTHOR | ||
+ | |||
+ | Reinhard Tartler < | ||
+ | |||
+ | </ |