summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-10-29 00:00:15 +0000
committerOlivier Blin <oblin@mandriva.com>2008-10-29 00:00:15 +0000
commit1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19 (patch)
tree2c3dac9f3552ce96bbca52aedfb3e370fdfd7111
parent208f1e470d70eec5f372b26c7c467c3e080c90d6 (diff)
downloaddrakiso-1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19.tar
drakiso-1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19.tar.gz
drakiso-1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19.tar.bz2
drakiso-1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19.tar.xz
drakiso-1396cd3dcbfdd55d887e661a9b6a4620a1b9ea19.zip
extract loop types in MDV::Draklive::Loopback
-rwxr-xr-xdraklive104
-rw-r--r--lib/MDV/Draklive/Loopback.pm115
2 files changed, 116 insertions, 103 deletions
diff --git a/draklive b/draklive
index 9611ab9..b1946c8 100755
--- a/draklive
+++ b/draklive
@@ -38,6 +38,7 @@ use MDV::Draklive::Live;
use MDV::Draklive::Media;
use MDV::Draklive::StorageFS;
use MDV::Draklive::Progress;
+use MDV::Draklive::Loopback;
my $dir_distrib_sqfs = {
mountpoint => '/distrib',
@@ -184,109 +185,6 @@ sub nls_modules {
if_($fs !~ /^ext/, map { "nls_$_" } (map { "iso8859_$_" } 1..7, 9, 13..15), 'utf8');
}
-my $loop_number = 0;
-my %loop_types;
-%loop_types = (
- squashfs => {
- read_only => 1,
- is_loopback => 1,
- modules => [ qw(loop sqlzma squashfs_lzma) ],
- extension => '-lzma.sqfs',
- build => sub {
- my ($live, $dir) = @_;
- my $dest = $live->get_builddir . $live->{prefix}{build}{loopbacks} . $dir->{path} . $loop_types{squashfs}{extension};
- mkdir_p(dirname($dest));
- my $root = $dir->{root} || $live->get_system_root;
- my $src = $root . $dir->{build_from};
- my $total = directory_usage($src);
- print "have to process " . int($total/1000000) . " MB\n";
- my $progress = MDV::Draklive::Progress->new($total, time(), 6);
- my $exclude_file = tmpnam();
- output_p($exclude_file, map { $root . "$_\n" } grep { -e $root . $_ } @{$dir->{exclude} || []});
- my $sort = $live->{settings}{config_root} . '/' . $dir->{sort};
- run_foreach(sub {
- if (/^mksquashfs: file .*, uncompressed size (\d+) bytes\s*(?:DUPLICATE|LINK)?$/) {
- $progress->{current} += $1;
- $progress->show(time());
- }
- },
- 'mksquashfs', $src, $dest, '-noappend', '-no-progress', '-info', '-lzma',
- #'-processors', 1,
- '-ef', $exclude_file,
- if_(-f $sort, '-sort', $sort),
- ) or die "unable to run mksquashfs\n";
- $progress->end;
- unlink $exclude_file;
- },
- mount => sub {
- my ($live, $dir) = @_;
- $dir->{loop} = "/dev/loop" . $loop_number++;
- my $media_loopbacks = $live->get_media_prefix('loopbacks');
- (
- "/bin/losetup $dir->{loop} $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}$loop_types{squashfs}{extension}",
- "nash-mount -o ro -t squashfs $dir->{loop} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
- );
- },
- },
- modules => {
- read_only => 1,
- delay_mount => 1,
- mount => sub {
- my ($live, $dir) = @_;
- my $media_loopbacks = $live->get_media_prefix('loopbacks');
- "sh -c 'modules=; for m in $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}/*; do n=\$(basename \$m); n=\${n%.sqfs}; d=$live->{prefix}{live}{mnt}$dir->{mountpoint}/\$n; mkdir -p \$d; mount -n -o loop,ro -t squashfs \$m \$d && modules=\$modules\$d=ro:; done; echo \$modules | sed -e s/:\$// > $live->{prefix}{live}{mnt}/$dir->{list}'";
- },
- },
- loopfs => {
- is_loopback => 1,
- modules => [],
- extension => '.loop',
- build => sub {
- my ($live, $dir) = @_;
- my $dest = $live->get_builddir . $live->{prefix}{build}{loopbacks} . $dir->{path} . $loop_types{loopfs}{extension};
- mkdir_p(dirname($dest));
- MDV::Draklive::Utils::device_allocate_file($dest, $dir->{pre_allocate});
- MDV::Draklive::Utils::device_mkfs($dest, $dir->{fs}) if !defined $dir->{min_size};
- },
- mount => sub {
- my ($live, $dir) = @_;
- $dir->{loop} = "/dev/loop" . $loop_number++;
- my $fsck = "chroot </dev/tty1 $live->{prefix}{live}{mnt}$dir_distrib_sqfs->{mountpoint} /sbin/fsck $dir->{loop}";
- my $media_loopbacks = $live->get_media_prefix('loopbacks');
- (
- "losetup $dir->{loop} $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}$loop_types{loopfs}{extension}",
- qq(sh -c "$fsck -a || $fsck -y"),
- "nash-mount -t $dir->{fs} $dir->{loop} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
- );
- },
- },
- plain => {
- mount => sub {
- my ($live, $dir) = @_;
- qq(sh -c "mkdir -p $live->{prefix}{live}{mnt}$dir->{mountpoint}");
- },
- },
- partition => {
- files => [ '/sbin/fsck', '/sbin/blkid' ],
- mount => sub {
- my ($live, $dir) = @_;
- my $fsck = "/bin/fsck";
- (
- qq(sh -c 'dev=`blkid -l -t $dir->{path} -o device`; [ -z "\$dev" ] || $fsck -a \$dev || $fsck -y \$dev'),
- "nash-mount -t $dir->{fs} $dir->{path} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
- );
- },
- },
- tmpfs => {
- mount => sub {
- my ($live, $dir) = @_;
- my $mnt = $live->{prefix}{live}{mnt} . $dir->{mountpoint};
- my $cmd = "mount -t tmpfs $mnt $mnt";
- $dir->{fallback} ? qq(sh -c 'if ! grep -q " $mnt " /proc/mounts; then $cmd; fi') : $cmd;
- },
- },
-);
-
my %overlay = (
unionfs => {
modules => [ qw(unionfs) ],
diff --git a/lib/MDV/Draklive/Loopback.pm b/lib/MDV/Draklive/Loopback.pm
new file mode 100644
index 0000000..768b708
--- /dev/null
+++ b/lib/MDV/Draklive/Loopback.pm
@@ -0,0 +1,115 @@
+package MDV::Draklive::Loopback;
+
+use MDK::Common;
+use File::Temp;
+use MDV::Draklive::Progress;
+use MDV::Draklive::Utils;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(%loop_types);
+
+my $loop_number = 0;
+our %loop_types;
+%loop_types = (
+ squashfs => {
+ read_only => 1,
+ is_loopback => 1,
+ modules => [ qw(loop sqlzma squashfs_lzma) ],
+ extension => '-lzma.sqfs',
+ build => sub {
+ my ($live, $dir) = @_;
+ my $dest = $live->get_builddir . $live->{prefix}{build}{loopbacks} . $dir->{path} . $loop_types{squashfs}{extension};
+ mkdir_p(dirname($dest));
+ my $root = $dir->{root} || $live->get_system_root;
+ my $src = $root . $dir->{build_from};
+ my $total = directory_usage($src);
+ print "have to process " . int($total/1000000) . " MB\n";
+ my $progress = MDV::Draklive::Progress->new($total, time(), 6);
+ my $exclude_file = tmpnam();
+ output_p($exclude_file, map { $root . "$_\n" } grep { -e $root . $_ } @{$dir->{exclude} || []});
+ my $sort = $live->{settings}{config_root} . '/' . $dir->{sort};
+ run_foreach(sub {
+ if (/^mksquashfs: file .*, uncompressed size (\d+) bytes\s*(?:DUPLICATE|LINK)?$/) {
+ $progress->{current} += $1;
+ $progress->show(time());
+ }
+ },
+ 'mksquashfs', $src, $dest, '-noappend', '-no-progress', '-info', '-lzma',
+ #'-processors', 1,
+ '-ef', $exclude_file,
+ if_(-f $sort, '-sort', $sort),
+ ) or die "unable to run mksquashfs\n";
+ $progress->end;
+ unlink $exclude_file;
+ },
+ mount => sub {
+ my ($live, $dir) = @_;
+ $dir->{loop} = "/dev/loop" . $loop_number++;
+ my $media_loopbacks = $live->get_media_prefix('loopbacks');
+ (
+ "/bin/losetup $dir->{loop} $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}$loop_types{squashfs}{extension}",
+ "nash-mount -o ro -t squashfs $dir->{loop} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
+ );
+ },
+ },
+ modules => {
+ read_only => 1,
+ delay_mount => 1,
+ mount => sub {
+ my ($live, $dir) = @_;
+ my $media_loopbacks = $live->get_media_prefix('loopbacks');
+ "sh -c 'modules=; for m in $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}/*; do n=\$(basename \$m); n=\${n%.sqfs}; d=$live->{prefix}{live}{mnt}$dir->{mountpoint}/\$n; mkdir -p \$d; mount -n -o loop,ro -t squashfs \$m \$d && modules=\$modules\$d=ro:; done; echo \$modules | sed -e s/:\$// > $live->{prefix}{live}{mnt}/$dir->{list}'";
+ },
+ },
+ loopfs => {
+ is_loopback => 1,
+ modules => [],
+ extension => '.loop',
+ build => sub {
+ my ($live, $dir) = @_;
+ my $dest = $live->get_builddir . $live->{prefix}{build}{loopbacks} . $dir->{path} . $loop_types{loopfs}{extension};
+ mkdir_p(dirname($dest));
+ MDV::Draklive::Utils::device_allocate_file($dest, $dir->{pre_allocate});
+ MDV::Draklive::Utils::device_mkfs($dest, $dir->{fs}) if !defined $dir->{min_size};
+ },
+ mount => sub {
+ my ($live, $dir) = @_;
+ $dir->{loop} = "/dev/loop" . $loop_number++;
+ my $fsck = "chroot </dev/tty1 $live->{prefix}{live}{mnt}$dir_distrib_sqfs->{mountpoint} /sbin/fsck $dir->{loop}";
+ my $media_loopbacks = $live->get_media_prefix('loopbacks');
+ (
+ "losetup $dir->{loop} $live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$dir->{path}$loop_types{loopfs}{extension}",
+ qq(sh -c "$fsck -a || $fsck -y"),
+ "nash-mount -t $dir->{fs} $dir->{loop} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
+ );
+ },
+ },
+ plain => {
+ mount => sub {
+ my ($live, $dir) = @_;
+ qq(sh -c "mkdir -p $live->{prefix}{live}{mnt}$dir->{mountpoint}");
+ },
+ },
+ partition => {
+ files => [ '/sbin/fsck', '/sbin/blkid' ],
+ mount => sub {
+ my ($live, $dir) = @_;
+ my $fsck = "/bin/fsck";
+ (
+ qq(sh -c 'dev=`blkid -l -t $dir->{path} -o device`; [ -z "\$dev" ] || $fsck -a \$dev || $fsck -y \$dev'),
+ "nash-mount -t $dir->{fs} $dir->{path} $live->{prefix}{live}{mnt}$dir->{mountpoint}",
+ );
+ },
+ },
+ tmpfs => {
+ mount => sub {
+ my ($live, $dir) = @_;
+ my $mnt = $live->{prefix}{live}{mnt} . $dir->{mountpoint};
+ my $cmd = "mount -t tmpfs $mnt $mnt";
+ $dir->{fallback} ? qq(sh -c 'if ! grep -q " $mnt " /proc/mounts; then $cmd; fi') : $cmd;
+ },
+ },
+);
+
+1;