diff options
Diffstat (limited to 'rescue/tree')
26 files changed, 694 insertions, 1497 deletions
diff --git a/rescue/tree/bin/insmod b/rescue/tree/bin/insmod deleted file mode 100755 index 717dc39e1..000000000 --- a/rescue/tree/bin/insmod +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -echo "Use modprobe instead" -echo "Or even better use autoprobe" diff --git a/rescue/tree/boot/grub/menu.lst b/rescue/tree/boot/grub/menu.lst deleted file mode 100644 index 1af0c85e3..000000000 --- a/rescue/tree/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -timeout 0 - -title oem -kernel (hd0,0)/boot/vmlinuz ramdisk_size=32000 hd vga=788 fbeginner oem -initrd (hd0,0)/boot/hd.rdz diff --git a/rescue/tree/etc/hostname b/rescue/tree/etc/hostname new file mode 100644 index 000000000..344f71bc8 --- /dev/null +++ b/rescue/tree/etc/hostname @@ -0,0 +1 @@ +rescue diff --git a/rescue/tree/etc/hosts b/rescue/tree/etc/hosts index a9bbdee7f..d02c36416 100644 --- a/rescue/tree/etc/hosts +++ b/rescue/tree/etc/hosts @@ -1 +1 @@ -127.0.0.1 mandrake-rescue +127.0.0.1 mageia-rescue diff --git a/rescue/tree/etc/inittab b/rescue/tree/etc/inittab deleted file mode 100644 index 0348c66f4..000000000 --- a/rescue/tree/etc/inittab +++ /dev/null @@ -1,14 +0,0 @@ -#Inittab for Mandrake Rescue Disk -#Author: Daouda Lo <daouda@mandrakesoft.com> -id:3:initdefault: - -si::sysinit:/etc/rc.sysinit -re:6:wait:/etc/rc.reboot -ca:12345:ctrlaltdel:/sbin/fakeshutdown - -1:12345:respawn:/bin/bash --login -2:23:respawn:/sbin/mingetty tty2 -3:23:respawn:/sbin/mingetty tty3 -4:23:respawn:/sbin/mingetty tty4 -5:23:respawn:/sbin/mingetty tty5 -6:23:respawn:/sbin/mingetty tty6 diff --git a/rescue/tree/etc/issue b/rescue/tree/etc/issue index 6de73abad..11f9f3102 100644 --- a/rescue/tree/etc/issue +++ b/rescue/tree/etc/issue @@ -11,17 +11,20 @@ [1;30;44m [40m [47m [40m [44m [40m[2[1;37;4[0m [1;30;44m [40m [47m [40m [30;44m [40m[2C[1;37;40m[0m [1;30;44m [40m [47m [40m [2C[1;37;40m[0m -[1;30;44m [40m [47m [40m [2C[1;37;40mMandrake Linux Rescue Disk[0m +[1;30;44m [40m [47m [40m [2C[1;37;40mMageia Linux Rescue Disk[0m [1;30;44m [43m [30;47m [43m [40m [2C[1;37;40m[0m [1;30;44m [43m [47m [43m [40m [2C [1;30;44m [43m [47m [43m [40m[2C [1;30;44m [43m [40m [47m [40m [43m [40m[2C [0m[255D -Mandrake Linux release 9.1 +DISTRIB_DESCR Use [1;33;40mloadkeys[0m to change your keyboard layout (eg: loadkeys fr) Use [1;33;40mmodprobe[0m to load modules (eg: modprobe snd-card-fm801) Use [1;33;40mdrvinst[0m to install drivers according to detected devices Use [1;33;40mlsparts[0m to list your partitions with types +Use [1;33;40mstartssh[0m to start an ssh daemon +Use [1;33;40mrescue-gui[0m to go back to the rescue menu +Use [1;33;40mgrabjournallogs[0m to grab the last 24 hours of journal logs diff --git a/rescue/tree/etc/oem b/rescue/tree/etc/oem deleted file mode 100755 index 3c97ec134..000000000 --- a/rescue/tree/etc/oem +++ /dev/null @@ -1,665 +0,0 @@ -#!/usr/bin/perl - -if (shift(@ARGV) ne '-f') { - print "Call it with option -f, but don't fear loosing all your data, this command is dangerous!"; - print " -usage: /etc/oem -f [options] -where [options] are: - server : allow server installalation - boot_entries=entry1,...,entryN : set boot entries to use, - the first one is the default one - no<option> : disable options <option> -"; - exit 1; -} -my (%options, $yes, $hd, $hdp, $cd, $fs); - -#- avoid globing as it is not available in rescue ramdisk. -foreach my $device (split ' ', `/bin/ls -d /proc/ide/hd*`) { - open F, "$device/media" or next; - foreach (<F>) { - /disk/ and do { $hd ||= $device; $hd =~ s,/proc/ide/,,; }; - /cdrom/ and do { $cd ||= $device; $cd =~ s,/proc/ide/,,; }; - } - close F; -} -#- examine available SCSI devices (avoid SCSI floppies like LS-120 or ZIP disk or generic floppies). -eval { - system "/usr/bin/drvinst"; #- load scsi drivers else it wont do anything. - - my ($driveNum, $cdromNum) = (0, 0); - open F, "/proc/scsi/scsi" or die "no scsi available"; - local $_ = <F>; /^Attached devices:/ or die "to attached devices found"; - while ($_ = <F>) { - my ($id) = /^Host:.*?Id: (\d+)/ or die "no host found"; - $_ = <F>; my ($vendor, $model) = /^\s*Vendor:\s*(.*?)\s+Model:\s*(.*?)\s+Rev:/ or die "no vendor nor model found"; - $_ = <F>; my ($type) = /^\s*Type:\s*(.*)/; - if ($type =~ /Direct-Access/ && $model !~ /ZIP\s+\d+|LS-?120|144MB|[Ff]loppy/) { - $hd ||= "sd" . chr($driveNum++ + ord('a')); - } elsif ($type =~ /CD-ROM/) { - $cd ||= "scd" . $cdromNum++; - } - } - close F; -}; -#- examine DAC960 device. -#- there is a problem as there is no more than 7 partitions available, this means no /home and no /var. -unless ($hd) { - local $_; - open F, "dmesg |"; - while (<F>) { - m|/dev/(rd/.*?): .*?,| and $hd ||= $1, last; - } - close F; - if ($hd) { - my ($c_id, $d_id) = $hd =~ m|rd/c(\d+)d(\d+)|; - -d "/dev/rd" or mkdir "/dev/rd"; - system "mknod", "/dev/$hd", "b", 48+$c_id, 8*$d_id; - foreach (1..7) { - system "mknod", "/dev/${hd}p$_", "b", 48+$c_id, 8*$d_id+$_; - } - $hdp = $hd . 'p'; - } -} -#- examine Compaq Smart Array device. -unless ($hd) { - foreach ('array/ida', 'cpqarray/ida', 'cciss/cciss') { - my $prefix = "/proc/driver/$_"; #- kernel 2.4 places it here - $prefix = "/proc/$_" if !-e "${prefix}0"; #- kernel 2.2 - - my ($name) = m|/(.*)|; - for (my $i = 0; -r ($f = "${prefix}$i"); $i++) { - local $_; - open F, $f; - while (<F>) { - if (m|^\s*($name/.*?):|) { - $hd ||= $1; - } - } - close F; - } - } - if ($hd) { - my ($type, $c_id, $d_id) = $hd =~ m,(ida|cciss)/c(\d+)d(\d+),; - -d "/dev/$type" or mkdir "/dev/$type"; - system "mknod", "/dev/$hd", "b", ($type eq 'ida' ? 72 : 104)+$c_id, 16*$d_id; - foreach (1..15) { - system "mknod", "/dev/${hd}p$_", "b", ($type eq 'ida' ? 72 : 104)+$c_id, 16*$d_id+$_; - } - $hdp = $hd . 'p'; - } -} -$hd && -e "/dev/$hd" or die "unable to access hard disk"; -print "hd: $hd\ncd: $cd\n"; -$hdp ||= $hd; - -#- try to free any reference to hard disk which will be used (as in rescue mode it has already loaded -#- existing partition in /mnt. -open F, "/proc/mounts"; -while (<F>) { - /$hdp(\d*)\s+(\S+)/ and $already_mounted{$2} = "$hdp$1"; -} -foreach (sort { $b cmp $a } keys %already_mounted) { - print "umounting $already_mounted{$_} from $_\n"; - system "umount", $_; -} - -#- find a cdrom (like) image, normally a true cdrom but if nfs install is running, use it instead. -mkdir "/cdrom"; -open F, "/proc/cmdline"; -while (<F>) { - /automatic=method:nfs,.*server:([^\s,]*),.*directory:([^\s,]*)/ - and system "mount", "-r", "-t", "nfs", "$1:$2", "/cdrom", "-o", "nolock"; -} -close F; -unless (-e "/cdrom/VERSION") { - -e "/dev/$cd" or die "unable to access local cdrom"; - system "mount", "-r", "-t", "iso9660", "/dev/$cd", "/cdrom"; -} - -#- using default options for HP. -#$options{free_size} = 500; -#$options{free_primary} = 1; -#$options{free_fs} = 'fat32'; -#$options{boot_entries} = 'linux,linux-nonfb,restore,failsafe,floppy'; -#$options{kernel} = "acpi=off"; - -open F, "/cdrom/VERSION" or die "no installation cdrom found on $cd"; -while (<F>) { - /\[boot_entries[=:]([^]]*)\]/ and $options{boot_entries} = $1; - /\[ext2\]/ and $options{fs} = "ext2"; - /\[ext3\]/ and $options{fs} = "ext3"; -} -close F; -foreach (@ARGV) { /^([^=:]*)[=:]?(.*)/ and $options{$1} = $2; /^no([^=:]*)/ and delete $options{$1} } - -foreach (keys %options) { - print "Using option [$_" . ($options{$_} && "=$options{$_}") . "]\n"; -} - -#- filesystem to use. -$fs ||= $options{fs} || "ext3"; -$fs eq "ext3" and system "modprobe", "ext3"; -print "Using filesystem of type $fs\n"; - -#- check for already existing partition table, if none are found -#- create 3 partitions (one for install, one for swap and one for root). -#- if only a fat partition is found, resize it do include the above partition. -#- other combination are really dangerous and are not supported, ask -#- the user that all data on the disk will be erased and go on. -my ($heads, $sectors, $cylinders, $hd_size, @hd_parts); -sub correct_start_end { - my ($rstart, $end, $keep_start) = @_; - my ($cylinder_size, $c_start, $c_end) = ($sectors*$heads*512/1024/1024, undef, undef); - if (abs($cylinder_size*$cylinders-$hd_size)/$hd_size < 0.01) { - $c_start = $$rstart+($keep_start ? 0 : $cylinder_size/$heads); - $c_end = $cylinder_size*int(1/2+$end/$cylinder_size); - $c_end > $hd_size and $c_end = $hd_size; - $$rstart = $c_end; - } else { - $c_start = $$rstart; - $c_end = $end; - $c_end > $hd_size and $c_end = $hd_size; - $$rstart = $c_end+5; #- fall back to use a problable safe method. - } - $c_start >= $c_end and die "no space left for partitionning\n"; - ($c_start, $c_end); -} -open F, "fdisk -l /dev/$hd |"; -while (<F>) { - /(\d+)\s*heads/ and $heads = $1; - /(\d+)\s*sectors/ and $sectors = $1; - /(\d+)\s*cylinders/ and $cylinders = $1; -} -if ($heads == 1 && $cylinders == 1) { - $cylinders = $sectors / 255 / 63; - $heads = 255; - $sectors = 63; -} -close F; -for (1..2) { - open F, "parted /dev/$hd -s print |"; - while (<F>) { - /^Disk geometry [^:]*:\s*([\d\.]+)-([\d\.]+)/ and do { $hd_size = $2 - $1 - 1 }; - #/^Disk label type:\s*msdos/ and do { $hd_type = 'msdos' }; - /^(\d+)\s+([\d\.]+)\s+([\d\.]+)\s+(primary|logical|extended)\s*(\S*)/ and do { - #- this automatically drops extended partition here! - push @hd_parts, { minor => $1, start => $2, end => $3, type => $4, fstype => $5 }; - }; - } - close F; - $hd_size and last; - print "Unable to detect partition on disk, trying with new label\n"; - do { - print " - -I'm going to install the OEM version on your hard drive -[1;31;40m!!ALL DATA WILL BE LOST!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - system "parted", "/dev/$hd", "mklabel", "msdos"; -} -my $min_size = $options{min_size} || 9000; -my $def_size = $options{def_size} || 8500; -my $trigger_size = $options{trigger_size} || 9000; -#my $inst_size = $options{inst_size} || 1500; -my $inst_size = $options{inst_size} || 5000; -my $swap_size = $options{swap_size} || 128; -$hd_size > $min_size or die "hard disk is too small to contain oem install (${hd_size}MB found, need $min_size at least)"; - -my ($fat_pos, $resize_fat_size, $root_size); -if (@hd_parts == 1 && $hd_parts[$fat_pos = 0]{fstype} eq 'FAT' || - @hd_parts == 2 && $hd_parts[0]{type} eq 'primary' && $hd_parts[$fat_pos = 1]{fstype} eq 'FAT' || - @hd_parts == 3 && $hd_parts[0]{type} eq 'primary' && $hd_parts[1]{type} eq 'primary' && $hd_parts[$fat_pos = 2]{fstype} eq 'FAT' || - @hd_parts == 2 && $hd_parts[0]{type} eq 'extended' && $hd_parts[$fat_pos = 1]{fstype} eq 'FAT' || - @hd_parts == 3 && $hd_parts[0]{type} eq 'extended' && $hd_parts[1]{type} eq 'primary' && $hd_parts[$fat_pos = 5]{fstype} eq 'FAT') { - if ($hd_size - $hd_parts[$fat_pos]{end} > $min_size + $options{free_size}) { - #- check first if there are some available space left on the disk. - #- so we are using it, root_size is fixed to match hard disk size. - $resize_fat_size = 0; - $root_size = $hd_size - $hd_parts[$fat_pos]{end} - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; - } elsif ($hd_size > 2*$min_size + $options{free_size}) { - #- resize this fat partition. - $resize_fat_size = 0.5 * $hd_size; - $root_size = $hd_size - $resize_fat_size - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; - } -} -unless ($root_size) { - #- there have not been defined above, so remove everything and start from - #- a blank partition. - $resize_fat_size = undef; - $root_size = $hd_size - $resize_fat_size - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; -} - -#- launch parted to edit partition table, start at minor. -#- point define where we start. -my $minor = defined $resize_fat_size && $hd_parts[0]{type} eq 'extended' ? 6 : 5; -my $point = 0.0; -my @commands; - -if (defined $resize_fat_size) { - do { - print " - -[1;31;40m!!An existing Windows partition has been found and will be kept. -Additional Linux partitions will be created!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - #- keep the current partition table, and try to resize the fat partition - #- if the size is not 0. - #- KEEP IN MIND there is only one partition defined. - if ($resize_fat_size) { - $point = $hd_parts[$fat_pos]{start}; - push @commands, sprintf "resize %d %s %s", $hd_parts[$fat_pos]{minor}, correct_start_end(\$point, $point+$resize_fat_size, 'keepstart'); - } else { - $point = $hd_parts[$fat_pos]{end}; - } - $point+=9; #- keep blank space between partitions if parted cannot handle partition table correctly. -} else { - unless (defined $yes) { - do { - print " - -I'm going to install the OEM version on your hard drive -[1;31;40m!!ALL DATA WILL BE LOST!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - } - #- build a new disk label here. - push @commands, "mklabel msdos"; -} - -#- at this point, the partition are created. -my ($instz, $inst, $swap, $root, $var, $home, $free) = ($minor-1, $minor, $minor+1, $minor+2, undef, undef, undef); - -#- all linux partition are stored inside an extended partition, this is easier to manipulate after. -my $free_point = $point; -if ($minor == 5) { - push @commands, sprintf "mkpart extended %s %s", correct_start_end(\$free_point, $hd_size - ($options{free_primary} && $options{free_size}), - 'keepstart'); -} else { - $hd_parts[0]{type} eq 'extended' or die "first partition assumed to be extended"; - $point = $hd_parts[0]{start}; - push @commands, sprintf "resize %s %s %s", $hd_parts[0]{minor}, correct_start_end(\$free_point, - $hd_size - ($options{free_primary} && $options{free_size}), - 'keepstart'); -} -push @commands, sprintf "mkpart logical ext2 %s %s", correct_start_end(\$point, $point+$inst_size); -push @commands, sprintf "mkpart logical linux-swap %s %s", correct_start_end(\$point, $point+$swap_size); -push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $point+$root_size); -if (exists $options{server} && $hd !~ /^rd\//) { - my $var_size = ($hd_size - $point) / 2; - if ($var_size > 1500) { - $var = $root+1; - push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $point+$var_size); - } -} -if ($hd_size - $point - $options{free_size} > 100 && $hd !~ /^rd\//) { - $home = ($var || $root) + 1; - push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $hd_size-$options{free_size}); -} -if ($options{free_size} && $options{free_fs}) { - if ($options{free_primary}) { - $free = scalar(grep { $_->{type} eq 'primary' } @hd_parts) + 2; - if ($free > 4) { - $free = ($home || $var || $root) + 1; - delete $options{free_primary}; - print "Unable to use primary partition for free partition, using logical partition.\n"; - } - } else { - $free = ($home || $var || $root) + 1; - } - push @commands, sprintf "mkpart %s %s %s %s", $options{free_primary} ? 'primary' : 'logical', $options{free_fs}, correct_start_end($options{free_primary} ? \$free_point : \$point, $hd_size); -} -system("parted", "-s", "/dev/$hd", @commands) == 0 or die "unable to partition the disk $hd"; - -#- try to help user if a free space has been set and no fs defined for it. -if ($options{free_size} && !$options{free_fs}) { - print " - -[1;31;40m!!A free space has been configured, now you can use parted -to defined the partition as you want.[0m - -Type \`\`quit'' and [enter] to finish parted\n"; - system "parted", "-i", "/dev/$hd"; -} - -#- we have to build swap and mount it. -print "Setting swap\n"; -system "mkswap", "/dev/$hdp$swap"; -system "swapon", "/dev/$hdp$swap"; - -#- we have to format using right fs. -print "Formatting /dev/$hdp$inst partition\n"; -mkfs("ext2", "/dev/$hdp$inst"); -print "Formatting /dev/$hdp$root partition\n"; -mkfs($fs, "/dev/$hdp$root"); -if ($var) { - print "Formatting /dev/$hdp$var partition\n"; - mkfs($fs, "/dev/$hdp$var"); -} -if ($home) { - print "Formatting /dev/$hdp$home partition\n"; - mkfs($fs, "/dev/$hdp$home"); -} -if ($free) { - print "Formatting /dev/$hdp$free partition\n"; - mkfs($options{free_fs}, "/dev/$hdp$free"); -} - -print "Mounting partitions\n"; -mkdir "/hd"; -system "mount", "-t", "ext2", "/dev/$hdp$inst", "/hd"; -mkdir "/mnt"; -system "mount", "-t", $fs, "/dev/$hdp$root", "/mnt"; -if ($var) { - mkdir "/mnt/var"; - system "mount", "-t", $fs, "/dev/$hdp$var", "/mnt/var"; -} -if ($home) { - mkdir "/mnt/home"; - system "mount", "-t", $fs, "/dev/$hdp$home", "/mnt/home"; -} - -print "Copying installation on hard drive\n"; -mkdir "/hd/boot"; -if (-e "/cdrom/oem/vmlinuz" && -e "/cdrom/oem/all.rdz") { - system "cp", "-a", "/cdrom/oem/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/oem/all.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/isolinux/alt0/vmlinuz" && -e "/cdrom/isolinux/alt0/all.rdz") { - system "cp", "-a", "/cdrom/isolinux/alt0/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/isolinux/alt0/all.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/boot/vmlinuz" && -e "/cdrom/boot/hd.rdz") { - system "cp", "-a", "/cdrom/boot/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/boot/hd.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/images/hd.img") { - mkdir "/tmp/hd"; - system "modprobe", "loop"; - system "modprobe", "vfat"; - system "mount", "-t", "vfat", "/cdrom/images/hd.img", "/tmp/hd", "-o", "loop"; - system "cp", "-a", "/tmp/hd/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/tmp/hd/hd.rdz", "/hd/boot/all.rdz"; - system "umount", "/tmp/hd"; -} else { - die "no installation stage1 found"; -} - -mkdir "/hd/Mandrake"; -mkdir "/hd/Mandrake/RPMS"; -system "cp", "-a", "/cdrom/VERSION", "/hd"; -system "cp", "-a", "/cdrom/Mandrake/base", "/cdrom/Mandrake/mdkinst", "/cdrom/Mandrake/share", "/hd/Mandrake"; - -if (open F, ">/hd/Mandrake/oem_patch.pl") { - print "Setting OEM specific extension to DrakX\n"; - if (exists $options{server}) { - print F q{ - use install_steps; - package install_steps; - undef *choosePackages; - *choosePackages = sub { - my ($o, $packages, $compssUsers, $first_time) = @_; - - #- make sure we kept some space left for available else the system may - #- not be able to start (xfs at least). - my $available = install_any::getAvailableSpace($o); - my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024); - - #- avoid destroying user selection of packages but only - #- for expert, as they may have done individual selection before. - install_any::unselectMostPackages($o); - - #- use specific OEM packages selection, go to level 5 - #- and disable some extension. - $o->{compssUsersChoice}{$_} = 0 foreach 'GNOME'; - $o->{compssUsersChoice}{$_} = 0 - foreach map { @{$o->{compssUsers}{$_}{flags}} } 'Workstation|Office Workstation', 'Workstation|Internet station'; - $o->{compssListLevel} = 5; - pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $o->{compssListLevel}, $availableCorrected); - - $availableCorrected; - }; - }; - } else { - print F q{ - use install_steps; - package install_steps; - undef *choosePackages; - *choosePackages = sub { - my ($o, $packages, $compssUsers, $first_time) = @_; - - #- make sure we kept some space left for available else the system may - #- not be able to start (xfs at least). - my $available = install_any::getAvailableSpace($o); - my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024); - - #- avoid destroying user selection of packages but only - #- for expert, as they may have done individual selection before. - install_any::unselectMostPackages($o); - - #- use specific OEM packages selection, go to level 4. - #- and select at least GAMES group, everything else has - #- already be selected during master preparation. - $o->{compssListLevel} = 4; - $o->{compssUsersChoice}{$_} = 1 foreach qw(GAMES VIDEO AUDIO GRAPHICS); - pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $o->{compssListLevel}, $availableCorrected); - - $availableCorrected; - }; - }; - } - if ($options{boot_entries}) { - print "Setting OEM specific extension for boot entries\n"; - print F q{ - my $sorted_entries = q(} . $options{boot_entries} . q{); #- insert boot_entries options here as string q(...). - my $old_setupBootloaderBefore = \&setupBootloaderBefore; - undef *setupBootloaderBefore; - *setupBootloaderBefore = sub { - $old_setupBootloaderBefore->(@_); - my @entries = split ',', $sorted_entries; - my @result_entries; - foreach my $p (@entries) { - foreach (@{$_[0]{bootloader}{entries}}) { - $_->{label} eq $p and push @result_entries, $_; - } - } - if (@result_entries) { - $_[0]{bootloader}{entries} = \@result_entries; - $_[0]{bootloader}{default} = $result_entries[0]{label}; #- first image is default. - } - }; - }; - } - close F; -} - -print "Setting bootloader\n"; -mkdir "/hd/boot/grub"; -foreach (1..2) { - -e "/hd/boot/grub/stage$_" or system "cp", "-a", "/boot/grub/stage$_", "/hd/boot/grub"; -} -open F, ">/hd/boot/grub/menu.lst"; -if (defined $resize_fat_size) { - print F "timeout 5\n"; - print F "color black/cyan yellow/cyan\n\n"; - print F "title linux\n"; -} else { - print F "timeout 0\n\n"; - print F "title oem\n"; -} -print F "kernel (hd0,$instz)/boot/vmlinuz ramdisk_size=128000 $options{kernel} automatic=method:disk,disk:$hd,partition:$hdp$inst,directory:/ hd vga=788 fbeginner oem defcfg=/tmp/hdimage/Mandrake/oem_patch.pl\n"; -print F "initrd (hd0,$instz)/boot/all.rdz\n"; -#- if a windows partition is available, add an entrie for it. -if (defined $resize_fat_size) { - print F "\ntitle windows\n"; - printf F "rootnoverify (hd0,%s)\n", $hd_parts[$fat_pos]{minor}-1; - print F "makeactive\n"; - print F "chainloader +1\n"; -} -close F; -open F, ">/hd/boot/grub/device.map"; -print F "(hd0) /dev/$hd\n"; -close F; -open F, "| grub --device-map=/hd/boot/grub/device.map --batch"; -print F "install (hd0,$instz)/boot/grub/stage1 d (hd0) (hd0,$instz)/boot/grub/stage2 p (hd0,$instz)/boot/grub/menu.lst\n"; -print F "quit\n"; -close F or die "error while executing grub"; - -my $packages = read_depslist("/cdrom/Mandrake/base/depslist.ordered"); - -my @media; -open F, "/cdrom/Mandrake/base/hdlists"; -foreach (<F>) { - chomp; - s/\s*#.*$//; - /^\s*$/ and next; - m/^\s*(hdlist\S*\.cz2?)\s+(\S+)\s*(.*)$/ or die "invalid hdlist description \"$_\" in hdlists file"; - - push @media, { hdlist => $1, rpmsdir => $2, descr => $3 }; -} -close F; - -#- initialize installation. -foreach (qw(/etc /etc/sysconfig /etc/rpm /var /var/lib /var/lib/rpm /var/log /proc)) { - mkdir "/mnt/$_"; -} -system "mount", "-t", "proc", "proc", "/mnt/proc"; -open F, ">/mnt/etc/fstab"; -print F "/dev/$hdp$root / $fs defaults 1 1\n"; -if ($var) { - print F "/dev/$hdp$var /var $fs defaults 1 2\n"; -} -if ($home) { - print F "/dev/$hdp$home /home $fs defaults 1 2\n"; -} -close F; -#- stupid things for installer to work correctly. -#open F, ">/mnt/etc/mandrake-release"; -#print F "Mandrake Linux release 9.1 (Bamboo) for i586"; -#close F; - -#- keep in mind all the rpm files available (according to hdlists). -my (%files, %rpms); - -require packdrake; -foreach my $medium (@media) { - my $packer = new packdrake("/cdrom/Mandrake/base/$medium->{hdlist}"); - foreach (@{$packer->{files}}) { - $packer->{data}{$_}[0] eq 'f' or next; - my ($fullname, $file) = /([^:]*):(.*)/ ? ($1, "$2.rpm") : ($_, "$_.rpm"); - $files{$fullname} = $file; - $rpms{$file} = $medium->{rpmsdir}; - } -} - -#- install some important packages. -system "rpm", "--root", "/mnt", "--initdb"; - -#- copy and install from each cd image. -foreach my $medium (@media) { - while ($cd && ! -d "/cdrom/$medium->{rpmsdir}") { - system "unmount", "/dev/$cd"; - system "eject", "/dev/$cd"; - print "Please insert the cdrom labeled \"$medium->{descr}\"\n and press [enter] when done\n"; - $yes = <STDIN>; - system "mount", "-r", "-t", "iso9660", "/dev/$cd", "/cdrom"; - } - - print "Copying packages from medium labeled \"$medium->{descr}\" to hard disk\n"; - system "mkdir", "-p", "/hd/$medium->{rpmsdir}"; - foreach my $pkg (@{$packages->{depslist}}) { - $files{rpm_fullname($pkg)} or next; - my $file = "/cdrom/$medium->{rpmsdir}/" . $files{rpm_fullname($pkg)}; - if (-e $file) { - print " copying " . rpm_fullname($pkg) . "\n"; - system "cp", "-a", $file, "/hd/$medium->{rpmsdir}"; - if (rpm_fullname($pkg) =~ /mandrake-release/) { - system "rpm", "-Uvh", "--root", "/mnt", "--nodeps", "--force", "/hd/$medium->{rpmsdir}/" . $files{rpm_fullname($pkg)}; - } - } - } -} - -#- try to figure out if a oem-message-graphic already exists. -#- if this is the case, rename it to /mnt/boot/message-graphic -if (-e "/cdrom/Mandrake/base/oem-message-graphic") { - print "Using specific oem graphic image\n"; - if (-e "/mnt/boot/message-graphic") { - rename "/mnt/boot/message-graphic", "/mnt/boot/message-graphic.old"; - system "cp", "-a", "/cdrom/Mandrake/base/oem-message-graphic", "/mnt/boot/message-graphic"; - } elsif (-e "/mnt/boot/lilo-graphic/message") { - rename "/mnt/boot/lilo-graphic/message", "/mnt/boot/lilo-graphic/message.old"; - system "cp", "-a", "/cdrom/Mandrake/base/oem-message-graphic", "/mnt/boot/lilo-graphic/message"; - } -} - -#- clean all initrd image which may have been built. -system "rm -f /mnt/boot/initrd*"; - -system "umount", "/mnt/proc"; -$home and system "umount", "/mnt/home"; -$var and system "umount", "/mnt/var"; -system "umount", "/mnt"; -system "umount", "/hd"; -system "umount", "/cdrom"; - -$cd and system "eject", "/dev/$cd"; - -print " -Done. OEM hard drive ready! -The hard drive is now ready for a customer. -System is now halted.\n\n"; - -system "halt"; - -#- gives way to format partition (simpler approach) -sub mkfs { - my ($fs, $dev) = @_; - for ($fs) { - /ext2/ and do { system "mkfs.ext2", $dev; - next }; - /ext3/ and do { system "mkfs.ext2", "-j", $dev; - system "tune2fs", "-c0", "-i0", $dev; - next }; - /fat16/ and do { system "mkdosfs", $dev; - next }; - /fat32/ and do { system "mkdosfs", "-F", "32", $dev; - next }; - die "unknown fs: $_\n"; - } -} - -sub chop_version { - ($_[0] =~ /^([^:\s]*)-[^:\-\s]+-[^:\-\s]+\.[^:\.\-\s]*(?::\S*)?/)[0] || die "unable to parse $_[0]"; -} -sub rpm_fullname { - ($_[0]{name} =~ /^([^:\s]*-[^:\-\s]+-[^:\-\s]+\.[^:\.\-\s]*)(?::\S*)?/)[0] || die "unable to parse $_[0]"; -} - -sub read_depslist { - my ($file) = @_; - my $packages = { depslist => [], names => {} }; - - #- read depslist.oredered file. - my $id = 0; - - open F, "$file" or die "unable to open ordered dependencies list file"; - while (<F>) { - my ($name, $size, @deps) = split; - push @{$packages->{depslist}}, { id => $id++, name => $name, size => $size, deps => \@deps }; - } - close F; - - foreach (@{$packages->{depslist}}) { - $packages->{names}{chop_version($_->{name})} = $_; - } - - print "read " . scalar(@{$packages->{depslist}}) . " package dependancies\n"; - $packages; -} - diff --git a/rescue/tree/etc/oem-all b/rescue/tree/etc/oem-all deleted file mode 100755 index 3c97ec134..000000000 --- a/rescue/tree/etc/oem-all +++ /dev/null @@ -1,665 +0,0 @@ -#!/usr/bin/perl - -if (shift(@ARGV) ne '-f') { - print "Call it with option -f, but don't fear loosing all your data, this command is dangerous!"; - print " -usage: /etc/oem -f [options] -where [options] are: - server : allow server installalation - boot_entries=entry1,...,entryN : set boot entries to use, - the first one is the default one - no<option> : disable options <option> -"; - exit 1; -} -my (%options, $yes, $hd, $hdp, $cd, $fs); - -#- avoid globing as it is not available in rescue ramdisk. -foreach my $device (split ' ', `/bin/ls -d /proc/ide/hd*`) { - open F, "$device/media" or next; - foreach (<F>) { - /disk/ and do { $hd ||= $device; $hd =~ s,/proc/ide/,,; }; - /cdrom/ and do { $cd ||= $device; $cd =~ s,/proc/ide/,,; }; - } - close F; -} -#- examine available SCSI devices (avoid SCSI floppies like LS-120 or ZIP disk or generic floppies). -eval { - system "/usr/bin/drvinst"; #- load scsi drivers else it wont do anything. - - my ($driveNum, $cdromNum) = (0, 0); - open F, "/proc/scsi/scsi" or die "no scsi available"; - local $_ = <F>; /^Attached devices:/ or die "to attached devices found"; - while ($_ = <F>) { - my ($id) = /^Host:.*?Id: (\d+)/ or die "no host found"; - $_ = <F>; my ($vendor, $model) = /^\s*Vendor:\s*(.*?)\s+Model:\s*(.*?)\s+Rev:/ or die "no vendor nor model found"; - $_ = <F>; my ($type) = /^\s*Type:\s*(.*)/; - if ($type =~ /Direct-Access/ && $model !~ /ZIP\s+\d+|LS-?120|144MB|[Ff]loppy/) { - $hd ||= "sd" . chr($driveNum++ + ord('a')); - } elsif ($type =~ /CD-ROM/) { - $cd ||= "scd" . $cdromNum++; - } - } - close F; -}; -#- examine DAC960 device. -#- there is a problem as there is no more than 7 partitions available, this means no /home and no /var. -unless ($hd) { - local $_; - open F, "dmesg |"; - while (<F>) { - m|/dev/(rd/.*?): .*?,| and $hd ||= $1, last; - } - close F; - if ($hd) { - my ($c_id, $d_id) = $hd =~ m|rd/c(\d+)d(\d+)|; - -d "/dev/rd" or mkdir "/dev/rd"; - system "mknod", "/dev/$hd", "b", 48+$c_id, 8*$d_id; - foreach (1..7) { - system "mknod", "/dev/${hd}p$_", "b", 48+$c_id, 8*$d_id+$_; - } - $hdp = $hd . 'p'; - } -} -#- examine Compaq Smart Array device. -unless ($hd) { - foreach ('array/ida', 'cpqarray/ida', 'cciss/cciss') { - my $prefix = "/proc/driver/$_"; #- kernel 2.4 places it here - $prefix = "/proc/$_" if !-e "${prefix}0"; #- kernel 2.2 - - my ($name) = m|/(.*)|; - for (my $i = 0; -r ($f = "${prefix}$i"); $i++) { - local $_; - open F, $f; - while (<F>) { - if (m|^\s*($name/.*?):|) { - $hd ||= $1; - } - } - close F; - } - } - if ($hd) { - my ($type, $c_id, $d_id) = $hd =~ m,(ida|cciss)/c(\d+)d(\d+),; - -d "/dev/$type" or mkdir "/dev/$type"; - system "mknod", "/dev/$hd", "b", ($type eq 'ida' ? 72 : 104)+$c_id, 16*$d_id; - foreach (1..15) { - system "mknod", "/dev/${hd}p$_", "b", ($type eq 'ida' ? 72 : 104)+$c_id, 16*$d_id+$_; - } - $hdp = $hd . 'p'; - } -} -$hd && -e "/dev/$hd" or die "unable to access hard disk"; -print "hd: $hd\ncd: $cd\n"; -$hdp ||= $hd; - -#- try to free any reference to hard disk which will be used (as in rescue mode it has already loaded -#- existing partition in /mnt. -open F, "/proc/mounts"; -while (<F>) { - /$hdp(\d*)\s+(\S+)/ and $already_mounted{$2} = "$hdp$1"; -} -foreach (sort { $b cmp $a } keys %already_mounted) { - print "umounting $already_mounted{$_} from $_\n"; - system "umount", $_; -} - -#- find a cdrom (like) image, normally a true cdrom but if nfs install is running, use it instead. -mkdir "/cdrom"; -open F, "/proc/cmdline"; -while (<F>) { - /automatic=method:nfs,.*server:([^\s,]*),.*directory:([^\s,]*)/ - and system "mount", "-r", "-t", "nfs", "$1:$2", "/cdrom", "-o", "nolock"; -} -close F; -unless (-e "/cdrom/VERSION") { - -e "/dev/$cd" or die "unable to access local cdrom"; - system "mount", "-r", "-t", "iso9660", "/dev/$cd", "/cdrom"; -} - -#- using default options for HP. -#$options{free_size} = 500; -#$options{free_primary} = 1; -#$options{free_fs} = 'fat32'; -#$options{boot_entries} = 'linux,linux-nonfb,restore,failsafe,floppy'; -#$options{kernel} = "acpi=off"; - -open F, "/cdrom/VERSION" or die "no installation cdrom found on $cd"; -while (<F>) { - /\[boot_entries[=:]([^]]*)\]/ and $options{boot_entries} = $1; - /\[ext2\]/ and $options{fs} = "ext2"; - /\[ext3\]/ and $options{fs} = "ext3"; -} -close F; -foreach (@ARGV) { /^([^=:]*)[=:]?(.*)/ and $options{$1} = $2; /^no([^=:]*)/ and delete $options{$1} } - -foreach (keys %options) { - print "Using option [$_" . ($options{$_} && "=$options{$_}") . "]\n"; -} - -#- filesystem to use. -$fs ||= $options{fs} || "ext3"; -$fs eq "ext3" and system "modprobe", "ext3"; -print "Using filesystem of type $fs\n"; - -#- check for already existing partition table, if none are found -#- create 3 partitions (one for install, one for swap and one for root). -#- if only a fat partition is found, resize it do include the above partition. -#- other combination are really dangerous and are not supported, ask -#- the user that all data on the disk will be erased and go on. -my ($heads, $sectors, $cylinders, $hd_size, @hd_parts); -sub correct_start_end { - my ($rstart, $end, $keep_start) = @_; - my ($cylinder_size, $c_start, $c_end) = ($sectors*$heads*512/1024/1024, undef, undef); - if (abs($cylinder_size*$cylinders-$hd_size)/$hd_size < 0.01) { - $c_start = $$rstart+($keep_start ? 0 : $cylinder_size/$heads); - $c_end = $cylinder_size*int(1/2+$end/$cylinder_size); - $c_end > $hd_size and $c_end = $hd_size; - $$rstart = $c_end; - } else { - $c_start = $$rstart; - $c_end = $end; - $c_end > $hd_size and $c_end = $hd_size; - $$rstart = $c_end+5; #- fall back to use a problable safe method. - } - $c_start >= $c_end and die "no space left for partitionning\n"; - ($c_start, $c_end); -} -open F, "fdisk -l /dev/$hd |"; -while (<F>) { - /(\d+)\s*heads/ and $heads = $1; - /(\d+)\s*sectors/ and $sectors = $1; - /(\d+)\s*cylinders/ and $cylinders = $1; -} -if ($heads == 1 && $cylinders == 1) { - $cylinders = $sectors / 255 / 63; - $heads = 255; - $sectors = 63; -} -close F; -for (1..2) { - open F, "parted /dev/$hd -s print |"; - while (<F>) { - /^Disk geometry [^:]*:\s*([\d\.]+)-([\d\.]+)/ and do { $hd_size = $2 - $1 - 1 }; - #/^Disk label type:\s*msdos/ and do { $hd_type = 'msdos' }; - /^(\d+)\s+([\d\.]+)\s+([\d\.]+)\s+(primary|logical|extended)\s*(\S*)/ and do { - #- this automatically drops extended partition here! - push @hd_parts, { minor => $1, start => $2, end => $3, type => $4, fstype => $5 }; - }; - } - close F; - $hd_size and last; - print "Unable to detect partition on disk, trying with new label\n"; - do { - print " - -I'm going to install the OEM version on your hard drive -[1;31;40m!!ALL DATA WILL BE LOST!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - system "parted", "/dev/$hd", "mklabel", "msdos"; -} -my $min_size = $options{min_size} || 9000; -my $def_size = $options{def_size} || 8500; -my $trigger_size = $options{trigger_size} || 9000; -#my $inst_size = $options{inst_size} || 1500; -my $inst_size = $options{inst_size} || 5000; -my $swap_size = $options{swap_size} || 128; -$hd_size > $min_size or die "hard disk is too small to contain oem install (${hd_size}MB found, need $min_size at least)"; - -my ($fat_pos, $resize_fat_size, $root_size); -if (@hd_parts == 1 && $hd_parts[$fat_pos = 0]{fstype} eq 'FAT' || - @hd_parts == 2 && $hd_parts[0]{type} eq 'primary' && $hd_parts[$fat_pos = 1]{fstype} eq 'FAT' || - @hd_parts == 3 && $hd_parts[0]{type} eq 'primary' && $hd_parts[1]{type} eq 'primary' && $hd_parts[$fat_pos = 2]{fstype} eq 'FAT' || - @hd_parts == 2 && $hd_parts[0]{type} eq 'extended' && $hd_parts[$fat_pos = 1]{fstype} eq 'FAT' || - @hd_parts == 3 && $hd_parts[0]{type} eq 'extended' && $hd_parts[1]{type} eq 'primary' && $hd_parts[$fat_pos = 5]{fstype} eq 'FAT') { - if ($hd_size - $hd_parts[$fat_pos]{end} > $min_size + $options{free_size}) { - #- check first if there are some available space left on the disk. - #- so we are using it, root_size is fixed to match hard disk size. - $resize_fat_size = 0; - $root_size = $hd_size - $hd_parts[$fat_pos]{end} - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; - } elsif ($hd_size > 2*$min_size + $options{free_size}) { - #- resize this fat partition. - $resize_fat_size = 0.5 * $hd_size; - $root_size = $hd_size - $resize_fat_size - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; - } -} -unless ($root_size) { - #- there have not been defined above, so remove everything and start from - #- a blank partition. - $resize_fat_size = undef; - $root_size = $hd_size - $resize_fat_size - $options{free_size} - $inst_size - $swap_size; - $root_size > $trigger_size and $root_size = $def_size; -} - -#- launch parted to edit partition table, start at minor. -#- point define where we start. -my $minor = defined $resize_fat_size && $hd_parts[0]{type} eq 'extended' ? 6 : 5; -my $point = 0.0; -my @commands; - -if (defined $resize_fat_size) { - do { - print " - -[1;31;40m!!An existing Windows partition has been found and will be kept. -Additional Linux partitions will be created!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - #- keep the current partition table, and try to resize the fat partition - #- if the size is not 0. - #- KEEP IN MIND there is only one partition defined. - if ($resize_fat_size) { - $point = $hd_parts[$fat_pos]{start}; - push @commands, sprintf "resize %d %s %s", $hd_parts[$fat_pos]{minor}, correct_start_end(\$point, $point+$resize_fat_size, 'keepstart'); - } else { - $point = $hd_parts[$fat_pos]{end}; - } - $point+=9; #- keep blank space between partitions if parted cannot handle partition table correctly. -} else { - unless (defined $yes) { - do { - print " - -I'm going to install the OEM version on your hard drive -[1;31;40m!!ALL DATA WILL BE LOST!![0m - -Type \`\`yes'' and [enter] to go on\n" - } while (($yes = <STDIN>) !~ /^\s*yes\s*$/i); - } - #- build a new disk label here. - push @commands, "mklabel msdos"; -} - -#- at this point, the partition are created. -my ($instz, $inst, $swap, $root, $var, $home, $free) = ($minor-1, $minor, $minor+1, $minor+2, undef, undef, undef); - -#- all linux partition are stored inside an extended partition, this is easier to manipulate after. -my $free_point = $point; -if ($minor == 5) { - push @commands, sprintf "mkpart extended %s %s", correct_start_end(\$free_point, $hd_size - ($options{free_primary} && $options{free_size}), - 'keepstart'); -} else { - $hd_parts[0]{type} eq 'extended' or die "first partition assumed to be extended"; - $point = $hd_parts[0]{start}; - push @commands, sprintf "resize %s %s %s", $hd_parts[0]{minor}, correct_start_end(\$free_point, - $hd_size - ($options{free_primary} && $options{free_size}), - 'keepstart'); -} -push @commands, sprintf "mkpart logical ext2 %s %s", correct_start_end(\$point, $point+$inst_size); -push @commands, sprintf "mkpart logical linux-swap %s %s", correct_start_end(\$point, $point+$swap_size); -push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $point+$root_size); -if (exists $options{server} && $hd !~ /^rd\//) { - my $var_size = ($hd_size - $point) / 2; - if ($var_size > 1500) { - $var = $root+1; - push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $point+$var_size); - } -} -if ($hd_size - $point - $options{free_size} > 100 && $hd !~ /^rd\//) { - $home = ($var || $root) + 1; - push @commands, sprintf "mkpart logical %s %s %s", $fs, correct_start_end(\$point, $hd_size-$options{free_size}); -} -if ($options{free_size} && $options{free_fs}) { - if ($options{free_primary}) { - $free = scalar(grep { $_->{type} eq 'primary' } @hd_parts) + 2; - if ($free > 4) { - $free = ($home || $var || $root) + 1; - delete $options{free_primary}; - print "Unable to use primary partition for free partition, using logical partition.\n"; - } - } else { - $free = ($home || $var || $root) + 1; - } - push @commands, sprintf "mkpart %s %s %s %s", $options{free_primary} ? 'primary' : 'logical', $options{free_fs}, correct_start_end($options{free_primary} ? \$free_point : \$point, $hd_size); -} -system("parted", "-s", "/dev/$hd", @commands) == 0 or die "unable to partition the disk $hd"; - -#- try to help user if a free space has been set and no fs defined for it. -if ($options{free_size} && !$options{free_fs}) { - print " - -[1;31;40m!!A free space has been configured, now you can use parted -to defined the partition as you want.[0m - -Type \`\`quit'' and [enter] to finish parted\n"; - system "parted", "-i", "/dev/$hd"; -} - -#- we have to build swap and mount it. -print "Setting swap\n"; -system "mkswap", "/dev/$hdp$swap"; -system "swapon", "/dev/$hdp$swap"; - -#- we have to format using right fs. -print "Formatting /dev/$hdp$inst partition\n"; -mkfs("ext2", "/dev/$hdp$inst"); -print "Formatting /dev/$hdp$root partition\n"; -mkfs($fs, "/dev/$hdp$root"); -if ($var) { - print "Formatting /dev/$hdp$var partition\n"; - mkfs($fs, "/dev/$hdp$var"); -} -if ($home) { - print "Formatting /dev/$hdp$home partition\n"; - mkfs($fs, "/dev/$hdp$home"); -} -if ($free) { - print "Formatting /dev/$hdp$free partition\n"; - mkfs($options{free_fs}, "/dev/$hdp$free"); -} - -print "Mounting partitions\n"; -mkdir "/hd"; -system "mount", "-t", "ext2", "/dev/$hdp$inst", "/hd"; -mkdir "/mnt"; -system "mount", "-t", $fs, "/dev/$hdp$root", "/mnt"; -if ($var) { - mkdir "/mnt/var"; - system "mount", "-t", $fs, "/dev/$hdp$var", "/mnt/var"; -} -if ($home) { - mkdir "/mnt/home"; - system "mount", "-t", $fs, "/dev/$hdp$home", "/mnt/home"; -} - -print "Copying installation on hard drive\n"; -mkdir "/hd/boot"; -if (-e "/cdrom/oem/vmlinuz" && -e "/cdrom/oem/all.rdz") { - system "cp", "-a", "/cdrom/oem/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/oem/all.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/isolinux/alt0/vmlinuz" && -e "/cdrom/isolinux/alt0/all.rdz") { - system "cp", "-a", "/cdrom/isolinux/alt0/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/isolinux/alt0/all.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/boot/vmlinuz" && -e "/cdrom/boot/hd.rdz") { - system "cp", "-a", "/cdrom/boot/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/cdrom/boot/hd.rdz", "/hd/boot/all.rdz"; -} elsif (-e "/cdrom/images/hd.img") { - mkdir "/tmp/hd"; - system "modprobe", "loop"; - system "modprobe", "vfat"; - system "mount", "-t", "vfat", "/cdrom/images/hd.img", "/tmp/hd", "-o", "loop"; - system "cp", "-a", "/tmp/hd/vmlinuz", "/hd/boot/vmlinuz"; - system "cp", "-a", "/tmp/hd/hd.rdz", "/hd/boot/all.rdz"; - system "umount", "/tmp/hd"; -} else { - die "no installation stage1 found"; -} - -mkdir "/hd/Mandrake"; -mkdir "/hd/Mandrake/RPMS"; -system "cp", "-a", "/cdrom/VERSION", "/hd"; -system "cp", "-a", "/cdrom/Mandrake/base", "/cdrom/Mandrake/mdkinst", "/cdrom/Mandrake/share", "/hd/Mandrake"; - -if (open F, ">/hd/Mandrake/oem_patch.pl") { - print "Setting OEM specific extension to DrakX\n"; - if (exists $options{server}) { - print F q{ - use install_steps; - package install_steps; - undef *choosePackages; - *choosePackages = sub { - my ($o, $packages, $compssUsers, $first_time) = @_; - - #- make sure we kept some space left for available else the system may - #- not be able to start (xfs at least). - my $available = install_any::getAvailableSpace($o); - my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024); - - #- avoid destroying user selection of packages but only - #- for expert, as they may have done individual selection before. - install_any::unselectMostPackages($o); - - #- use specific OEM packages selection, go to level 5 - #- and disable some extension. - $o->{compssUsersChoice}{$_} = 0 foreach 'GNOME'; - $o->{compssUsersChoice}{$_} = 0 - foreach map { @{$o->{compssUsers}{$_}{flags}} } 'Workstation|Office Workstation', 'Workstation|Internet station'; - $o->{compssListLevel} = 5; - pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $o->{compssListLevel}, $availableCorrected); - - $availableCorrected; - }; - }; - } else { - print F q{ - use install_steps; - package install_steps; - undef *choosePackages; - *choosePackages = sub { - my ($o, $packages, $compssUsers, $first_time) = @_; - - #- make sure we kept some space left for available else the system may - #- not be able to start (xfs at least). - my $available = install_any::getAvailableSpace($o); - my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024); - - #- avoid destroying user selection of packages but only - #- for expert, as they may have done individual selection before. - install_any::unselectMostPackages($o); - - #- use specific OEM packages selection, go to level 4. - #- and select at least GAMES group, everything else has - #- already be selected during master preparation. - $o->{compssListLevel} = 4; - $o->{compssUsersChoice}{$_} = 1 foreach qw(GAMES VIDEO AUDIO GRAPHICS); - pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $o->{compssListLevel}, $availableCorrected); - - $availableCorrected; - }; - }; - } - if ($options{boot_entries}) { - print "Setting OEM specific extension for boot entries\n"; - print F q{ - my $sorted_entries = q(} . $options{boot_entries} . q{); #- insert boot_entries options here as string q(...). - my $old_setupBootloaderBefore = \&setupBootloaderBefore; - undef *setupBootloaderBefore; - *setupBootloaderBefore = sub { - $old_setupBootloaderBefore->(@_); - my @entries = split ',', $sorted_entries; - my @result_entries; - foreach my $p (@entries) { - foreach (@{$_[0]{bootloader}{entries}}) { - $_->{label} eq $p and push @result_entries, $_; - } - } - if (@result_entries) { - $_[0]{bootloader}{entries} = \@result_entries; - $_[0]{bootloader}{default} = $result_entries[0]{label}; #- first image is default. - } - }; - }; - } - close F; -} - -print "Setting bootloader\n"; -mkdir "/hd/boot/grub"; -foreach (1..2) { - -e "/hd/boot/grub/stage$_" or system "cp", "-a", "/boot/grub/stage$_", "/hd/boot/grub"; -} -open F, ">/hd/boot/grub/menu.lst"; -if (defined $resize_fat_size) { - print F "timeout 5\n"; - print F "color black/cyan yellow/cyan\n\n"; - print F "title linux\n"; -} else { - print F "timeout 0\n\n"; - print F "title oem\n"; -} -print F "kernel (hd0,$instz)/boot/vmlinuz ramdisk_size=128000 $options{kernel} automatic=method:disk,disk:$hd,partition:$hdp$inst,directory:/ hd vga=788 fbeginner oem defcfg=/tmp/hdimage/Mandrake/oem_patch.pl\n"; -print F "initrd (hd0,$instz)/boot/all.rdz\n"; -#- if a windows partition is available, add an entrie for it. -if (defined $resize_fat_size) { - print F "\ntitle windows\n"; - printf F "rootnoverify (hd0,%s)\n", $hd_parts[$fat_pos]{minor}-1; - print F "makeactive\n"; - print F "chainloader +1\n"; -} -close F; -open F, ">/hd/boot/grub/device.map"; -print F "(hd0) /dev/$hd\n"; -close F; -open F, "| grub --device-map=/hd/boot/grub/device.map --batch"; -print F "install (hd0,$instz)/boot/grub/stage1 d (hd0) (hd0,$instz)/boot/grub/stage2 p (hd0,$instz)/boot/grub/menu.lst\n"; -print F "quit\n"; -close F or die "error while executing grub"; - -my $packages = read_depslist("/cdrom/Mandrake/base/depslist.ordered"); - -my @media; -open F, "/cdrom/Mandrake/base/hdlists"; -foreach (<F>) { - chomp; - s/\s*#.*$//; - /^\s*$/ and next; - m/^\s*(hdlist\S*\.cz2?)\s+(\S+)\s*(.*)$/ or die "invalid hdlist description \"$_\" in hdlists file"; - - push @media, { hdlist => $1, rpmsdir => $2, descr => $3 }; -} -close F; - -#- initialize installation. -foreach (qw(/etc /etc/sysconfig /etc/rpm /var /var/lib /var/lib/rpm /var/log /proc)) { - mkdir "/mnt/$_"; -} -system "mount", "-t", "proc", "proc", "/mnt/proc"; -open F, ">/mnt/etc/fstab"; -print F "/dev/$hdp$root / $fs defaults 1 1\n"; -if ($var) { - print F "/dev/$hdp$var /var $fs defaults 1 2\n"; -} -if ($home) { - print F "/dev/$hdp$home /home $fs defaults 1 2\n"; -} -close F; -#- stupid things for installer to work correctly. -#open F, ">/mnt/etc/mandrake-release"; -#print F "Mandrake Linux release 9.1 (Bamboo) for i586"; -#close F; - -#- keep in mind all the rpm files available (according to hdlists). -my (%files, %rpms); - -require packdrake; -foreach my $medium (@media) { - my $packer = new packdrake("/cdrom/Mandrake/base/$medium->{hdlist}"); - foreach (@{$packer->{files}}) { - $packer->{data}{$_}[0] eq 'f' or next; - my ($fullname, $file) = /([^:]*):(.*)/ ? ($1, "$2.rpm") : ($_, "$_.rpm"); - $files{$fullname} = $file; - $rpms{$file} = $medium->{rpmsdir}; - } -} - -#- install some important packages. -system "rpm", "--root", "/mnt", "--initdb"; - -#- copy and install from each cd image. -foreach my $medium (@media) { - while ($cd && ! -d "/cdrom/$medium->{rpmsdir}") { - system "unmount", "/dev/$cd"; - system "eject", "/dev/$cd"; - print "Please insert the cdrom labeled \"$medium->{descr}\"\n and press [enter] when done\n"; - $yes = <STDIN>; - system "mount", "-r", "-t", "iso9660", "/dev/$cd", "/cdrom"; - } - - print "Copying packages from medium labeled \"$medium->{descr}\" to hard disk\n"; - system "mkdir", "-p", "/hd/$medium->{rpmsdir}"; - foreach my $pkg (@{$packages->{depslist}}) { - $files{rpm_fullname($pkg)} or next; - my $file = "/cdrom/$medium->{rpmsdir}/" . $files{rpm_fullname($pkg)}; - if (-e $file) { - print " copying " . rpm_fullname($pkg) . "\n"; - system "cp", "-a", $file, "/hd/$medium->{rpmsdir}"; - if (rpm_fullname($pkg) =~ /mandrake-release/) { - system "rpm", "-Uvh", "--root", "/mnt", "--nodeps", "--force", "/hd/$medium->{rpmsdir}/" . $files{rpm_fullname($pkg)}; - } - } - } -} - -#- try to figure out if a oem-message-graphic already exists. -#- if this is the case, rename it to /mnt/boot/message-graphic -if (-e "/cdrom/Mandrake/base/oem-message-graphic") { - print "Using specific oem graphic image\n"; - if (-e "/mnt/boot/message-graphic") { - rename "/mnt/boot/message-graphic", "/mnt/boot/message-graphic.old"; - system "cp", "-a", "/cdrom/Mandrake/base/oem-message-graphic", "/mnt/boot/message-graphic"; - } elsif (-e "/mnt/boot/lilo-graphic/message") { - rename "/mnt/boot/lilo-graphic/message", "/mnt/boot/lilo-graphic/message.old"; - system "cp", "-a", "/cdrom/Mandrake/base/oem-message-graphic", "/mnt/boot/lilo-graphic/message"; - } -} - -#- clean all initrd image which may have been built. -system "rm -f /mnt/boot/initrd*"; - -system "umount", "/mnt/proc"; -$home and system "umount", "/mnt/home"; -$var and system "umount", "/mnt/var"; -system "umount", "/mnt"; -system "umount", "/hd"; -system "umount", "/cdrom"; - -$cd and system "eject", "/dev/$cd"; - -print " -Done. OEM hard drive ready! -The hard drive is now ready for a customer. -System is now halted.\n\n"; - -system "halt"; - -#- gives way to format partition (simpler approach) -sub mkfs { - my ($fs, $dev) = @_; - for ($fs) { - /ext2/ and do { system "mkfs.ext2", $dev; - next }; - /ext3/ and do { system "mkfs.ext2", "-j", $dev; - system "tune2fs", "-c0", "-i0", $dev; - next }; - /fat16/ and do { system "mkdosfs", $dev; - next }; - /fat32/ and do { system "mkdosfs", "-F", "32", $dev; - next }; - die "unknown fs: $_\n"; - } -} - -sub chop_version { - ($_[0] =~ /^([^:\s]*)-[^:\-\s]+-[^:\-\s]+\.[^:\.\-\s]*(?::\S*)?/)[0] || die "unable to parse $_[0]"; -} -sub rpm_fullname { - ($_[0]{name} =~ /^([^:\s]*-[^:\-\s]+-[^:\-\s]+\.[^:\.\-\s]*)(?::\S*)?/)[0] || die "unable to parse $_[0]"; -} - -sub read_depslist { - my ($file) = @_; - my $packages = { depslist => [], names => {} }; - - #- read depslist.oredered file. - my $id = 0; - - open F, "$file" or die "unable to open ordered dependencies list file"; - while (<F>) { - my ($name, $size, @deps) = split; - push @{$packages->{depslist}}, { id => $id++, name => $name, size => $size, deps => \@deps }; - } - close F; - - foreach (@{$packages->{depslist}}) { - $packages->{names}{chop_version($_->{name})} = $_; - } - - print "read " . scalar(@{$packages->{depslist}}) . " package dependancies\n"; - $packages; -} - diff --git a/rescue/tree/etc/passwd b/rescue/tree/etc/passwd index 568451e4e..c0274a116 100644 --- a/rescue/tree/etc/passwd +++ b/rescue/tree/etc/passwd @@ -1,3 +1,2 @@ -root::0:0::/:/bin/bash -shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown -halt:*:7:0:halt:/sbin:/sbin/halt +root::0:0::/root:/bin/bash +messagebus:x:1:1::/:/sbin/nologin diff --git a/rescue/tree/etc/profile b/rescue/tree/etc/profile index cc91e4dab..17f0700dc 100644 --- a/rescue/tree/etc/profile +++ b/rescue/tree/etc/profile @@ -1,12 +1,12 @@ # /etc/profile -# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com> +# (c) Mandrakesoft, Chmouel Boudjnah <chmouel> # System wide environment and startup programs # Functions and aliases go in /etc/bashrc PROFILE_LOADED=1 -export PATH=/usr/bin:/bin:/sbin:/usr/sbin:/usr/X11R6/bin +PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/bin:/mnt/usr/sbin:/mnt/usr/bin PS1="[root@rescue \w]\\$ " ls () { /bin/ls --color=auto -F "$@";} diff --git a/rescue/tree/etc/rc.reboot b/rescue/tree/etc/rc.reboot deleted file mode 100755 index 0b67416f1..000000000 --- a/rescue/tree/etc/rc.reboot +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -sleep 1 -/sbin/killall5 -9 - -umount -a -f -t noproc - -reboot -i -d diff --git a/rescue/tree/etc/rc.sysinit b/rescue/tree/etc/rc.sysinit deleted file mode 100755 index 27fdb8187..000000000 --- a/rescue/tree/etc/rc.sysinit +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -action() { echo $1; shift; $*; } - -export PATH=/bin:/sbin:/usr/bin:/usr/sbin - -echo -e "\t\t\tWelcome to \\033[1;36mMandrake\\033[0;39m Linux" - -action "Mounting proc filesystem" mount -n -t proc /proc /proc -action "Remounting root filesystem in read-write mode" mount -n -o remount,rw / - ->/etc/mtab -mount -f / -mount -f /proc - -# Set the hostname. -action "Setting hostname rescue" hostname rescue -echo rescue > /etc/HOSTNAME - -# Loads common modules ( no kerneld :( ) -echo "Loading additional modules..." -load() { modprobe $* 2>/dev/null; } -load ide-mod -load ide-probe -load ide-disk -load ide-cd -load floppy -load af_packet -load isofs -load vfat -load ext3 -load reiserfs -load xfs -load jfs -load loop -load sd_mod -load sr_mod - -grep -q oem /proc/cmdline && exec /etc/oem-all -f - -/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 -/sbin/route add 127.0.0.1 lo - -grep -q noauto /proc/cmdline || drvinst SERIAL_USB - -if ! grep -q expert /proc/cmdline; then - rescue-gui -fi diff --git a/rescue/tree/sbin/fakeshutdown b/rescue/tree/sbin/fakeshutdown deleted file mode 100755 index c6d9b8440..000000000 --- a/rescue/tree/sbin/fakeshutdown +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/perl - -# -# Guillaume Cottenceau (gc@mandrakesoft.com) -# -# Copyright 2001 MandrakeSoft -# -# This software may be freely redistributed under the terms of the GNU -# public license. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# - -sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l } - -print "\n"; - - -#- try to umount as much as possible; uses Pixel's ultra optimized algo (let you guess how it works..) -print "Umounting:\n"; -my @mounts = cat_('/proc/mounts'); -my $something_moved; -do { - $something_moved = 0; - foreach (@mounts) { - my $where = (split)[1]; - next if $where eq '/'; #- ouch! umounting the ramdisk on / always succeeds, and makes it becoming ro :-( - if (!system("umount $where 2>/dev/null")) { - print "\t$where\n"; - $something_moved++; - } - } -} while $something_moved; - - -#- shutdown with init -exec '/sbin/init', 6; diff --git a/rescue/tree/sbin/modprobe b/rescue/tree/sbin/modprobe deleted file mode 100755 index 84de032e2..000000000 --- a/rescue/tree/sbin/modprobe +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl - -sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l } - -sub read_already_loaded() { - foreach (cat_("/proc/modules")) { - my ($name) = split; - $conf{$name}{loaded} = 1; - } -} - -sub load_deps($) { - my ($file) = @_; - - local *F; - open F, $file or log::l("error opening $file: $!"), return 0; - foreach (<F>) { - my ($f, $deps) = split ':'; - push @{$deps{$f}}, split ' ', $deps; - } -} - -sub load { - my ($name, @options) = @_; - $name =~ s/\.o//; - - $conf{$name}{loaded} and return; - eval { load($_, 'prereq') } foreach @{$deps{$name}}; - - system("packdrake -x /modules/modules.cz* /tmp $name.o"); - -r "/tmp/$name.o" or die "can't find module $name\n"; - system("/sbin/insmod /tmp/$name.o"); - my $retval = $?; - system("rm /tmp/$name.o"); - $retval and die("insmod $name failed"); -} - -!@ARGV || $ARGV[0] =~ /-h/ and die "usage: modprobe <module> [<options...>]\n"; - -read_already_loaded(); -load_deps("/modules/modules.dep"); -load(@ARGV); diff --git a/rescue/tree/bin/login b/rescue/tree/usr/bin/login index 4b2816926..4b2816926 100755 --- a/rescue/tree/bin/login +++ b/rescue/tree/usr/bin/login diff --git a/rescue/tree/usr/bin/mageia-rescue b/rescue/tree/usr/bin/mageia-rescue new file mode 100755 index 000000000..7d8bb5135 --- /dev/null +++ b/rescue/tree/usr/bin/mageia-rescue @@ -0,0 +1,42 @@ +#!/bin/sh + +# Uncomment for debugging: +# set -x + +systemctl start systemd-udevd +udevadm trigger --type=subsystems --action=add +udevadm trigger --type=devices --action=add + +# disable the weird echoprt in cooked mode for user interaction: +stty sane + +#LANGUAGE (filled by make_rescue_img) + +grep -q noauto /proc/cmdline || drvinst SERIAL_USB + +partimage_default_dir=/data/box +partimage_dir=`perl -lne 'print $1 if /BOX=(\S+)/' /proc/cmdline` +[ -z "$partimage_dir" ] && partimage_dir=$partimage_default_dir +partimage_server=`perl -lne 'print $1 if /\bpserver=(\S+)/' /proc/cmdline` + +LOOP="" +if grep -q save_all /proc/cmdline; then + partimage_whole_disk -s $partimage_server save_all $partimage_default_dir +elif grep -q rest_all /proc/cmdline; then + if [ -d /tmp/image$partimage_dir ]; then + partimage_whole_disk rest_all /tmp/image$partimage_dir + else + partimage_whole_disk -s $partimage_server rest_all $partimage_dir + fi +elif grep -q oem /proc/cmdline; then + /tmp/image/oem-rescue.sh +elif grep -q restore /proc/cmdline; then + /usr/sbin/restore-image.sh +elif ! grep -q expert /proc/cmdline; then + rescue-gui && LOOP=y +fi + +while [ "$LOOP" ]; do + bash --login + rescue-gui +done diff --git a/rescue/tree/usr/lib/CVS. b/rescue/tree/usr/lib/CVS. deleted file mode 100644 index e69de29bb..000000000 --- a/rescue/tree/usr/lib/CVS. +++ /dev/null diff --git a/rescue/tree/usr/lib/modules-load.d/mageia-rescue.conf b/rescue/tree/usr/lib/modules-load.d/mageia-rescue.conf new file mode 100644 index 000000000..9d9850baf --- /dev/null +++ b/rescue/tree/usr/lib/modules-load.d/mageia-rescue.conf @@ -0,0 +1,8 @@ +ide-gd_mod +ide-cd_mod +floppy +af_packet +loop +fuse +sd_mod +sr_mod diff --git a/rescue/tree/usr/lib/restore-image-lib.sh b/rescue/tree/usr/lib/restore-image-lib.sh new file mode 100755 index 000000000..3451f7be5 --- /dev/null +++ b/rescue/tree/usr/lib/restore-image-lib.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +TITLE="%s Installer" +BACKTITLE="%s" +MIN_DISKSIZE=5000000 + +debug="/dev/null" + +function _msgbox() +{ + dialog --timeout 60 --backtitle "$BACKTITLE" --title "$TITLE" --msgbox \ + "$1" 0 0 + + return $? +} + +function _infobox() +{ + dialog --backtitle "$BACKTITLE" --title "$TITLE" --sleep 2 \ + --infobox "$1" 0 0 + + return $? +} + +function _yesno() +{ + dialog --backtitle "$BACKTITLE" --title "$TITLE" \ + --yes-label "Yes" --no-label "No" --yesno "$1" 0 0 + + return $? +} + +function _mount() +{ + mount $1 $2 > $debug 2>&1 + + return $? +} + +function _umount() +{ + umount $1 > $debug 2>&1 + + return $? +} + +function _bind() +{ + mount --bind $1 $2 > $debug 2>&1 + + return $? +} + +function _eject() +{ + eject $1 > $debug 2>&1 + + return $? +} + +function _shutdown() +{ + [ -e /tmp/no-shutdown ] && exit + clear + sync + echo s > /proc/sysrq-trigger + echo o > /proc/sysrq-trigger + exit +} + +function _reboot() +{ + [ -e /tmp/no-shutdown ] && exit + clear + sync + echo s > /proc/sysrq-trigger + echo b > /proc/sysrq-trigger + exit +} + diff --git a/rescue/tree/usr/lib/systemd/system/rescue.service b/rescue/tree/usr/lib/systemd/system/rescue.service new file mode 100644 index 000000000..336e06c22 --- /dev/null +++ b/rescue/tree/usr/lib/systemd/system/rescue.service @@ -0,0 +1,20 @@ +[Unit] +Description=Mageia Rescue +DefaultDependencies=no +Conflicts=shutdown.target +After=sysinit.target plymouth-start.service +Before=shutdown.target + +[Service] +Environment=HOME=/ +WorkingDirectory=/ +ExecStartPre=-/bin/plymouth quit +ExecStart=/usr/bin/mageia-rescue +ExecStopPost=-/usr/bin/systemctl --fail --no-block reboot +Type=idle +StandardInput=tty-force +StandardOutput=inherit +StandardError=inherit +KillMode=process +IgnoreSIGPIPE=no +SendSIGHUP=yes diff --git a/rescue/tree/usr/lib/systemd/system/systemd-udevd.service.d/dracut-rules.conf b/rescue/tree/usr/lib/systemd/system/systemd-udevd.service.d/dracut-rules.conf new file mode 100644 index 000000000..b75df2e4e --- /dev/null +++ b/rescue/tree/usr/lib/systemd/system/systemd-udevd.service.d/dracut-rules.conf @@ -0,0 +1 @@ +ExecStartPre=-/usr/bin/rm -f /etc/udev/rules.d/10-console.rules diff --git a/rescue/tree/usr/sbin/diskdrake-resize b/rescue/tree/usr/sbin/diskdrake-resize new file mode 100755 index 000000000..88372aac7 --- /dev/null +++ b/rescue/tree/usr/sbin/diskdrake-resize @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use lib qw(/usr/lib/libDrakX); + +use devices; +use log; +use resize_fat::main; +use diskdrake::resize_ntfs; +use diskdrake::resize_ext2; + +my ($device, $fs_type, $size) = @ARGV + or die "usage: $0 <device> <fs type> <size>\n"; + +my %fs_pkgs = ( + vfat => 'resize_fat::main', + ntfs => 'diskdrake::resize_ntfs', + ext2 => 'diskdrake::resize_ext2', + ext3 => 'diskdrake::resize_ext2', + ext4 => 'diskdrake::resize_ext2', +); + +my $resize_pkg = $fs_pkgs{$fs_type} + or die "no support for $fs_type type\n"; + +log::l("resizing $device to $size"); + +my $resize = $resize_pkg->new($device, devices::make($device)) + or die "unable to initialize resize\n"; +$resize->resize($size); diff --git a/rescue/tree/usr/sbin/genpasswd b/rescue/tree/usr/sbin/genpasswd new file mode 100755 index 000000000..2f129673d --- /dev/null +++ b/rescue/tree/usr/sbin/genpasswd @@ -0,0 +1,13 @@ +#!/usr/bin/perl + +use strict; + +system "stty -echo"; +print STDERR "Give a password for ssh access: "; +chomp(my $word = <STDIN>); +print STDERR "\n"; +system "stty echo"; + +my @salt = ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; +print crypt($word, join('', @salt)); +print "\n"; diff --git a/rescue/tree/usr/sbin/grabjournallogs b/rescue/tree/usr/sbin/grabjournallogs new file mode 100755 index 000000000..ef2ea4a1d --- /dev/null +++ b/rescue/tree/usr/sbin/grabjournallogs @@ -0,0 +1,51 @@ +#!/bin/bash + +if ! mountpoint -q /mnt ; then + echo "I do not seem to see a Mageia install mounted on /mnt. You need to mount it first!" >&2 + exit 1 +fi + +if [ ! -f /mnt/etc/machine-id ]; then + echo "Cannot find machine-id file (/mnt/etc/machine-id)" >&2 + exit 1 +fi + +MID=$(cat /mnt/etc/machine-id) +echo +echo "Found machine-id: $MID" +if [ ! -d /mnt/var/log/journal/$MID ]; then + echo "Cannot find journal log directory (/mnt/var/log/journal/<machine-id>)" >&2 + exit 1 +fi + +TIMEFRAME=24 +if [ -n "$1" ]; then + NEWTIMEFRAME=$(( 0 + $1 )) + if [ $NEWTIMEFRAME -gt 0 ]; then + TIMEFRAME=$NEWTIMEFRAME + fi +fi +SINCE="$(LC_ALL=c date --date=$TIMEFRAME' hours ago' +'%F %T')" +echo "Will collect logs from the last $TIMEFRAME hour(s)" +echo " NB give numeric argument to override capture period" + +TEMPFILE=$(mktemp /tmp/grabjournallogs.XXXXXX) +echo -n "Extracting logs... " +journalctl -D /mnt/var/log/journal/$MID --since "$SINCE" -o short >$TEMPFILE +echo "done" + +if [ $(cat $TEMPFILE | wc -l) -lt 2 ]; then + rm -f $TEMPFILE + echo >&2 + echo "Cannot find any logs. Consider increasing the capture period by passing a" >&2 + echo "numeric argument larger than $TIMEFRAME." >&2 + exit 1 +fi + +echo -n "Compressing logs... " +cat $TEMPFILE | xz >/journallogs.xz +rm -f $TEMPFILE +echo "done" + +echo +echo "Your logs have been extracted to the file 'journallogs.xz'" diff --git a/rescue/tree/usr/sbin/restore-image.sh b/rescue/tree/usr/sbin/restore-image.sh new file mode 100755 index 000000000..f4f904f3f --- /dev/null +++ b/rescue/tree/usr/sbin/restore-image.sh @@ -0,0 +1,412 @@ +#!/bin/bash + +setterm -powersave off +setterm -blank 0 + +if [ -r ./restore-image-lib.sh ]; then + . ./restore-image-lib.sh +elif [ -r /usr/lib/restore-image-lib.sh ]; then + . /usr/lib/restore-image-lib.sh +fi + +export PATH="/sbin:/bin:/usr/sbin:/usr/bin" + +mnt_dir="/tmp/mnt" +restore_media="/tmp/media" +images_dir="$restore_media/images" +images="$images_dir/list" +images_config="$images_dir/config" +image="" +win32_part_dev= +win32_part_type= +win32_part_new_size= + +function read_config() +{ + if [ -r "$images_config" ]; then + . $images_config + fi +} + +function image_list() +{ + list=$(cat $images | awk -F',' \ + '{ print $1 " " $2 " " $4 }') + + echo $list +} + +function image_file() +{ + country="$1" + + file=$(grep ^$country $images | awk -F',' '{ print $3 }') + + echo $file +} + +function welcome() +{ + while true; do + clear + msg="\n Welcome to $TITLE\n\ +\nThe following images were found, select one:\n " + opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" \ + --stdout --radiolist "$msg" 0 0 0 \ + $(image_list)) + + if [ "$?" != "0" ]; then + _yesno "\nInterrupt installation?\n " + if [ "$?" = "0" ]; then + _shutdown + fi + else + if [ -z "$opcao" ]; then + continue + else + image=$(image_file $opcao) + break + fi + fi + done + + # disable kernel messages in the console + echo "1 4 1 7" > /proc/sys/kernel/printk +} + +function install_warning() +{ + if [ -n "${win32_part_dev}" ]; then + warn_msg="Windows installation detected.\nWe will set it up as dual boot. \ +You may lose some data.\nPlease backup before proceeding." + else + warn_msg="WARNING: This process will erase all data in this machine, \ +do you want to continue?" + fi + + clear + _yesno "\n$warn_msg\n" + if [ "$?" != "0" ]; then + _shutdown + fi +} + +function detect_root() +{ + inst_source_dev=$(awk "\$2 == \"$restore_media\" { print \$1 }" /proc/mounts | sed -e 's/[0-9]$//') + inst_source_dev=${inst_source_dev#/dev/} + devices=$(grep "^ .*[^0-9]$" < /proc/partitions | grep -v ${inst_source_dev} | awk '$3 > '$MIN_DISKSIZE' { print $4,$3 }') + + if [ -z "${devices}" ]; then + exit 1 + fi + + devs_found=$(($(echo $devices | wc -w)/2)) + + root_data=$(detect_win32 ${inst_source_dev}) + + if [ -z "${root_data}" ]; then + if [ "$devs_found" -gt "1" ]; then + if [ -n "${inst_source_dev}" ]; then + opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" --stdout --menu 'Choose one of the detected devices to restore to (check the blocks size column first):' 8 50 0 $devices ) + if [ "$?" != "0" ]; then + _yesno "\nInterrupt installation?\n " + if [ "$?" = "0" ]; then + _shutdown + fi + else + root_data=${opcao} + fi + fi + else + root_data=$(echo ${devices} | cut -d ' ' -f 1) + fi + fi + + echo ${root_data} +} + +function detect_win32() +{ + # from detect_root() + skip_dev=${1} + + # win32 detection won't handle complex layouts + if [ $(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | wc -l) -gt 1 ]; then + exit + fi + + # get the last created windows partition information + set -f + device=$(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | grep -e "FAT\|NTFS\|HPFS" | tail -1 | sed 's/ .*$//') + set +f + + if [ -z "${device}" ]; then + exit + fi + + # it might be needed, for safety + device_type=$(blkid -o value -s TYPE ${device}) + modprobe ${device_type} + + # df for that partition + mount ${device} /mnt + size=$(df ${device} | tail -1) + umount /mnt + + # its diskspace + used=$(echo ${size} | awk '{ print $3 }') + left=$(echo ${size} | awk '{ print $4 }') + avail=$((${left}/2)) + + if [ ! ${avail} -lt ${MIN_DISKSIZE} ]; then + win32_part_dev=${device} + win32_part_type=${device_type} + # our install takes half of 'left' + win32_part_new_size=$((${used}+${avail})) + + dev=${win32_part_dev#/dev/} + disk=${dev%[0-9]} + number=${dev#[a-w][a-w][a-w]} + let number++ + echo ${disk}${number} ${win32_part_dev} ${win32_part_type} ${win32_part_new_size} + fi +} + +function resize_win32() +{ + device=${1} + device_type=${2} + new_win32_size=${3} + + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "\nResizing Windows partition...\n" 4 55 + + dev=${device#/dev/} + disk=${dev%[0-9]} + win32_number=${dev#[a-w][a-w][a-w]} + + case ${device_type} in + vfat) device_id=b ;; + ntfs) device_id=7 ;; + hpfs) device_id=87 ;; + esac + + # wrapper around libdrakx by blino + diskdrake-resize ${device} ${device_type} $((${new_win32_size}*2)) &>/dev/null + + # we need some free sector here, rebuilding layout + fdisk /dev/${disk} &>/dev/null <<EOF +d +n +p +${win32_number} + ++${new_win32_size}K +t +${device_id} +a +${win32_number} +w +EOF + # adds linux partition to the end of the working disk + fdisk /dev/${disk} &>/dev/null <<EOF +n +p +$((${win32_number}+1)) + ++${MIN_DISKSIZE}K +t +$((${win32_number}+1)) +83 +w +EOF +} + +function detect_device() +{ + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "\nTrying to detect your root partition and disk...\n" 4 55 + + root_data=$(detect_root) + if [ -z "${root_data}" ]; then + _msgbox "\nError writing image: disk device not detected.\n" + # so that netbooks using USB sticks as disks can retry (like Gdium) + welcome + root_data=$(detect_root) + fi + set ${root_data} + root=$1 + win32_part_dev=$2 + win32_part_type=$3 + win32_part_new_size=$4 +} + +function write_image() +{ + if [ -n "${win32_part_dev}" ]; then + resize_win32 ${win32_part_dev} ${win32_part_type} ${win32_part_new_size} + fi + + image=$(cat $images_dir/list | cut -d ',' -f 3) + extension=${image/*./} + imagesize=$(ls -l $images_dir/$image | awk '{ print $5 }') + case $extension in + gz) + uncomp=zcat + total=$(gzip -l $images_dir/$image | tail -n 1 | awk '{ print $2 }') + ;; + bz2) + uncomp=bzcat + total=$((imagesize * 3)) + ;; + *) + uncomp=cat + total=$imagesize + ;; + esac + + skipstart=/bin/true + if [ -n "$win32_part_dev" ]; then + skipstart='dd of=/dev/null bs=1 count=32256' + fi + + # the actual dumping command, from image to disk + ${uncomp} ${images_dir}/${image} | (${skipstart} &>/dev/null; dd bs=4M of=/dev/${root} >/tmp/backup.out 2>&1>>/tmp/log) & + + sleep 3 + pid=$(ps ax | grep 'dd bs=4M of' | grep -v grep | awk '{ print $1 }') + + while [ true ]; do + ps | grep -q $pid + if [ $? -eq 0 ]; then + /bin/kill -SIGUSR1 $pid + complete=$(tail -n 1 /tmp/backup.out | awk '{ print $1 }') + echo $((complete*100/total)) + sleep 1 + else + break + fi + done | dialog --backtitle "$BACKTITLE" --title "$TITLE" --gauge "\nWriting image..." 8 45 + + in=$(tail -n 3 /tmp/backup.out | grep 'in$' | cut -d' ' -f1) + out=$(tail -n 3 /tmp/backup.out | grep 'out$' | cut -d' ' -f1) + + if [ x"$in" != x"$out" ]; then + _msgbox "\nError writing image!\n" + sleep 24h + fi + + # Now re-read the partition table because 'dd' might have changed it + sfdisk -R /dev/${root} +} + +function grub_setup() +{ + root=${1} + grub_dir=${2} + + # install the bootloader + grub <<EOF +device (hd0) /dev/${root%[0-9]} +root (hd0,1) +setup (hd0) +quit +EOF + # change the partition order and boot timeout accordingly + sed -i 's/(hd0,0)/(hd0,1)/g;/^timeout/s/$/0/' ${grub_dir}/menu.lst + + # dualboot configuration for grub + cat >> ${grub_dir}/menu.lst <<EOF +title Microsoft Windows +root (hd0,0) +makeactive +rootnoverify(hd0,0) +chainloader +1 +EOF +} + +function expand_fs() +{ + if [ -z "$win32_part_dev" ]; then + if [ -n "$MAIN_PART_NUMBER" ]; then + part_number=$MAIN_PART_NUMBER + else + part_number=1 + fi + root=${root%[0-9]}$part_number + fi + filesystem_type=$(dumpe2fs -h /dev/${root} 2>/dev/null| grep "Filesystem OS type" | awk '{ print $4 }') + if [ "${filesystem_type}" = "Linux" ]; then + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "Finishing Install... Expanding ${root}" 3 40 + disk=/dev/${root%[0-9]} + main_part=/dev/${root} + + # FIXME: absurdly dirty hack + main_part_num=${root:3} + swap_part_num=$((main_part_num+1)) + swap_part=${disk}${swap_part_num} + + main_part_sectors= + if [ -n "$SWAP_BLOCKS" ]; then + if [ -n "$EXPAND_FS" ]; then + total_blocks=$(sfdisk -s $disk) + main_part_blocks=$((total_blocks-SWAP_BLOCKS)) + main_part_sectors=$((main_part_blocks*2)) + else + main_part_sectors=$(sfdisk -d $disk | perl -lne 'm|^'$main_part'\b.*,\s*size\s*=\s*(\d+)\b| and print($1), exit') + fi + fi + if [ -n "$SWAP_BLOCKS" ]; then + parted $disk -- mkpartfs primary linux-swap ${main_part_sectors}s -1s yes + mkswap -L swap $swap_part + fi + if [ -n "$EXPAND_FS" ]; then + e2fsck -fy $main_part + fdisk $disk << EOF +d +$main_part_num +n +p +$main_part_num + + +a +$main_part_num +w +EOF + sfdisk -R $disk + e2fsck -fy $main_part + resize2fs $main_part + fi + mkdir -p $mnt_dir + mount $main_part $mnt_dir + grub_dir="$mnt_dir/boot/grub" + if [ -d "$grub_dir" ]; then + echo "(hd0) $disk" > "$grub_dir/device.map" + if [ -n "$win32_part_dev" ]; then + grub_setup ${root} ${grub_dir} + fi + fi + if [ -n "$MKINITRD" ]; then + mount -t sysfs none "$mnt_dir/sys" + mount -t proc none "$mnt_dir/proc" + chroot $mnt_dir bootloader-config --action rebuild-initrds + umount "$mnt_dir/sys" + umount "$mnt_dir/proc" + fi + umount $mnt_dir + fi +} + +# installation steps +welcome +read_config +detect_device +install_warning +write_image +expand_fs + +# all done! +_msgbox "\nInstallation process finished.\nPress ENTER to shutdown.\n " + +_shutdown + diff --git a/rescue/tree/usr/sbin/startssh b/rescue/tree/usr/sbin/startssh new file mode 100755 index 000000000..e14bb10e8 --- /dev/null +++ b/rescue/tree/usr/sbin/startssh @@ -0,0 +1,27 @@ +#!/bin/bash + +# test for an up interface != lo +if test "x"`ifconfig | cut -d ' ' -f 1 | grep -v '^$' | grep -v lo` = "x"; then + echo "There is no up interface, you can try to execute 'drvinst' to find drivers and 'dhcp-client' to configure your interface for DHCP." >&2 + exit 5 +fi + +# generate host keys +mkdir -p /etc/dropbear +[[ -f /etc/dropbear/dropbear_dss_host_key ]] || dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key >/dev/null || { echo "Can't generate dsa host key" >&2 ; exit 4; } +[[ -f /etc/dropbear/dropbear_rsa_host_key ]] || dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key >/dev/null || { echo "Can't generate rsa host key" >&2 ; exit 3; } + +# set a password +passwd=`genpasswd` +if (( $? != 0 )); then + reset + exit $? +fi +sed -E -i -e 's/^root:[^:]*:/root:'"${passwd//\//\\/}"':/' /etc/passwd || { echo "Can't set password" >&2 ; exit 2; } + +# test for /dev/pts +grep '^devpts /dev/pts devpts ' /proc/mounts >/dev/null 2>/dev/null || mount -t devpts devpts /dev/pts + +echo "" +echo -n "Starting ssh daemon... " +dropbear -E 2>/var/log/dropbear.log && echo "OK" || { echo "Failed" ; exit 1; } |
