source: MondoRescue/branches/2.2.10/mindi/mindi@ 2508

Last change on this file since 2508 was 2508, checked in by Bruno Cornec, 14 years ago

r3287@localhost (orig r2285): bruno | 2009-07-20 11:36:47 +0200

r3285@localhost: bruno | 2009-07-20 11:17:35 +0200
Apply fix in 2.2.10 around multi USB device handling to 2.2.9 as well


r3291@localhost (orig r2288): bruno | 2009-07-21 16:48:31 +0200
Copy 2.2.10 test script in to 2.2.9 for memory problm analysis


r3293@localhost (orig r2290): bruno | 2009-07-22 14:03:44 +0200

  • Fix a printing error in mindi for the tar command
  • Fix all mr_asprintf which had no second param as a string


r3295@localhost (orig r2292): bruno | 2009-07-22 16:55:00 +0200

  • Fix #160 and #346 by rewriting the message.txt file with more valid information gathered in mindi


r3300@localhost (orig r2294): bruno | 2009-07-23 01:58:08 +0200

Man pages patch from Joe Ross (joe.ross_at_gmail.com)


r3303@localhost (orig r2297): bruno | 2009-07-23 17:43:49 +0200
Fix a remaining display error for 2.2.9. That version has been tested OK in a lab.


r3304@localhost (orig r2298): bruno | 2009-07-23 18:18:27 +0200

  • Remove memory leak for the last modification


r3308@localhost (orig r2302): bruno | 2009-07-24 21:18:50 +0200
Improve logging of mountlist.txt


r3310@localhost (orig r2304): bruno | 2009-07-27 19:45:10 +0200

  • popup_and_get_string needs an allocated buffer for the moment so fixing the calls with dyn. ones
  • Fix a bug in mem.c for mr_strcat, which wasn't modifying the right pointer level


r3311@localhost (orig r2305): bruno | 2009-07-27 19:49:35 +0200
Avoid a memory leak in the previous patch


r3314@localhost (orig r2308): bruno | 2009-07-27 20:59:06 +0200
Fix a bug in mr_strcat backported from 2.2.10. Should solve our seg faults.


r3315@localhost (orig r2309): bruno | 2009-07-28 02:14:23 +0200
Cosmetic changes to allow for quality to not giv false positive


r3343@localhost (orig r2311): bruno | 2009-08-18 02:13:43 +0200
Fix for initramfs detection with 2.6.30 (Hugo Vanwoerkom hvw59601_at_care2.com)


r3367@localhost (orig r2333): bruno | 2009-08-18 16:26:26 +0200
Adds a precision for -U option in man page on raw device usage and not partition name


r3373@localhost (orig r2336): bruno | 2009-08-20 17:37:41 +0200

  • Precise the combined usage of -E and -I in mondoarchive (Case 4601017223)


r3379@localhost (orig r2342): bruno | 2009-08-21 16:27:10 +0200


r3383@localhost (orig r2344): bruno | 2009-08-24 13:37:09 +0200

r3382@localhost: bruno | 2009-08-24 13:30:25 +0200
In NFS mode also propose access to expert, interactive, ... entry at boot prompt


r3388@localhost (orig r2346): bruno | 2009-08-27 11:41:16 +0200
Adds fdisk -l result in Log File at restore time


r3389@localhost (orig r2347): bruno | 2009-08-27 13:51:00 +0200

  • Solve tmp dir creation which sometimes was trying to create /%xx dirs. Should fix #293 for good


r3390@localhost (orig r2348): bruno | 2009-08-27 13:54:25 +0200
Improve logging (minor)


r3394@localhost (orig r2350): bruno | 2009-08-28 02:24:19 +0200
Change inerface of evaluate_mountlist and spread_flaws_across_three_lines in order to solve bugs linked to strings management in these functions. May fix a restoration crash seen by some customers


r3397@localhost (orig r2353): bruno | 2009-08-28 19:03:45 +0200

  • Addition of a nomd option to avoid starting mdadm
  • mpath is now already started if there was a mpath entry in mountlist


r3399@localhost (orig r2355): bruno | 2009-08-29 00:56:50 +0200
Remove function spread_flaws_across_three_lines and expand it at the single place where it was useful, and fix memory allocation issues in it.


r3402@localhost (orig r2358): bruno | 2009-09-01 19:02:35 +0200
P2V doc updated (Lester Wade lester.wade_at_hp.com)


r3404@localhost (orig r2360): bruno | 2009-09-01 19:26:53 +0200
Website update to refer to new P2V document


r3405@localhost (orig r2361): bruno | 2009-09-03 13:54:25 +0200

  • Fix a case where the NFS dir in restore mode was mounted rw (linked to bug #291 could create a huge problem)


r3407@localhost (orig r2363): bruno | 2009-09-03 14:46:46 +0200
More verbose at installation of additional tools


r3409@localhost (orig r2365): bruno | 2009-09-03 18:08:32 +0200

  • New update from Lester Wade (lester.wade_at_hp.com) for P2V doc


r3410@localhost (orig r2366): bruno | 2009-09-05 01:28:18 +0200
place the code of mondo_makefilelist before its call



r3411@localhost (orig r2367): bruno | 2009-09-06 01:51:26 +0200

  • Advertising for project-builder on the website added


r3412@localhost (orig r2368): bruno | 2009-09-07 15:36:23 +0200
Fix compilation issue


r3413@localhost (orig r2369): bruno | 2009-09-07 18:03:40 +0200
Another compilation issue fixed.


r3415@localhost (orig r2371): bruno | 2009-09-08 13:40:25 +0200

  • Fix a problem a error detection in evaluate_mountlist which casued nuke mode to abort. Error string should also be better now.


r3417@localhost (orig r2373): bruno | 2009-09-08 13:55:31 +0200
Avoid asking the Prefix name in NFS mode twice


r3418@localhost (orig r2374): bruno | 2009-09-08 20:04:07 +0200

  • Try to fix garbled screen progression in text mode based on 2.2.10 modifications which are working


r3424@localhost (orig r2380): bruno | 2009-09-09 20:30:47 +0200

  • Change NFS support into a NetFS support to allow for multiple protocol in addition to NFS (NEEDS TESTING)
  • Better logging to detect a potential nuke issue


r3425@localhost (orig r2381): bruno | 2009-09-10 02:05:55 +0200
Fix a missing param for sshfs call


r3428@localhost (orig r2384): bruno | 2009-09-10 13:02:56 +0200

  • Remove separate function look_for_duplicate_mountpoints used only once and whose interface created problems with caller


r3430@localhost (orig r2386): bruno | 2009-09-10 16:06:52 +0200
Be compatible on backup type by making old nfs recognized as netfs and proto forced


r3431@localhost (orig r2387): bruno | 2009-09-10 18:40:47 +0200
Fix a problem in netfs analysis in mondoarchive


r3432@localhost (orig r2388): bruno | 2009-09-10 20:25:13 +0200
Fix mondoarchive CLI analysis for NETFS type of requests


r3434@localhost (orig r2390): bruno | 2009-09-11 03:05:20 +0200

  • Adds ext3 initrd support for 2.6.30


r3437@localhost (orig r2393): bruno | 2009-09-11 11:56:52 +0200

  • Tries to add support for bzip2 and lzma initramfs (preliminary, not tested) for 2.6.30


r3438@localhost (orig r2394): bruno | 2009-09-12 02:53:02 +0200
Fix interface of evaluate_mountlist (remove 2nd param useless) and fix nuke mode which wasn't working.


r3441@localhost (orig r2397): bruno | 2009-09-14 18:54:34 +0200
Fix a format issue in text mode on percentage


r3452@localhost (orig r2398): bruno | 2009-09-15 16:00:13 +0200

  • Fix a bug where flaws_str could be NULL and wasn't tested correctly.


r3453@localhost (orig r2399): bruno | 2009-09-15 19:28:39 +0200

  • Use protocol name when displaying restore progress instead of netfs
  • Ask for network protocol name at restore time


r3455@localhost (orig r2401): bruno | 2009-09-15 19:34:19 +0200
Wrong structure member name was used


r3456@localhost (orig r2402): bruno | 2009-09-16 13:04:17 +0200
Use dir for shell related commands and dir1 for C related actions in open_and_list_dir to avoid missing some files with { in names e.g.


r3457@localhost (orig r2403): bruno | 2009-09-16 16:32:03 +0200

  • At restore time read the netfs protocol in the conf file


r3462@localhost (orig r2408): bruno | 2009-09-18 15:17:08 +0200
Remove useless script


r3463@localhost (orig r2409): bruno | 2009-09-18 15:25:35 +0200

  • Split deplist.txt into multiple conf files under deplist.d in the conf dir. This will allow to have a minimal.conf file for initrd content to analyze to improve support of new embedded feature in the future (sshfs, live install). The other conf files contain the additional commands to put in the all.tar.gz. For the moment, mindi is still working the same. THis infra will allow that support in a near future. deplist.txt is now reserved for the admin additional commands.


r3465@localhost (orig r2410): bruno | 2009-09-18 19:10:54 +0200

  • Better list of mandatory tools
  • Adds fuse and sshfs support in initrd


r3466@localhost (orig r2411): bruno | 2009-09-18 20:32:47 +0200
sshfs also needs ssh at restore time in initrd


r3478@localhost (orig r2418): bruno | 2009-09-23 23:22:39 +0200
Modify getfattr call to have all extended attributes, including non user ones. (patch from Kevin Ritzenthaler Kevin.Ritzenthaler_at_hp.com) and fix #357


r3479@localhost (orig r2419): bruno | 2009-09-23 23:50:34 +0200
star only supports ACL when used with exustar mode. Fix #356.


r3482@localhost (orig r2422): bruno | 2009-09-24 16:53:24 +0200

  • Adds support for bnx2x (BL 460 G6) and auth_rpcgss (Debian 2.6.31)


r3485@localhost (orig r2423): bruno | 2009-09-25 16:38:40 +0200
Fix an issue in is_this_device_mounted (string freed before last usage)


r3486@localhost (orig r2424): bruno | 2009-09-25 18:44:01 +0200

  • analyze-my-lvm now removes excluded devices from list coming from mondoarchive
  • new mr_make_devlist_from_pathlist which handle the new bkpinfo->exclude_devs field containing the excluded devices and remove corresponding code from libmondo-cli.c
  • Move DSF code into libmondo-devices.c for coherency, and only the previous function is made externally available
  • Remove dev_to_exclude in libmondo-archive.c which wasn't working correctly and replace it with bkpinfo->exclude_devs


r3487@localhost (orig r2425): bruno | 2009-09-25 18:58:23 +0200

  • Improving ssh support at restore time by providing a shadow file


r3489@localhost (orig r2426): bruno | 2009-09-25 19:42:09 +0200

  • Attempt to stay backward compatible without protocol for -n option


r3490@localhost (orig r2427): bruno | 2009-09-28 02:08:06 +0200
Avoids null param for excludes_devs for mindi call


r3492@localhost (orig r2429): bruno | 2009-09-28 11:46:16 +0200

  • Simplify GetInitrdFilesystemToUse which doesn't need to detect everything, but just know if it's initramfs (new mode) or a compressed FS ext2/3 (older mode) as initrd is anyway re-made by mindi. Should fix #353


r3494@localhost (orig r2431): bruno | 2009-09-28 13:16:18 +0200

  • Use only the AWK veriable everywhere and not the awk command


r3495@localhost (orig r2432): bruno | 2009-09-28 14:16:31 +0200
Warning emited in case of duplicate mountpoints or devices in fstab found


r3496@localhost (orig r2433): bruno | 2009-09-28 15:55:17 +0200
ssh in the restore env needs some dlopened libs (libnss_compat|files)


r3497@localhost (orig r2434): bruno | 2009-09-28 16:33:14 +0200
Compiler warning fixed


r3498@localhost (orig r2435): bruno | 2009-09-28 17:55:26 +0200
Improve user management for NetFS cases


r3499@localhost (orig r2436): bruno | 2009-09-29 01:48:32 +0200

  • Improve deplist.d/* files
  • adds libnss for ssh support in boot disk
  • Solve a memory management issue in DSF module (strtok => mr_strtok)
  • DSF now also supports partitions in addition to full disks
  • Adds debug in open_and_list_dir


r3500@localhost (orig r2437): bruno | 2009-09-29 10:41:56 +0200

  • Fix udev support in init for Mandriva 2009.1 (udevadm settle is blocking)


r3501@localhost (orig r2438): bruno | 2009-09-29 14:41:36 +0200

  • Improvements on sshfs/ssh management in restore mode
  • Include now all minimal requirements for sshfs


r3502@localhost (orig r2439): bruno | 2009-09-29 18:46:08 +0200

  • Avoids error message if some ssh conf files do not exist


r3503@localhost (orig r2440): bruno | 2009-09-29 18:57:13 +0200

  • Avoids comment analysis in the new code handling deplist.d


r3504@localhost (orig r2441): bruno | 2009-09-29 19:34:34 +0200

  • fuse device is needed at restore time for sshfs


r3505@localhost (orig r2442): bruno | 2009-09-29 20:02:36 +0200

  • Improves udev timeout handling


r3506@localhost (orig r2443): bruno | 2009-09-29 20:43:38 +0200

  • priority given to env var for tmpdir
  • fuse FS excluded from tmpdir computation


r3518@localhost (orig r2447): bruno | 2009-10-04 01:58:08 +0200

  • Iprove USB log in case of error by adding the conf file


r3519@localhost (orig r2448): bruno | 2009-10-05 11:06:13 +0200


r3520@localhost (orig r2449): bruno | 2009-10-06 01:10:35 +0200

  • Adds support for grub2 conf file grub.cfg in addition to menu.lst


r3521@localhost (orig r2450): bruno | 2009-10-06 01:24:02 +0200

  • Fix a mr_asprintf usage without & causing a seg fault.


r3523@localhost (orig r2452): bruno | 2009-10-06 12:47:56 +0200
CIFS mounts shouldn't be part of the mountlist analysis (should help solving #288)


r3524@localhost (orig r2453): bruno | 2009-10-07 10:17:03 +0200

  • Fix a bug in handling of -E option with real devices (bad report in function mr_make_devlist_from_pathlist of the test between -E and -I)


r3525@localhost (orig r2454): bruno | 2009-10-07 10:19:02 +0200

  • Fix an error in the test for grub conf files (or used instead of and)


r3526@localhost (orig r2455): bruno | 2009-10-07 16:14:59 +0200
afio is under /bin on Debian


r3527@localhost (orig r2456): bruno | 2009-10-07 17:31:26 +0200

  • Adds support for libcrc32c (needed by bnx2x)


r3532@localhost (orig r2457): bruno | 2009-10-09 13:33:44 +0200

  • Apply path from Matthew Cline (matt_at_nightrealms.com) in order to fix #359


r3533@localhost (orig r2458): bruno | 2009-10-09 13:41:02 +0200
Adds a conf file example for mindi and fix #360


r3535@localhost (orig r2459): bruno | 2009-10-09 15:13:01 +0200
MOde of conf file


r3546@localhost (orig r2461): bruno | 2009-10-14 01:12:24 +0200

  • umount freshly created VFAT partition on USB key as Ubunu has an automounter mounting it as soon as created (Steffen Neumann sneumann_at_ipb-halle.de)


r3566@localhost (orig r2463): bruno | 2009-10-26 01:34:16 +0100

  • Reset an error counter before blanking a DVD to avoid always returning an error (Vincent Raman vincent.raman_at_macqel.eu)


r3567@localhost (orig r2464): bruno | 2009-10-26 13:57:14 +0100
bzip2 is under /bin on Debian


r3568@localhost (orig r2465): bruno | 2009-10-28 01:46:30 +0100
some distro hold lvm commands under /usr/sbin


r3595@localhost (orig r2469): bruno | 2009-11-10 12:22:10 +0100
/dev/shm is now part of the default exclude list


r3596@localhost (orig r2470): bruno | 2009-11-10 12:32:40 +0100
Remove useless pb_log and MONDO_TRACEFILE


r3597@localhost (orig r2471): bruno | 2009-11-10 12:57:58 +0100
Improve analysis of kernel modules by printing whether it's a live or extra module which has not been found (Matthew Cline) as reported in #362


r3598@localhost (orig r2472): bruno | 2009-11-10 13:21:46 +0100

  • Default to DVD size when in iso or netfs mode


r3599@localhost (orig r2473): bruno | 2009-11-10 14:13:10 +0100

  • Fix #363 where exclude_paths was extended up to memory limit dumping core


r3600@localhost (orig r2474): bruno | 2009-11-10 14:31:14 +0100

  • Update deplist for Debian support


r3602@localhost (orig r2476): bruno | 2009-11-11 02:44:42 +0100

  • small improvement for loging in USB case


r3603@localhost (orig r2477): bruno | 2009-11-11 13:29:27 +0100

  • Adds a nolvm boot option at restore time


r3604@localhost (orig r2478): bruno | 2009-11-11 19:54:51 +0100

  • Fix #367 - the for loop doesn't make any test now, as it was computed before entering the loop, leading to an error, and was also made inside the loop anyway.


r3605@localhost (orig r2479): bruno | 2009-11-12 00:32:45 +0100

  • Add support for diskdumplib driver useful for RHEL 3 and IBM xseries 336


r3606@localhost (orig r2480): bruno | 2009-11-12 01:09:40 +0100

  • If using nolvm, mondorestore should also not nalyze and handle i-want-my-lvm


r3608@localhost (orig r2482): bruno | 2009-11-14 12:54:11 +0100
Fix bunzip2 on debian as well


r3610@localhost (orig r2484): bruno | 2009-11-15 00:44:19 +0100

  • Adds support for variable serial port console, with defalut to /dev/ttyS0, and a boot param to change it with serial=/dev/ttySx


r3615@localhost (orig r2485): bruno | 2009-11-15 01:34:33 +0100

r3614@localhost: bruno | 2009-11-15 01:34:12 +0100
Adds a space in exclude paths


r3623@localhost (orig r2487): bruno | 2009-11-18 20:41:40 +0100

r3620@localhost: bruno | 2009-11-18 10:31:36 +0100

  • Only link /dev/tty to serial port when there is indeed a serial port. If not breaks mondorestore on normal console


r3631@localhost (orig r2490): bruno | 2009-11-24 01:48:29 +0100
Put news below in the main page to make it more readable


r3648@localhost (orig r2492): bruno | 2009-11-25 23:50:13 +0100

r3647@localhost: bruno | 2009-11-25 23:49:11 +0100

  • Add warning for -f and SW Raid as in 2.2.10


r3650@localhost (orig r2493): bruno | 2009-11-26 00:19:52 +0100

r3649@localhost: bruno | 2009-11-26 00:18:27 +0100

  • Addition of the german translation made by Magnus Rasche (Magnus.rasche_at_gmx.de) and Website inclusion


r3652@localhost (orig r2495): bruno | 2009-11-27 15:55:55 +0100
cosmetic display fix
r3659@localhost (orig r2498): bruno | 2009-12-05 17:53:03 +0100
nfsopt restore boot time option added to support custom mount options for network restore


r3684@localhost (orig r2501): bruno | 2009-12-17 00:35:08 +0100
Fix #375 mondo will segfault if the partition in sensibly_set_tmpdir_and_scratchdir() is read-only (cylau)


r3685@localhost (orig r2502): bruno | 2009-12-17 01:02:47 +0100

  • Fix an issue in the function listing kernel modules when not found


r3686@localhost (orig r2503): bruno | 2009-12-17 01:15:01 +0100
Adds scsi_dump_register to mindi SCSI_MODS for RHEL3 + IBM servers


r3701@localhost (orig r2504): bruno | 2009-12-23 02:24:33 +0100

  • Addition of the Lab for Mondorescue


r3702@localhost (orig r2505): bruno | 2009-12-23 02:41:17 +0100
Web site update for Lab MondoRescue delivery


r3706@localhost (orig r2506): bruno | 2010-01-04 11:31:53 +0100

  • Fix a bug when isodir is / only when splitting it in iso_path and iso_mnt


r3707@localhost (orig r2507): bruno | 2010-01-04 13:22:49 +0100

  • Fix #377: Segfault in pause_and_ask_for_cdr() (ggeens)


  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 94.4 KB
RevLine 
[747]1#!/bin/bash
2
3# $Id: mindi 2508 2010-01-04 18:21:55Z bruno $
4#
5#-----------------------------------------------------------------------------
6# mindi - mini-Linux distro based on the user's filesystem & distribution
7#
[1880]8# Mindi can create a multi-image boot/root kit. The first image is the boot
[747]9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
[1565]16ARCH=`/bin/uname -m`
[2293]17KERVERRUN=`/bin/uname -r`
18# By default we use the running kernel as a reference
19KERVER=$KERVERRUN
[747]20
[2444]21# In case of problem with udev you can try to add udevdebug
22ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off udevtimeout=10"
[747]23
[1691]24MINDI_REV=PBREV
25MINDI_VER=PBVER
[747]26
27MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
28MINDI_PREFIX=XXX
29MINDI_CONF=YYY
30MINDI_SBIN=${MINDI_PREFIX}/sbin
[2462]31MINDI_DATA=LLL
32MINDI_CACHE=CCC
[747]33
[925]34# Temporary directory for mindi
35TMPDIR=/tmp
36
[2462]37EXTRA_SPACE=50000 # increase if you run out of ramdisk space
[2446]38BOOT_SIZE=24576 # size of the boot disk
[747]39
40PROMPT_MAKE_CD_IMAGE="yes"
41 # Ask if you want to make a CD Image to be written?
42 # if this is set to 'no', then the image will be created automatically
43
[1684]44PROMPT_MAKE_USB_IMAGE="yes"
45 # Ask if you want to make a USB Image to be written?
46 # if this is set to 'no', then the image will be created automatically
47
[966]48USE_OWN_KERNEL="yes"
[747]49 # If set to "no", you will be prompted for whether or not
50 # you want to use your own kernel, or the supplied default.
51 # If "yes" mindi will automatically use your own kernel.
[925]52
[747]53MY_FSTAB=/etc/fstab
54TAPE_MODS="ht st osst ide-tape ide_tape"
[2503]55SCSI_MODS="3w-xxxx 3w_xxxx 3w_9xxx 3w-9xxx 53c7,8xx a100u2w a320raid aacraid adpahci advansys aha152x aha1542 aha1740 aic79xx aic79xx_mod aic7xxx aic7xxx_mod aic7xxx_old AM53C974 atp870u BusLogic cciss cpqfc dmx3191d dpt_i2o dtc eata eata_dma eata_pio fdomain gdth g_NCR5380 i2o_block i2o_core ide-scsi ieee1394 imm in2000 initio ips iscsi iscsi_tcp libiscsi scsi_transport_iscsi isp megaraid megaraid_mm megaraid_mbox megaraid_sas mptbase mptscsih mptsas mptspi mptfc mptscsi mptctl NCR53c406a ncr53c8xx nsp32 pas16 pci2000 pci2220i pcmcia ppa psi240i qla1280 qla2200 qla2300 qla2400 qla2xxx qla2xxx_conf qlogicfas qlogicfc qlogicisp qlogicfas qlogicfas408 raw1394 scsi_mod scsi_transport_sas scsi_transport_spi scsi_transport_fc sd_mod crc_t10dif crc-t10dif seagate sg sim710 sr_mod sym53c416 sym53c8xx sym53c8xx_2 t128 tmscsim u14-34f ultrastor wd7000 vmhgfs intermodule scsi_dh scsi_tgt emcpdm emcpgpx emcpmpx emcp dc395x diskdumplib scsi_dump_register"
[747]56
57# ide-probe-mod
[2169]58IDE_MODS="ide ide-floppy floppy ide-generic ide-detect ide-mod ide-disk ide_disk ide-cd ide_cd ide_cd_mod ide-cd_mod ide-cs ide-core ide_core ide-gd_mod edd paride ata_generic ata_piix libata dock via82cxxx generic nvidia ahci sata_nv cmd64x pata_amd pata_marvell pata_serverworks pata_sis amd74xx sis5513 jmicron sata_promise sata_via serverworks"
[747]59PCMCIA_MODS="pcmcia_core ds yenta_socket"
[2151]60USB_MODS="usb-storage usb-ohci usb-uhci usbcore usb_storage input hid uhci_hcd ehci_hcd uhci-hcd ehci-hcd ohci-hcd ohci_hcd usbkbd usbhid keybdev mousedev libusual scsi_mod ff-memless"
[2462]61NET_MODS="auth_rpcgss sunrpc nfs nfs_acl lockd fscache loop mii 3c59x e100 bcm5700 bnx2 bnx2x e1000 e1000e igb eepro100 ne2k-pci tg3 libphy pcnet32 8139cp 8139too 8390 forcedeth vmxnet vmnet exportfs fuse libcrc32c crc32c"
[1993]62CDROM_MODS="$TAPE_MODS $IDE_MODS $USB_MODS $PCMCIA_MODS $SCSI_MODS $NET_MODS af_packet cdrom isocd isofs inflate_fs nls_iso8859-1 nls_base nls_cp437 nls_utf8 sg sr_mod zlib_inflate iso9660"
63# Those modules will only go on the backup media, not the boot media.
[2382]64EXTRA_MODS="$CDROM_MODS vfat fat loop md-mod linear raid0 raid1 xor raid10 raid5 raid456 lvm-mod dm-mod dm_mod dm-snapshot dm_snapshot dm-zero dm_zero dm-mirror dm_mirror dm-multipath dm-round-robin dm-emc dm-hp-sw dm-rdac multipath jfs xfs xfs_support pagebuf reiserfs ext2 ext3 minix nfs nfs_acl nfsd lockd sunrpc jbd mbcache ext4 jbd2 crc16"
[1230]65# Replace with that line for HP OCMP e.g.
[2073]66#DENY_MODS="MPS_Driver_Mapper mps octtldrv tscttl streams kqemu fdomain"
[1828]67DENY_MODS="kqemu"
[1399]68# Force some modules to be included
[1354]69FORCE_MODS=""
[925]70
[747]71LOGFILE=/var/log/mindi.log
72BOOT_MEDIA_MESSAGE="\
73To format and restore all files automatically, type 'nuke' <enter>.\n\
74To restore some/all files interactively, type 'interactive' <enter>.\n\
75To compare the archives with your filesystem, type 'compare' <enter>.\n\
76To boot to a command-line prompt (expert mode), type 'expert' <enter>.\n\
77You may add one or more of the following parameters as well:-\n\n\
78 donteject - mondorestore will not eject the CD; this is useful if, for\n\
79 instance, your PC's case has a concealed CD-ROM drive\n\
80 noresize - your mountlist will not be adjusted to use your unallocated\n\
81 hard disk space\n\
82 textonly - do not call any Newt library routines; this is unattractive\n\
83 but valuable if you find your Newt library has bugs in it\n\n\
84e.g. Type 'nuke donteject textonly' if you have an unstable Newt library and \n\
85a PC whose CD-ROM drive tray would be damaged if it unexpectedly ejected.\n\
86"
[925]87FDISK=$MINDI_SBIN/parted2fdisk
[747]88
[925]89# Using a config file allow to overwrite some values
90MINDI_CONFIG="$MINDI_CONF/mindi.conf"
91if [ -f $MINDI_CONFIG ]; then
92 . $MINDI_CONFIG
93fi
[2445]94DEPLIST_FILE="$MINDI_CONF/deplist.conf"
95DEPLIST_FILE_MIN="$MINDI_CONF/deplist-minimal.conf"
[2412]96DEPLIST_DIR="$MINDI_CONF/deplist.d"
97
[2508]98DEPLIST_DIR="$MINDI_CONF/deplist.d"
99
[1885]100ISO_CMD="/usr/bin/mkisofs"
101ISO_OPT="-J -r -v -p Mindi -publisher http://www.mondorescue.org -A Mindi"
[925]102
[2460]103# Mandriva system e.g. use cdrkit, which uses genisoimage instead of mkisofs.
104# However, they use exactly the same command line parameters, so just
105# use genisoimage if it's available.
106if [ ! -x $ISO_CMD ]; then
107 ISO_CMD=/usr/bin/genisoimage
108fi
109
[1485]110# Now we can create what we need
[2150]111MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
112if [ $? -ne 0 ]; then
113 df $TMPDIR
114 Die "Unable to create a temporary directory ! Check space on $TMPDIR"
115fi
[2153]116if [ _"$MINDI_TMP" = _"" ]; then
117 Die "MINDI_TMP is empty, aborting"
118fi
119if [ _"$MINDI_TMP" = _"/" ]; then
120 Die "MINDI_TMP is /, aborting"
121fi
[2150]122export MINDI_TMP
[940]123
[747]124# ----------------------------------------------------------------------------
125
126
127AbortHere() {
128 [ "$mountpoint" ] && umount $mountpoint 2>> $LOGFILE
129 Die "Program is terminating in response to signal received from OS/user"
130}
131
132
133Aborted() {
134 trap SIGHUP SIGTERM SIGTRAP SIGINT
[1880]135 [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
[747]136 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
137 Die "User abort."
138}
139
140
141AddFileToCfgIfExists() {
142 [ -e "$1" ] && echo -en "$2 `cat $1`\n" >> $3
143}
144
145
146AddKeyboardMappingFile() {
147 local mappath r included_list included_item i res ii sss
148 mappath=$1
149 KBDEPTH=$(($KBDEPTH+1))
150 [ "$KBDEPTH" -gt "128" ] && Die "Edit $MINDI_SBIN/mindi and disable FindAndAddUserKeyboardMappingFile (line 2160, approx.)"
151 if [ -e "$bigdir/$mappath" ] ; then
[2341]152 LogFile "$mappath already added"
[747]153 return
154 elif [ -d "$bigdir/$mappath" ] ; then
155 echo "Cannot add $mappath: it's a directory. Sorry."
156 return
157 fi
[2341]158 LogFile "Added kbd map $mappath"
[747]159 if [ ! -e "$mappath" ] ; then
[1764]160 mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
[747]161 if [ ! -e "$mappath" ] ; then
[2341]162 LogAll "Cannot add $mappath: kbd map file not found"
[747]163 return
164 fi
165 fi
166
167 mkdir -p $bigdir/etc
[2341]168 tar cf - -C / $mappath 2>> $MINDI_TMP/$$.log | (cd $bigdir ; tar xf -) || LogAll "AKMF -- Could not copy $mappath to $bigdir" $MINDI_TMP/$$.log
[747]169 if [ "`echo $mappath | grep -F ".gz"`" ] ; then
170 included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
171 else
172 included_list=`grep -Fi include $mappath | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
173 fi
174 for included_item in $included_list ; do
[925]175 if [ ! -e "$included_item" ] ; then
[1764]176 sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
177 [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
[925]178 for ii in $sss ; do
[747]179 [ -e "$ii" ] && AddKeyboardMappingFile $ii
[925]180 done
181 else
182 AddKeyboardMappingFile $included_item
183 fi
[747]184 done
185}
186
187
188CopyDependenciesToDirectory() {
[1989]189 local outdir incoming fname counter d found
[747]190 outdir=$1
[2445]191 noof_lines=$2
[747]192 mkdir -p $outdir
193 incoming=`ReadLine`
[2445]194 progress=0
[747]195 while [ "$incoming" != "" ] ; do
[1526]196 # Non absolute file names should not arrive till here => skipped
197 if [ `echo "$incoming" | cut -c1` != '/' ]; then
[2341]198 LogAll "Unable to handle $incoming"
[1526]199 incoming=`ReadLine`
200 continue
201 fi
202 # no parent directory of incoming should be a link, copy is not possible in that case
203 d=`dirname "$incoming"`
204 found="false"
205 while [ $d != "/" -a $found = "false" ]; do
206 [ -h "$d" ] && found="true"
207 d=`dirname "$d"`
208 done
209 if [ -d "$incoming" ] && [ ! -h "$incoming" ]; then
[2445]210 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir 0
[1526]211 elif [ -e "$incoming" ] && [ $found = "false" ]; then
[2166]212 tar cf - -C / $incoming 2>> $MINDI_TMP/$$.log | (cd $outdir ; tar xf -) || Die "Cannot copy $incoming to $outdir - did you run out of disk space?" $MINDI_TMP/$$.log
[1989]213
214 # Only uncompress modules if not using udevd
215 if [ "`echo "$incoming" | grep "lib/modules/.*\..*o\.gz"`" != "" ] && [ "`ps auxww | grep -v grep | grep -qw udevd`" != "" ]; then
[2341]216 gunzip -f $outdir/$incoming || LogAll "Cannot gunzip $outdir/$incoming"
[925]217 fi
[1989]218 [ -x "$outdir" ] && StripExecutable $outdir "-$filename-"
[2445]219 progress=$(($progress+1))
220 LogProgress $progress $noof_lines
[747]221 fi
222 incoming=`ReadLine`
223 done
224}
225
226
227CountItemsIn() {
228 local r
229 r=0
230 for q in $1 ; do
231 r=$(($r+1))
232 done
233 echo $r
234}
235
236
[925]237# Last function called before exiting
238# Parameter is exit code value
[931]239MindiExit() {
[925]240 local my_partitions
[747]241
[2341]242 LogFile "Mindi $MINDI_VERSION is exiting"
243 LogFile "End date : `date`"
[1335]244 if [ _"$MONDO_SHARE" != _"" ] ; then
[1349]245 echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
[1315]246 cat $LOGFILE >> /var/log/mondoarchive.log
[1349]247 echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
[1315]248 fi
[747]249
[925]250 cd /
[1636]251 sync&
[747]252
[1636]253 # Unmount what could remain mounted
[2462]254 my_partitions=`mount | grep -F $MINDI_TMP | cut -f1 -d' '`
[925]255 [ "$my_partitions" != "" ] && umount $my_partitions
[940]256 # Clean temporary files only when standalone mindi
[948]257 if [ _"$MINDI_TMP" != _"$MONDO_TMP" ]; then
[2153]258 rm -Rf $MINDI_TMP
[940]259 fi
[925]260 exit $1
261}
262
[747]263Die() {
[925]264 local i
[747]265 if [ "$1" = "" ] ; then
[2341]266 LogAll "FATAL ERROR"
[747]267 else
[2341]268 LogAll "FATAL ERROR. $1"
[747]269 fi
[2166]270 if [ _"$2" != _"" ]; then
271 grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
272 fi
273 rm -f "$2"
[747]274
[2341]275 LogAll "Please e-mail a copy of $LOGFILE to the mailing list."
276 LogAll "See http://www.mondorescue.org for more information."
277 LogAll "WE CANNOT HELP unless you enclose that file.\n"
[925]278 MindiExit -1
[747]279}
280
281
282DropOptimizedLibraries() {
[2446]283 local outdir filelist list_of_optimized_libraries optimized_lib_name vanilla_lib_name reason msg resolved res progress
[747]284 filelist=$1
285 outdir=$2
286
[2446]287 progress=0
[747]288 list_of_optimized_libraries=`grep "lib/i[5-7]86/" $filelist`
289 if [ "$list_of_optimized_libraries" = "" ] ; then
[859]290 return 0
[2446]291 else
292 noof_lines=`echo $list_of_optimized_libraries | tr ' ' '\n' | wc -l`
[747]293 fi
294 echo -en "Dropping i686-optimized libraries if appropriate"
295 for optimized_lib_name in $list_of_optimized_libraries ; do
[859]296 reason=""
[1483]297 vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
[859]298 echo "$vanilla_lib_name" >> $filelist
[2341]299 LogFile "Adding $vanilla_lib_name to filelist"
[859]300 mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null
301 rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null
[2168]302
303 # This may return multiple files
304 for resolved in `ReadAllLink $vanilla_lib_name`; do
[2341]305 LogFile "Adding as deps $resolved to filelist"
[2168]306 vanilla_resolved_name=`echo "$resolved" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
307 mkdir -p $outdir$resolved> /dev/null 2> /dev/null
308 rmdir $outdir$resolved > /dev/null 2> /dev/null
309 ln -sf $vanilla_resolved_name $outdir$resolved
[2341]310 LogFile "Excluding deps $resolved"
[2168]311 grep -Fvx "$resolved" "$filelist" > $filelist.tmp
[2341]312 LogFile "Replacing it with $vanilla_resolved_name"
[2168]313 echo "$vanilla_resolved_name" >> $filelist.tmp
314 mv -f $filelist.tmp $filelist
315 done
[2446]316 progress=$(($progress+1))
317 LogProgress $progress $noof_lines
[747]318 done
[925]319 $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
[747]320 mv -f $filelist.tmp $filelist
321 echo -e "$DONE"
322}
323
324
325FindAndAddUserKeyboardMappingFile() {
326 local r res mapfile mappath included_item included_list keyfile mp locale
[2445]327 LogFile "Analyzing your keyboard's configuration."
[747]328 KEYDIR=/lib/kbd
329 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware
330 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
331 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
[1713]332 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
333 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole-setup
[747]334 if [ ! -e "$KEYDIR" ] ; then
[2341]335 LogAll "Keyboard mapping directory not found. I shall use default map at boot-time."
[747]336 return 0
337 fi
[2445]338 LogFile "Adding the following keyboard mapping tables: "
[747]339 if [ -e "/etc/sysconfig/keyboard" ] ; then
[2341]340 LogFile "Red Hat-style config detected."
[747]341 keyfile=/etc/sysconfig/keyboard
342 elif [ -e "/etc/rc.d/rc.keymap" ] ; then
[2341]343 LogFile "Slackware-style config detected."
[747]344 keyfile=/etc/rc.d/rc.keymap
345 elif [ -e "/etc/rc.config" ] ; then
[2341]346 LogFile "Debian-style config detected."
[747]347 keyfile=/etc/rc.config
348 elif [ -e "/etc/console/boottime.kmap.gz" ] ; then
[2341]349 LogFile "Debian-style config detected."
[747]350 mkdir -p $bigdir/tmp
[2488]351 echo "/etc/console/boottime.kmap.gz" > $MINDI_CACHE/KEYMAP-LIVES-HERE
[747]352 KBDEPTH=0
353 mkdir -p $bigdir/etc/console
[963]354 cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
[747]355 echo -e "$DONE"
356 return 0
[1713]357 elif [ -e "/etc/console-setup/boottime.kmap.gz" ] ; then
[2341]358 LogFile "Ubuntu-style config detected."
[1713]359 mkdir -p $bigdir/tmp
[2488]360 echo "/etc/console-setup/boottime.kmap.gz" > $MINDI_CACHE/KEYMAP-LIVES-HERE
[1713]361 KBDEPTH=0
362 mkdir -p $bigdir/etc/console-setup
363 cp /etc/console-setup/boottime.kmap.gz $bigdir/etc/console-setup 2>> $LOGFILE
364 echo -e "$DONE"
365 return 0
[1465]366 elif [ -e "/etc/conf.d/keymaps" ] ; then
[2341]367 LogFile "Gentoo-style config detected."
[1465]368 keyfile=/etc/conf.d/keymaps
[747]369 else
[2445]370 LogAll "Searching for rc.config ..."
[747]371 keyfile=`find /etc -name rc.config | head -n1`
372 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
[2341]373 LogAll "Unknown config detected. Default keyboard map will be used."
[747]374 return
375 else
[2341]376 LogFile "Found $keyfile"
[747]377 fi
378 fi
379 if [ ! -e "$KEYDIR/keymaps" ] ; then
[2341]380 LogAll "Keyboard mapping directory not found. Default keyboard map will be used."
[747]381 return
382 fi
[2341]383 LogFile "keyfile=$keyfile"
[747]384 locale=`grep -F KEYTABLE "$keyfile" | tr -d '"' |cut -d'=' -f2`
385 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware
[1465]386 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | tr -d '"' |cut -d'=' -f2` # Gentoo
[2341]387 LogFile "locale=$locale"
[1764]388 #
389 # Process the keymaps dir once for all
390 # AddKeyboardMappingFile will use it recursively
391 #
392 find $KEYDIR/keymaps > $MINDI_TMP/keymaps.find
393 mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep -F "/${locale}." | grep -vx " *#.*"`
394 [ ! "$mp" ] && mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
[747]395 # If we have multiple keymaps then log it !!
[2445]396 echo "$mp" | grep -q " " >> $LOGFILE
[747]397 if [ $? -eq 0 ]; then
[2341]398 LogAll "WARNING: Multiple keymaps found: $mp"
399 LogFile "The following one will be used"
[747]400 fi
401 for i in $mp ; do
402 mappath=$i
403 [ -e "$i" ] && [ ! -d "$i" ] && break
404 done
405 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
[1854]406 mappath=$(find / -name "*/kbd/keymaps/*/$locale")
[747]407 fi
[2341]408 LogFile "mappath = $mappath"
[747]409 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
[2341]410 LogAll "Keyboard mapping file not found. Default keyboard map will be used."
[747]411 return
412 fi
413 mkdir -p $bigdir/tmp
[2488]414 echo "$mappath" > $MINDI_CACHE/KEYMAP-LIVES-HERE
[2055]415 KBDEPTH=0
[747]416 AddKeyboardMappingFile $mappath
417 echo -e "$DONE"
[1764]418 rm -f $MINDI_TMP/keymaps.find
[747]419 return 0
420}
421
422
423FindIsolinuxBinary() {
424 ISOLINUX=/usr/lib/isolinux.bin
425 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
[1491]426 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
[747]427 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
428 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
[1491]429 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
[1854]430 [ ! -e "$ISOLINUX" ] && ISOLINUX=`find / -name isolinux.bin | grep -x "/.*/isolinux.bin"`
[747]431 [ ! -e "$ISOLINUX" ] && Die "Please install isolinux first. If your syslinux RPM doesn't include isolinux, you may download an isolinux RPM from Mondo's website - go to http://www.mondorescue.com and click on 'Download'"
[2341]432 LogFile "Found isolinux.bin at $ISOLINUX"
[747]433}
434
435
436FindSpecificModuleInPath() {
[2462]437 local modpaths line
438
[747]439 if [ ! -e "$1" ] ; then
[2341]440 LogAll "WARNING - cannot search specific path '$1'"
[747]441 return 1
442 fi
443 modpaths=`find $1 -name $2.*o -type f`
444 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
445 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
446 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
447 echo "$modpaths"
448}
449
450
451GenerateGiantDependencyList() {
452 local incoming loc fname list_of_files i tempfile outfile progress filelist res r mapfile mappath included_list included_item old_pwd tempdepfile modres noof_lines lvmversion lvmresolved
453
454 echo -en "Analyzing dependency requirements"
455 outfile=$1
[940]456 tempfile=$MINDI_TMP/$$.txt
[747]457 incoming=`ReadLine`
458
459 > $tempfile
460 progress=0
461 res=0
462 noof_lines=$2
463 while [ "$incoming" != "" ] ; do
[861]464 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
465 incoming=`ReadLine`
466 continue
467 fi
468 if [ "$incoming" = "LVMFILES:" ] ; then
469 break
470 fi
[747]471 filelist=`GenerateListForFile "$incoming"`
472 r=$?
[2341]473 [ "$r" -ne "0" ] && LogAll "$incoming not found"
[747]474 res=$(($res+$r))
[2444]475# LogFile "'$incoming' generates filelist '$filelist'"
[747]476 for fname in $filelist ; do
[861]477 [ "$fname" != "" ] && echo "$fname" >> $tempfile
[747]478 done
479 progress=$(($progress+1))
[2341]480 LogProgress $progress $noof_lines
[747]481 incoming=`ReadLine`
482 done
[861]483 if [ "$incoming" = "LVMFILES:" ] ; then
484 incoming=`ReadLine`
485 lvmversion=""
486 while [ "$incoming" != "" ] ; do
487 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
488 incoming=`ReadLine`
489 continue
490 fi
491 filelist=`GenerateListForFile "$incoming"`
492 for tool in $filelist ; do
493 lvmresolved=`readlink -f $tool`
[1342]494 if [ "$tool" = "$lvmresolved" ]; then
[861]495 echo "$tool" >> $tempfile
496 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
497 if [ "$lvmversion" = "" ] ; then
498 lvmversion=`$lvmresolved`
499 echo "$lvmresolved" >> $tempfile
500 fi
501 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
[1342]502 if [ "$lvmversion" = "200" ]; then
[861]503 # pvdata and lvmcreate_initrd don't exist in LVM2
504 case "$toolstripped" in
505 "pvdata")
506 continue
507 ;;
508 "lvmcreate_initrd")
509 continue
510 ;;
511 esac
512 fi
513 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
514 if [ -e "$toolpath" ] ; then
515 echo "$toolpath" >> $tempfile
516 echo "$tool" >> $tempfile
517 else
518 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
519 fi
520 if [ -e "$toolpath" ] ; then
521 echo "$toolpath" >> $tempfile
522 echo "$tool" >> $tempfile
523 else
524 echo "Where are your LVM-Tools? Couldn't find $tool"
525 fi
526 else
527 echo "$tool" >> $tempfile
528 fi
529 done
530 progress=$(($progress+1))
[2341]531 LogProgress $progress $noof_lines
[861]532 incoming=`ReadLine`
533 done
[747]534 fi
535 echo -en "$DONE\nMaking complete dependency list"
536
537 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
538 mv -f $tempfile.new $tempfile
539 > $outfile.pre
540 progress=0
541 noof_lines=`cat $tempfile | wc -l`
[2341]542 LogFile "---------------------------------"
543 LogFile "List of dependencies: "
544 LogFile "---------------------------------"
[747]545 for fname in `cat $tempfile` ; do
[1876]546 echo "$fname" | tee -a $LOGFILE >> $outfile.pre
547 LocateDeps $fname | tee -a $LOGFILE >> $outfile.pre
[925]548 progress=$(($progress+1))
[2341]549 LogProgress $progress $noof_lines
[747]550 done
[1684]551 if [ _"$MONDO_SHARE" != _"" ]; then
[925]552 mkdir -p $bigdir/tmp
553 mkdir -p $bigdir/sbin
554 mkdir -p $bigdir/bin
[940]555 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
[2341]556 LogAll "\nIncorporating post-nuke tarball"
[925]557 old_pwd=`pwd`
558 cd $bigdir
[2341]559 tar -zxf $MINDI_TMP/post-nuke.tgz 2>> $MINDI_TMP/$$.log || LogAll "Error occurred when untarring post-nuke tarball" $MINDI_TMP/$$.log
[925]560 cd $old_pwd
[747]561 fi
[2341]562 cp -f $MINDI_TMP/BOOTLOADER.* $bigdir 2>> $LOGFILE || LogAll "\nMondo v1.2x defaults to LILO as the bootloader, BTW."
[2382]563 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[2341]564 LogAll "\nIncorporating NFS-related settings"
[2406]565 for r in NETFS-* ; do
[963]566 cp -f $MINDI_TMP/$r $bigdir/tmp 2>> $LOGFILE || Die "Cannot copy $r - did you run out of disk space?"
[2341]567 LogFile "Copying $r to ramdisk"
[925]568 done
569 fi
[747]570 fi
[925]571 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
[747]572 rm -f $tempfile $outfile.pre
573 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
574 return $res
575}
576
577
578GenerateListForFile() {
579 local files_found loc fname incoming i res
580 incoming="$1"
581 files_found=""
582 res=0
583
584 for fname in $incoming ; do
585 files_found="$files_found `LocateFile $fname`"
586 done
587
588 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
589}
590
591
592# Returns all disk devices which are part of a raid array
593GetAllRaidMembers() {
594 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
595}
596
597
598GetFileSizeList() {
599 local i
600 for i in `find $1 -type d -o -print` ; do
601 du -sk $i
602 done
603}
604
605
606GetHomeDir() {
607 local res loc
608 loc=`which $1 2>/dev/null`
609 res=`file $loc | $AWK '{print $NF;}'`
610 dirname $res
611}
612
613
[1230]614# Check kernel filesystem capabilites for accessing initrd image
[2444]615# Could be ext2 FS (old mode) or initramfs (new mode)
[1230]616#
617# Interface definition:
618# param #1: absolute path to kernel image
619GetInitrdFilesystemToUse() {
620
621 # interface test: make sure we have one parameter
622 if [ $# -ne 1 ]; then
623 Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
624 fi
625
626 # interface parameters
627 local lvKernelImage=$1
628
629 # local constants (filesystem magic strings)
630 local lcMagicCramfs="<3>cramfs: wrong magic"
[2047]631 local lcMagicExt2fs="EXT2-fs: blocksize too small for device."
[2391]632 local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device."
[2312]633 local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs...|<6>Trying to unpack rootfs image as
634initramfs"
[1230]635
636 # local variables
637 local lvOffset
638 local lvScanRes
639 local lvUseFilesystem
640
641 # say where we are.
[2495]642 LogFile " GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage"
[1230]643
644 # verify that file exists
645 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
646
[1566]647 # Kernel may be gzip compressed
[1730]648 file $lvKernelImage 2>&1 | grep -q gzip
[1566]649 if [ $? -eq 0 ]; then
[2391]650 lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicExt3fs|$lcMagicInitfs"`
[2444]651
652 # determine which filesystem to use for initrd image: ext2|3fs, gzip'ed cpio (initramfs) or cramfs
653 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then
654 lvUseFilesystem="ext2fs"
655 elif [ `echo $lvScanRes | grep -Ec "$lcMagicExt3fs"` -eq 1 ]; then
656 lvUseFilesystem="ext3fs"
657 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then
658 lvUseFilesystem="initramfs"
659 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then
660 lvUseFilesystem="cramfs"
[2395]661 else
[2444]662 lvUseFilesystem="UNSUPPORTED"
[2395]663 fi
664
[2444]665 else
666 # In that case, we are after 2.6.30 and use the supported initramfs
[1230]667 lvUseFilesystem="initramfs"
668 fi
669 # say what we are using
[2495]670 LogFile " GetInitrdFilesystemToUse(): Filesytem to use for initial ramdisk is $lvUseFilesystem."
[1230]671
672 # return file system to use
673 echo "$lvUseFilesystem"
674
675}
676
[747]677# Searches parent raid device of given disk device
678# $1: disk device (i.e. /dev/hda1)
679GetParentRaidDev() {
680 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
681}
682
683
684# Searches members of raid device
685# $1: raid device (/dev/md...)
686GetRaidDevMembers() {
687 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
688}
689
690
691ListAllPartitions() {
692 local res currline partition all_partitions ap_orig remaining i j
693
[2070]694 grep -Evx " *#.*| *none.*" $MY_FSTAB | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/\/fdd|\/cdr|\/zip|\/floppy/ {print $1}'
[747]695 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
[1824]696 if [ -e "/vmfs/volumes" ]; then
697 # For VMWare ESX 3 get the device names of these volumes
[2444]698 vdf -P | grep -E '/vmfs/volumes' | $AWK '{print $1}'
[1824]699 fi
[747]700 return
701}
702
703
704ListImagesForUser() {
705 local path fname
[1983]706 path=$MINDI_CACHE
[747]707 echo -en "In the directory '$path' you will find the images:-\n"
708 for fname in `ls $path | grep -F mindi-` ; do
709 printf "%19s " $fname
710 done
711 echo " "
712}
713
714
715ListKernelModulePaths() {
716 local module_list module fname oss r kern
[2445]717 outfile=$1
718 echo -en "Analyzing modules requirements"
[747]719 oss="/root/oss/modules"
[1399]720 module_list="$MODULES"
[1230]721 # Remove unwanted modules from list
722 for i in $DENY_MODS; do
723 module_list=`echo ${module_list} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1726]724 EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1230]725 done
[747]726###
727### Sq-Modification ... Use kernelname for module search path if specified
728###
[2462]729 if [ "${kernelname}" != "" ]
[747]730 then
731 kern=${kernelname}
732 else
[2293]733 kern="$KERVERRUN"
[747]734 fi
[2293]735 export KERVER=$kern
[747]736###
737### Sq-Mod End
738###
[2445]739 noof_lines=0
[2475]740 # Get rid of duplicates, so that if a live kernel module also appears
741 # in $EXTRA_MODS that it won't get reported as "live module file not found" twice.
742 for module in `echo $module_list $EXTRA_MODS | tr ' ' '\n' | sort -u` ; do
[2445]743 noof_lines=$(($noof_lines+1))
744 done
745 progress=0
[2475]746 for module in `echo $module_list $EXTRA_MODS | tr ' ' '\n' | sort -u` ; do
[747]747 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
[2475]748 if [ -z "$r" ]; then
749 if [ "`echo "$MODULES" | grep -w $module`" ]; then
750 r="[live module file not found]"
751 else
752 r="[extra module file not found]"
753 fi
754 fi
[2341]755 LogFile "module $module --> $r"
[2502]756 [ -f "$r" ] && echo "$r" >> $outfile
[2445]757 [ -f "$oss" ] && find $oss | grep -F $module >> $outfile
758 progress=$(($progress+1))
759 LogProgress $progress $noof_lines
[747]760 done
[2445]761 find /lib/modules/$kern/modules.* -type f 2> /dev/null >> $outfile
762 [ -f "$oss" ] && find $oss.* 2> /dev/null >> $outfile
[747]763}
764
[1784]765#
766# Critical function which computes all dependencies (dyn. lib.)
767# for a list of binaries
768#
[747]769LocateDeps() {
770 local incoming fname deps
[1724]771 incoming="$*"
[747]772 for fname in $incoming ; do
773 if [ ! -e "$fname" ] ; then
[2341]774 LogFile "WARNING - $fname does not exist; cannot be LDD'd."
[747]775 if echo $fname | grep lvm &> /dev/null ; then
[2341]776 LogFile "This warning only affects you if you are using LVM."
[1399]777 if echo "$MODULES" | grep lvm &> /dev/null ; then
[2341]778 LogFile "I think you are, so please take heed!"
[747]779 else
[2341]780 LogFile "I don't think you are, so don't worry about it."
[747]781 fi
782 fi
783 elif [ -h "$fname" ] && [ -x "$fname" ] ; then
[2341]784 LogFile "$fname is softlink"
[747]785 else
[1526]786 ldd $fname 2> /dev/null | ProcessLDD
[747]787 fi
788 done
789}
790
[925]791
[860]792# Give all symlinks recursively of a full path name
793ReadAllLink() {
[747]794
[2446]795 incoming="$*"
[747]796
[2446]797 for file in $incoming ; do
[2462]798 if [ ! -f $file ]; then
799 continue
800 fi
[2446]801 echo "$file"
802 if [ ! -h $file ]; then
803 continue
804 fi
805
806 link=`readlink -e $file`
807 d=`dirname $file`
808 fchar=`echo $link | cut -c1`
809 # If mother dir is a link print it
810 if [ -h "$d" ]; then
811 echo "$d"
812 d=`readlink -e $d`
813 fi
814 if [ "$fchar" != "/" ]; then
815 # Relative or local link
816 ReadAllLink "$d/$link"
817 else
818 # Absolute path
819 ReadAllLink $link
820 fi
821 done
[860]822}
823
[925]824
[747]825LocateFile() {
826 local i path fname_to_find location output resolved tmp stub cache_id loclist
827 fname_to_find="$1"
[1526]828 # It's an absolute path
[747]829 if echo "$fname_to_find" | grep -x "/.*" ; then
[859]830 output="$fname_to_find"
[860]831 if [ -h "$output" ] ; then
832 output="`ReadAllLink $output` $output"
833 fi
[859]834 echo "$output"
835 return 0
[747]836 fi
[1526]837 # It's not an absolute path
[747]838 output=""
[1526]839 for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin `find /usr/lib /lib /usr/local/lib /usr/X11R6/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/X11R6/lib64 -type d -maxdepth 1 2> /dev/null` ; do
840 #for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin /usr/lib /usr/lib64 /usr/lib64/* /lib /lib64 /lib64/* /usr/local/lib /usr/local/lib64 /usr/local/lib64/* /usr/X11R6/lib /usr/X11R6/lib64 /usr/X11R6/lib64/* ; do
841 [ -h "$path" ] && continue
842 [ ! -e "$path/$fname_to_find" ] && continue
843 output="$path/$fname_to_find $output"
844 if [ -h "$path/$fname_to_find" ] ; then
845 output="`ReadAllLink $path/$fname_to_find` $output"
846 fi
[747]847 done
848 if [ "$output" = "" ] ; then
[860]849 return 1
[747]850 fi
851 echo "$output"
852 return 0
853}
854
[2341]855LogProgress() {
856 local i progress modres noof_lines
857
858 progress=$1
859 noof_lines=$2
[747]860
[2341]861 echo -en "\r\t\t\t\t\t\t\t\t"
862 i=$(($progress*100))
863 i=$(($i/$noof_lines))
864 echo -en "$i"
865 echo -en "%"
866 modres=$(($progress%4))
867 [ "$modres" -eq "0" ] && echo -en "\t/"
868 [ "$modres" -eq "1" ] && echo -en "\t-"
869 [ "$modres" -eq "2" ] && echo -en "\t\\"
870 [ "$modres" -eq "3" ] && echo -en "\t|"
871}
872
873# Function to log on screen only
874LogScreen() {
[747]875 if [ -e /dev/stderr ] ; then
[925]876 echo -e "$1" >> /dev/stderr
[747]877 elif [ -e /usr/bin/logger ] ; then
[925]878 /usr/bin/logger -s $1
[747]879 fi
[2341]880}
881
882# Function to log in log file only
883LogFile() {
884
[965]885 echo -e "$1" >> $LOGFILE
[2166]886 if [ _"$2" != _"" ]; then
887 grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
888 fi
889 rm -f "$2"
[747]890}
891
[2341]892# Function to log in both screen and logfile
893LogAll() {
894 LogScreen "$1"
895 LogFile "$1" "$2"
896}
[747]897
[2341]898
[2462]899# Called by TurnTgzIntoRdz, to make mondorestore.cfg
[747]900MakeMondoConfigFile() {
901 local outfile use_lzo use_comp use_star
902 outfile=$1
903 > $outfile
904 [ "$TAPESIZE" ] && echo "media-size $TAPESIZE" >> $outfile
905 [ "$TAPEDEV" ] && echo "media-dev $TAPEDEV" >> $outfile
[1698]906 [ "$USBDEVICE" ] && echo "usb-dev $USBDEVICE" >> $outfile
[747]907 [ "$FILES_IN_FILELIST" ] && echo "files-in-filelist $FILES_IN_FILELIST" >> $outfile
908 [ "$LAST_FILELIST_NUMBER" ] && echo "last-filelist-number $LAST_FILELIST_NUMBER" >> $outfile
909 [ "$INTERNAL_TAPE_BLOCK_SIZE" ] && echo "internal-tape-block-size $INTERNAL_TAPE_BLOCK_SIZE" >> $outfile
910 use_lzo=$USE_LZO; [ "$use_lzo" = "" ] && use_lzo="no"
[998]911 use_gzip=$USE_GZIP; [ "$use_gzip" = "" ] && use_gzip="no"
[2338]912 use_lzma=$USE_LZMA; [ "$use_lzma" = "" ] && use_lzma="no"
[747]913 use_comp=$USE_COMP; [ "$use_comp" = "" ] && use_comp="yes"
914 use_star=$USE_STAR; [ "$use_star" = "" ] && use_star="no"
915 echo "use-lzo $use_lzo" >> $outfile
[2338]916 echo "use-lzma $use_lzma" >> $outfile
[747]917 echo "use-star $use_star" >> $outfile
918 echo "use-comp $use_comp" >> $outfile
919 echo "datestamp `date`" >> $outfile
920 [ "$ESTIMATED_TOTAL_NOOF_SLICES" ] && echo "total-slices $ESTIMATED_TOTAL_NOOF_SLICES" >> $outfile
[2382]921 AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-MOUNT netfs-server-mount $outfile
922 AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-PATH netfs-server-path $outfile
923 AddFileToCfgIfExists $MINDI_TMP/NETFS-DEV netfs-dev $outfile
[940]924 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
925 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME bootloader.name $outfile
926 AddFileToCfgIfExists $MINDI_TMP/TAPEDEV-HAS-DATA-DISKS tapedev-has-data-disks $outfile
[747]927}
928
929
930MakeMountlist() {
931 local scratchdir mountlist all_partitions current_partition \
932partition_size partition_format outstring partition_number \
933partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
[2013]934absolute_partition old_partition_fmt current_lvolume uname skip
[747]935
[2445]936 LogFile "------------------------------------"
[2341]937 LogFile "Your raw fstab file looks like this:"
938 LogFile "------------------------------------"
[747]939 cat $MY_FSTAB >> $LOGFILE
[2445]940 LogAll "-----------------------------------"
[2341]941 LogAll "Your mountlist will look like this:"
942 LogAll "-----------------------------------"
[747]943
944# scratchdir, mountlist(OUT)
[940]945 scratchdir=$MINDI_TMP
[747]946 mountlist=$1
947
948# NB: partition = device
949# NB: mountpt = where the device is mounted
950
951 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
952
[1684]953 [ "$mountlist" != "" ] && rm -Rf $mountlist
[747]954 > $mountlist
955 all_partitions=""
956
957 if [ $LVM != "false" ]; then
[2445]958 LogFile "Analyzing LVM..."
[2462]959 $MINDI_DATA/analyze-my-lvm > $MINDI_TMP/lvm.res
[971]960 if [ $? -ne 0 ]; then
[963]961 LVM="false"
962 fi
[2428]963 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
[747]964 fi
965 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
966# echo "all partitions = $all_partitions" > /dev/stderr
967 for i in $IMAGE_DEVS ; do
968 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
969 done
970 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
[2462]971 printf "%-15s %-15s %-15s %-15s %s\n" DEVICE MOUNTPOINT FORMAT "SIZE MB" LABEL/UUID | tee -a $LOGFILE
972 printf "%-15s %-15s %-15s %-15s %s\n" ------ ---------- ------ ------- ---------- | tee -a $LOGFILE
[747]973 useless_dev="/dev/floppy /dev/fd0h1440 /dev/fd0H1440 /dev/cdrom /dev/cdrom/cdrom /dev/cdrom/cdrom1 /dev/cdrom/cdrom2 /dev/cdrom0 /dev/cdrom1 /dev/cdrom2 /dev/cdrom3 /dev/cdrw /dev/scd /dev/ram :/ /dev/sr0 /dev/sr1 /dev/cdrom1"
974 for c_p in $all_partitions ; do
[2460]975 # Skip evices, network FS, cisf
976 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] || [ "`echo "$c_p" | grep -E "^//"`" != "" ]&& continue
[747]977 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
978 if [ -h "$c_p" ] && [ "`echo "$c_p" | grep -F "/dev/hd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/sd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/md"`" = "" ] ; then
[861]979 current_partition=`readlink -f $c_p`
[747]980 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
981 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
982 else
983 current_partition="$c_p"
984 fi
985 [ "$c_p" = "none" ] && continue
[2193]986 # Debian 5 does that
987 [ "$c_p" = "proc" ] && continue
[747]988 redhat_label=""
[1831]989 label=""
[957]990 uuid=""
[861]991 absolute_partition=`readlink -f $c_p`
[747]992 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
993
994 # Detects noauto partitions not mounted and exclude them
995 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
996 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then
997 continue
998 fi
999
[1986]1000 # set default in case we dont't find it
1001 str_to_find_fmt_with=$current_partition
1002
[747]1003 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1004 # current_partition contains only first column of /etc/fstab
1005 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
[980]1006 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
[747]1007 actual_dev=""
[853]1008
1009 # 1st try, findfs - the RHEL way of finding labels and their partitions
1010 if [ -x "/sbin/findfs" ]; then
[855]1011 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
[853]1012 fi
[747]1013
[853]1014 # 2nd try : blkid, the good way for all LABEL except swap
1015 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1016 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
[747]1017 # For LVM FS it will give a /dev/dm-# which should then be converted
[748]1018 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1019 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1020 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[747]1021 for dev in `ls /dev/mapper/*`; do
[963]1022 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1023 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[747]1024 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1025 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[747]1026 break
1027 fi
1028 done
1029 fi
1030 fi
1031
[853]1032 # 3rd try, which works on a standard partition (ext2/3), but not on swap
[747]1033 # For LVM gives a /dev/mapper entry
1034 if [ "x$actual_dev" = "x" ]; then
[980]1035 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
[747]1036 fi
1037
[853]1038 # 4th try, with vol_id
[747]1039 # SWAP only
1040 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1041 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
[747]1042 for dev_swap in $list_swaps ; do
1043 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1044 if [ "x$dev_exists" != "x" ]; then
1045 actual_dev=$dev_swap
1046 break;
1047 fi
1048 done
1049 fi
1050
[853]1051 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
[789]1052 # LABEL=SW-cciss/c0d0p3 (RDP)
[853]1053 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
[747]1054 # SWAP only
[789]1055 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
[2013]1056 skip=""
[2293]1057 uname=$KERVERRUN
[2013]1058 [ "`echo $uname | grep "2.4.[0-9]"`" != "" ] && skip=16
1059 # 2.6.12 needs 16 (FC3)
1060 [ "`echo $uname | grep "2.6.[0-1]"`" != "" ] && skip=16
1061 # 2.6.19 and upper needs 1052
1062 [ "`echo $uname | grep "2.6.19"`" != "" ] && skip=1052
1063 [ "`echo $uname | grep "2.6.[2-9]"`" != "" ] && skip=1052
1064 if [ $skip = "" ]; then
1065 Die "Your kernel is too old. I don't know how to support labelled swap spaces with it"
1066 fi
[853]1067 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1068 do
1069 # Location of the swap label for kernel 2.6
[2013]1070 try_dev_label=`dd bs=1 count=16 skip=$skip if=$try_dev 2> /dev/null`
[853]1071 if [ "x$try_dev_label" = "x$redhat_label" ]; then
[855]1072 actual_dev=$try_dev
[853]1073 fi
1074 done
[747]1075 fi
[1008]1076
1077 # Check if one of all those tries has known success
1078 if [ "x$actual_dev" != "x" ]; then
1079 current_partition=$actual_dev
1080 else
[1885]1081 Die "Your system uses a LABEL partition ($current_partition), but you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or install findfs|blkid|vol_id"
[1008]1082 fi
[957]1083 # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1084 # current_partition contains only first column of /etc/fstab
[1009]1085 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
[980]1086 uuid=`echo "$current_partition" | cut -d'=' -f2`
[957]1087 actual_dev=""
1088
1089 # 1st try, findfs - the RHEL way of finding labels and their partitions
1090 if [ -x "/sbin/findfs" ]; then
1091 actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1092 fi
1093
[1531]1094 # 2nd try : blkid, the good way for all UUID except swap
[957]1095 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1096 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
[957]1097 # For LVM FS it will give a /dev/dm-# which should then be converted
1098 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1099 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1100 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[957]1101 for dev in `ls /dev/mapper/*`; do
[963]1102 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1103 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[957]1104 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1105 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[957]1106 break
1107 fi
1108 done
1109 fi
1110 fi
1111
1112 # 3th try, with vol_id
1113 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1114 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
[957]1115 for dev in $list_dev ; do
1116 dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1117 if [ "x$dev_exists" != "x" ]; then
1118 actual_dev=$dev
1119 break;
1120 fi
1121 done
1122 fi
1123
[1531]1124 # 4th try, with dumpuuid (VMWare only ?) for swap
1125 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1126 list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1127 for dev in $list_dev ; do
1128 dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1129 if [ "x$dev_exists" != "x" ]; then
1130 actual_dev=$dev
1131 break;
1132 fi
1133 done
1134 fi
1135
[747]1136 # Check if one of all those tries has known success
1137 if [ "x$actual_dev" != "x" ]; then
1138 current_partition=$actual_dev
1139 else
[2069]1140 Die "Your system uses a UUID partition ($current_partition),\nbut you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or\ninstall findfs|blkid|vol_id or\nrelabel the partition with the correct UUID if it's a swap partition."
[747]1141 fi
1142 else
[1863]1143 # Needs to handle the recent OpenSUSE fancy way of dealing with fstab :-(
1144 # they use symlinks in fstab unrelated to what is shown in mount !
1145 if [ _"$partition_mountpt" = _"" ]; then
[1986]1146 # set default in case we dont't find it
[1863]1147 for tmpp in `tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -Ev "^#" | $AWK '{print $1}'`; do
[1864]1148 if [ _"`readlink -f $tmpp`" = _"$current_partition" ]; then
[1863]1149 str_to_find_fmt_with=$tmpp
[1865]1150 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$tmpp" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
[1864]1151 break;
[1863]1152 fi
1153 done
1154 fi
[747]1155 fi
1156
1157 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1158 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1159 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1160 # the former is then a link to the latter, so we test whether
1161 # $current_partition is actually such a link or not and set
[755]1162 # $current_lvolume accordingly. On Debian you may find more than one answer
1163 # so we remove the one corresponding to /dev/.static
1164 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1165 # principle is the same and we need to find the link to it as well.
1166 # Note that $current_lvolume may well be an
[747]1167 # ordinary device. It is just to make sure that we feed the right value
1168 # into any of the LVM tools if possible.
1169
1170 current_lvolume="$current_partition"
[763]1171 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
[755]1172 # .static dir are a Debian specificity
[763]1173 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
[755]1174 echo $current_lvolume | grep -q ' '
[784]1175 if [ $? -eq 0 ]; then
[2341]1176 LogFile "WARNING: Multiple Logical Volumes found. Report to dev team"
[755]1177 fi
[2072]1178 # if it's not found, it may well be a real device such as a multipath one
1179 # /dev/mapper/mpath... Thus we revert the situation so that next test succeed
1180 if [ _"$current_lvolume" = _"" ]; then
1181 current_lvolume="$current_partition"
1182 fi
[747]1183 fi
1184 #
1185 # End of LVM device style variation code (other than $current_lvolume).
1186
[745]1187 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1188 # Size computed via LVM not directly
[747]1189 partition_size="lvm"
1190 else
1191 partition_size=`SizeOfPartition $current_partition`
1192 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1193 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1194 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1195 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1196 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1197 [ "$partition_format" != "swap" ] && partition_format="swap"
1198 if [ "$partition_size" = "" ] ; then
1199 totalsize=0
1200 items=0
1201 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1202 totalsize=$(($totalsize+$i))
1203 items=$(($items+1))
1204 done
1205 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1206 [ "$partition_size" -lt "125000" ] && partition_size=125000
[2341]1207 LogFile "I'm guessing $c_p is $(($partition_size/1024))MB"
[747]1208 fi
1209 fi
1210 fi
1211 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1212 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1213 if [ "$partition_mountpt" = "" ] ; then
1214 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1215 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1216 partition_mountpt="raid"
1217 partition_format="raid"
1218 else
1219 partition_mountpt="lvm"
1220 partition_format="lvm"
1221 fi
1222 fi
1223 fi
1224 psz=$partition_size
[2341]1225 LogFile "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)"
[747]1226 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1227 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1228 partition_mountpt="image"
1229 old_partition_fmt=$partition_format
1230 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1231 partition_size=$(($partition_size+1)); # just in case
1232 if [ "$partition_format" = "Linux" ] ; then
[2341]1233 LogFile "Are you imaging a mounted swap partition? Silly..."
1234 LogFile "Reverting format from $old_partition_fmt to $partition_format"
[747]1235 partition_format=$old_partition_fmt
1236 fi
1237 fi
1238 if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then
[2341]1239 LogFile "Excluding $current_partition from mountlist"
[747]1240 continue
1241 fi
1242 if [ ! "$partition_mountpt" ] ; then
[2341]1243 LogFile "------- $FDISK -l $qq log ------------"
[1883]1244 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
[747]1245 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1246 [ "$partition_format" ] && break
1247 done
[2341]1248 LogFile "------- $FDISK log end ------------"
[747]1249 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1250 partition_format="compaq"
1251 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
[2341]1252 LogAll "Unable to find mountpoint of $current_partition - ignoring"
[747]1253 continue
1254 fi
1255 fi
[1755]1256 if [ "$redhat_label" ]; then
1257 label="$redhat_label"
[1756]1258 elif [ "$uuid" ]; then
[1755]1259 label="$uuid"
1260 fi
[747]1261 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
[963]1262 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
[2445]1263 unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
[747]1264 if [ "$current_partition" = "" ] ; then
[2341]1265 LogFile "Unknown partition (outstring = $unofficial_outstring)"
[747]1266 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1267 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1268 partition_mountpt=raid
1269 partition_format=raid
[2445]1270 printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
[1755]1271 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1272 else
[2341]1273 LogFile "Unknown mountpoint (outstring = $unofficial_outstring)"
[747]1274 fi
1275 elif [ "$partition_format" = "" ] ; then
[2341]1276 LogFile "Unknown format (outstring = $unofficial_outstring)"
[747]1277 elif [ "$partition_size" = "" ] ; then
[2341]1278 LogFile "Unknown partition size (outstring = $unofficial_outstring)"
[747]1279 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1280 continue
1281 else
1282 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
[2444]1283 LogFile "vfat should be used instead of dos/msdos as a partition format"
[747]1284 partition_format="vfat"
1285 fi
[2445]1286 printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
[1755]1287 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1288 fi
1289 done
[2445]1290 LogAll "-----------------------------------"
[747]1291}
1292
[2444]1293CheckMountlist() {
1294 local file=$1
1295 # Coherency verification
1296 ML0=`cat $file | wc -l`
1297 ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
1298 ML2=`$AWK '{print $2}' $file | sort -u | wc -l`
1299 if [ "$ML0" -ne "$ML1" ]; then
1300 LogFile "--------------------------------------------"
1301 echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE
1302 LogFile "--------------------------------------------"
1303 fi
1304 if [ "$ML0" -ne "$ML2" ]; then
1305 LogFile "--------------------------------------------"
1306 echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE
1307 LogFile "------------------------------------------------"
1308 fi
1309}
[747]1310
1311MakeSureNumberIsInteger() {
1312 res=`echo "$1" | tr -s '\-[0-9]' ' '`
1313 if [ "$res" != " " ] && [ "$res" != "" ] ; then
1314 echo "result = '$res'"
1315 Die "$1 should be an integer"
1316 fi
1317}
1318
1319
1320OfferToMakeBootableISO() {
1321 local i old_pwd
[2460]1322 if [ -z "$ISO_CMD" ]; then
1323 LogIt "Neither mkisofs nor genisoimage found, unable to make CD image"
1324 return
1325 fi
[1684]1326 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[966]1327 echo -en "Shall I make a bootable CD image? (y/[n]) "
[747]1328 read i
1329 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1330 fi
[940]1331 rm -Rf $MINDI_TMP/iso
[1983]1332 mkdir -p $MINDI_TMP/iso/{images,archives}
[2341]1333 cp -f $MINDI_CACHE/{*.gz,*.img} $MINDI_TMP/iso/images 2>> $LOGFILE || LogAll "OfferToMakeBootableISO: Cannot copy $MINDI_CACHE/*.gz to $MINDI_TMP/iso/images"
[2462]1334 LogFile "mindi_lib = $MINDI_DATA"
[747]1335 for i in memdisk memtest.bin memtest.img ; do
[2462]1336 j=$MINDI_DATA/$i
[1983]1337 k=$MINDI_TMP/iso
[953]1338 if [ -e "$j" ] ; then
[2341]1339 LogAll "Copying $j to $k"
[2092]1340 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1341 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
[1885]1342 if [ _"$MONDO_SHARE" != _"" ]; then
1343 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1344 fi
[953]1345 fi
[747]1346 done
[1983]1347 MakeMessageFile > $MINDI_TMP/iso/message.txt
1348 cp $kernelpath $MINDI_TMP/iso/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/iso/vmlinuz). Did you run out of disk space?"
1349 cp $MINDI_TMP/initrd.img $MINDI_TMP/iso/initrd.img 2>> $LOGFILE || Die "Cannot copy initrd.img ($MINDI_TMP/initrd.img) to $MINDI_TMP/iso/initrd.img. Did you run out of disk space?"
[1885]1350 if [ _"$MONDO_SHARE" != _"" ]; then
[1929]1351 cp $kernelpath $MONDO_ROOT/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
[1983]1352 cp $MINDI_TMP/initrd.img $MONDO_ROOT/initrd.img 2>> $LOGFILE || Die "Cannot copy initrd.img ($MINDI_TMP/initrd.img) to $MONDO_ROOT/initrd.img. Did you run out of disk space?"
[1885]1353 fi
[2073]1354 MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
[747]1355 if [ "$ARCH" != "ia64" ] ; then
[2092]1356 cp $ISOLINUX $MINDI_TMP/iso/isolinux.bin 2>> $LOGFILE || Die "Cannot copy isolinux.bin ($ISOLINUX) to $MINDI_TMP/iso - did you run out of disk space?"
[747]1357 fi
[1983]1358 old_pwd=`pwd`
[940]1359 cd $MINDI_TMP/iso
[747]1360 if [ "$ARCH" != "ia64" ] ; then
[1885]1361 if [ _"$MONDO_SHARE" != _"" ]; then
[2092]1362 cp -f $MINDI_TMP/iso/{isolinux.cfg,initrd.img,vmlinuz,isolinux.bin,message.txt} $MONDO_ROOT 2>> $LOGFILE || Die "Cannot copy core files to ramdisk for boot disk (under $MONDO_ROOT). Did you run out of disk space?"
[1983]1363 cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
[1885]1364 fi
[1983]1365 $ISO_CMD -U $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . > /dev/null 2> $MINDI_TMP/mkisofs.log
[747]1366 else
[1983]1367 $ISO_CMD $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b images/mindi-bootroot.$BOOT_SIZE.img -c images/boot.cat -no-emul-boot . > /dev/null 2> $MINDI_TMP/mkisofs.log
[1950]1368 rm -f images/mindi-bootroot.$BOOT_SIZE.img
[747]1369 fi
1370 if [ "$?" -ne "0" ] ; then
[2341]1371 LogFile "----------- $ISO_CMD's errors --------------"
[940]1372 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
[1885]1373 echo "$ISO_CMD returned the following errors:-"
[940]1374 cat $MINDI_TMP/mkisofs.log
[2341]1375 LogAll "Failed to create ISO image."
[747]1376 else
[2341]1377 LogAll "Created bootable ISO image at $MINDI_CACHE/mindi.iso"
[747]1378 fi
[940]1379 rm -f $MINDI_TMP/mkisofs.log
[747]1380 cd $old_pwd
1381}
1382
1383
[1684]1384OfferToMakeBootableUSB() {
[2041]1385 local i
[1684]1386 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[1786]1387 echo -n "Shall I make a bootable USB image ? (y/[n]) "
[1764]1388 read i
1389 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1390 if [ "$USBDEVICE" = "" ]; then
1391 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1392 read dev
1393 USBDEVICE=$dev
[1722]1394 fi
[1764]1395 echo "WARNING: This will erase all content on $USBDEVICE"
1396 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
[2040]1397 read i
1398 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
[1684]1399 fi
1400 rm -Rf $MINDI_TMP/usb
1401 mkdir -p $MINDI_TMP/usb
1402 USBPART="${USBDEVICE}1"
1403
1404 echo -en "Transforming $USBDEVICE in a Bootable device "
1405 echo -en "."
[2341]1406 LogFile "Transforming $USBDEVICE in a Bootable device"
1407 LogFile "Checking $USBDEVICE"
[1857]1408 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
[1684]1409 if [ $? -ne 0 ]; then
[2341]1410 LogAll "Unable to access $USBDEVICE"
1411 LogAll "Make sure your USB device is pluged in"
[1684]1412 exit -1
1413 fi
1414 echo -en "."
[2488]1415 # Some distro do auto mount at that point (Ubuntu)
[2462]1416 LogFile "Unmounting $USBPART just in case"
[1721]1417 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
[2057]1418 # If your key has no MBR it may cause an issue
1419 # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
[2341]1420 LogFile "Preparing $USBDEVICE"
[1721]1421 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
[2057]1422d
1423d
1424d
1425d
[1684]1426n
1427p
14281
1429
1430
1431t
1432b
1433a
14341
1435w
1436EOF
1437 if [ $? -ne 0 ]; then
[2341]1438 LogAll "Unable to create a vfat Filesystem on $USBDEVICE"
1439 LogAll "Make sure your USB device is pluged in"
[1684]1440 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1441 MindiExit -1
1442 fi
[2341]1443 LogFile "The USB device $USBDEVICE now looks like this:"
[2190]1444 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1684]1445 echo -en "."
[2462]1446 # Some distro do auto mount at that point (Ubuntu)
1447 LogFile "Unmounting $USBPART just in case again"
1448 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1449 echo -en "."
[2341]1450 LogFile "Creating a vfat filesystem on $USBPART"
[1688]1451 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
[1684]1452 if [ $? -ne 0 ]; then
[2341]1453 LogAll "Unable to create a vfat filesystem on $USBPART"
1454 LogAll "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)"
[1684]1455 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1456 MindiExit -1
1457 fi
1458 echo -en "."
[2341]1459 LogFile "Mounting $USBPART on $MINDI_TMP/usb"
[1684]1460 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1461 if [ $? -ne 0 ]; then
[2341]1462 LogAll "Unable to mount $USBPART on $MINDI_TMP/usb"
1463 LogAll "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)"
[1684]1464 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1465 MindiExit -1
1466 fi
1467 echo -en "."
[1691]1468 mkdir -p $MINDI_TMP/usb/images
[2341]1469 cp -f $MINDI_CACHE/*.img $MINDI_CACHE/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogAll "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
[1684]1470 echo -en "."
[2462]1471 LogFile "mindi_lib = $MINDI_DATA"
[1684]1472 for i in memdisk memtest.bin memtest.img ; do
[2462]1473 j=$MINDI_DATA/$i
[1684]1474 k=$MINDI_TMP/usb
1475 if [ -e "$j" ] ; then
[2341]1476 LogAll "Copying $j to $k"
[2092]1477 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1478 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
[1684]1479 fi
1480 done
1481 echo -en "."
[1983]1482 MakeMessageFile > $MINDI_TMP/usb/message.txt
[1684]1483 echo -en "."
[2092]1484 cp $kernelpath $MINDI_TMP/usb/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/usb/vmlinuz). Did you run out of disk space?"
[1684]1485 echo -en "."
[1983]1486 cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
[1684]1487 echo -en "."
[2041]1488 MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
[1684]1489 echo -en "."
[2508]1490 LogAll "----------- syslinux's conf --------------"
[2481]1491 cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
[2508]1492 LogAll "------------------------------------------"
[1721]1493 umount $MINDI_TMP/usb
[1684]1494 if [ "$ARCH" != "ia64" ] ; then
[2056]1495 syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
[1684]1496 if [ "$?" -ne "0" ] ; then
[2508]1497 LogAll "----------- syslinux's errors --------------"
[1684]1498 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
[2508]1499 LogAll "------------------------------------------"
[2341]1500 LogAll "Failed to create USB image."
[1684]1501 else
1502 echo -e "$DONE"
[2341]1503 LogFile "Created bootable USB image on $USBDEVICE"
[1684]1504 fi
1505 rm -f $MINDI_TMP/syslinux.log
1506 else
[2341]1507 echo "No USB boot support for ia64"
[1684]1508 MindiExit -1
1509 fi
1510}
1511
1512
[747]1513MakeMessageFile() {
[2293]1514
1515 if [ -x "/bin/lsb_release" ]; then
1516 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1517 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1518 # For pb >= 0.9.8
1519 DESC=`/usr/bin/pbdistrocheck -d`
[747]1520 else
[2293]1521 iss="/dev/null"
1522 [ -r /etc/issue.net ] && iss="/etc/issue.net"
1523 [ -r /etc/issue ] && iss="/etc/issue"
1524 DESC=`head -1 $iss`
[747]1525 fi
[2462]1526 sed "s/ZZZZZ/$MINDI_VERSION/" $MINDI_DATA/msg-txt | sed "s/KKKKK/Kernel $KERVER/" | sed "s/AAAAA/on a $ARCH architecture/" | sed "s/TTTTT/`LC_TIME=C date`/" | sed "s/MMMMM/`hostname`/" | sed "s/DDDDD/$DESC/"
[1885]1527 if [ _"$MONDO_SHARE" != _"" ]; then
1528 if [ "$CDRECOVERY" != "yes" ] ; then
[2382]1529 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[1885]1530 echo -en "Press <enter> to continue.\n"
1531 elif [ ! "$MINDI_TMP" ] ; then
1532 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
[2462]1533 if [ -e "$MINDI_DATA/memtest.img" ] ; then
[1983]1534 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
1535 fi
[1885]1536 else
1537 echo -en "$BOOT_MEDIA_MESSAGE"
[747]1538 fi
[1983]1539 else
1540 echo -en "\
[747]1541To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1542CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
[1983]1543 fi
[747]1544 fi
1545 echo -en "\n\n\n"
1546}
1547
1548
[1983]1549MakeBootConfFile() {
[1885]1550 local options i ooo
[747]1551 options=""
[1983]1552 # Type of boot file (elilo or syslinux/isolinux)
1553 type=$1
1554 if [ "$type" = "elilo" ]; then
1555 sep="="
1556 else
1557 sep=" "
1558 fi
[925]1559
[1983]1560 # Generic header for conf file
1561 if [ "$type" != "elilo" ] ; then
1562 echo -en "prompt 1\ndisplay message.txt\n"
1563 else
1564 echo -en "prompt\n"
[925]1565 fi
[1983]1566
1567 # Compute which default option to boot from
[747]1568 if [ "$CDRECOVERY" = "yes" ] ; then
[1983]1569 echo -en "default${sep}RESTORE\n"
1570 # In case it's mondoarchive
[1885]1571 elif [ _"$MONDO_SHARE" != _"" ]; then
[2382]1572 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[1983]1573 echo -en "default${sep}iso\n"
[747]1574 else
[1983]1575 echo -en "default${sep}interactive\n"
[747]1576 fi
1577 else
[1983]1578 echo -en "default${sep}expert\n"
[747]1579 fi
1580
[1983]1581 # Handle timeout
[747]1582 if [ "$CDRECOVERY" != "yes" ] ; then
[1983]1583 echo -en "timeout${sep}300\n"
1584 else
1585 echo -en "timeout${sep}10000\n"
[747]1586 fi
1587 echo -en "\n"
[1983]1588
[2124]1589 # prepare which labels will be generated
[747]1590 if [ "$CDRECOVERY" = "yes" ] ; then
[925]1591 options="RESTORE expert"
[1885]1592 else
1593 if [ _"$MONDO_SHARE" != _"" ]; then
[2345]1594 options="interactive expert compare iso nuke isonuke"
[747]1595 else
1596 options="expert"
[925]1597 fi
[747]1598 fi
[1983]1599
1600 # Generate rest of conf file
[747]1601 for i in $options ; do
[925]1602 ooo=$i
1603 [ "$ooo" = "RESTORE" ] && ooo="nuke"
[1983]1604 if [ "$type" = "elilo" ]; then
[2126]1605 outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/initrd.img\n\troot=/dev/ram0 append=\" rw ramdisk_size=$ramdisk_size $ooo $ADDITIONAL_BOOT_PARAMS \"\n"
[925]1606 else
[2073]1607 ps="/"
1608 if [ "$type" = "syslinux" ]; then
1609 ps=""
1610 fi
[2126]1611 outstr="label $i\n\tkernel ${ps}vmlinuz\n\tappend initrd=${ps}initrd.img root=/dev/ram0 rw ramdisk_size=$ramdisk_size ${ooo} $ADDITIONAL_BOOT_PARAMS\n"
[925]1612 fi
[1885]1613 echo -en "$outstr"
[747]1614 done
[1983]1615
[2462]1616 if [ -e "$MINDI_DATA/memtest.img" ] ; then
[1983]1617 if [ "$type" = "elilo" ]; then
1618 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
[2073]1619 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
[1983]1620 else
[2073]1621 ps="/"
1622 if [ "$type" = "syslinux" ]; then
1623 ps=""
1624 fi
1625 echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
1626 echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
[1983]1627 fi
1628 fi
[747]1629}
1630
1631
[2488]1632
1633PrepareBootDiskImage() {
1634 local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage liloconf mountefi
[1983]1635 imagesdir=$MINDI_CACHE
1636 kernelpath=$1
[2488]1637 do_boot_root_thingy=""
1638 retval=0
[747]1639
1640 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
[1885]1641 echo -en "Making "$BOOT_SIZE"KB boot disk..."
[2462]1642 TurnTgzIntoRdz $MINDI_DATA/rootfs $MINDI_TMP/initrd.img `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into initrd.img; are you SURE your kernel supports loopfs?"
[747]1643 echo -en "..."
[2488]1644 imagefile=$MINDI_CACHE/mindi-bootroot.$BOOT_SIZE.img
[940]1645 mountpoint=$MINDI_TMP/mountpoint.$$
[747]1646 mkdir -p $mountpoint
[1885]1647 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[2488]1648 LogFile "Creating vfat filesystem on $imagefile"
[1983]1649 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
[2488]1650 if [ "$ARCH" != "ia64" ] ; then
1651 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1652 # Ensure that $MINDI_CACHE is not on NFS (it shouldn't)
1653 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1654 fi
1655
[2341]1656 mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
[2488]1657
[964]1658 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]1659 mkdir -p $mountpoint/etc
[1983]1660 liloconf=$mountpoint/elilo.conf
[747]1661
[2488]1662 MakeMessageFile > $mountpoint/message.txt
[747]1663
[2488]1664 if [ "$ARCH" != "ia64" ] ; then
1665 MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1666 else
1667 MakeBootConfFile elilo > $liloconf
1668 # Copy it so that CD-ROM menu entry is satisfied
1669 mountefi=0
1670 df -T | grep /boot/efi | grep -q vfat
[1230]1671 if [ $? -ne 0 ]; then
[2488]1672 mount /boot/efi
1673 if [ $? -ne 0 ]; then
1674 echo "You have to mount your EFI partition when using mindi"
1675 MindiExit -1
1676 fi
1677 mountefi=1
[1230]1678 fi
[2488]1679 el=`find /boot/efi -name elilo.efi`
1680 cp $el $mountpoint
1681 cp $liloconf $mountpoint
1682 if [ $mountefi -eq 1 ]; then
1683 umount /boot/efi 2>&1 > /dev/null
[747]1684 fi
1685 fi
1686
[2341]1687 LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
[1983]1688 cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
[747]1689 if [ "$?" -ne "0" ] ; then
[2341]1690 LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
[940]1691 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[2341]1692 LogAll "Please unload some of your modules and try again."
[940]1693 rm -f $MINDI_TMP/mtpt.$$
[2341]1694 LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
[747]1695 retval=$(($retval+1))
1696 fi
1697
[925]1698 # copy the kernel across
[1230]1699 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]1700 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
[1796]1701 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[747]1702 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
[1885]1703 if [ "$?" -ne "0" ] ; then
[2341]1704 LogFile "Files at mountpoint ($mountpoint) :-"
[747]1705 du -sk $mountpoint/* >> $LOGFILE
[2341]1706 LogFile "--- end of list of files ---"
[747]1707 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
[1885]1708Sorry, your kernel is too big for your image.\n" >> $LOGFILE
[1998]1709 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
[747]1710 cd $old_pwd
1711 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[2341]1712 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
[747]1713
[2488]1714 rm -f $imagefile
[1885]1715 return 0
[747]1716 fi
1717 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
[2341]1718 LogFile "Free space left on image = $free_space KB"
1719 LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
[925]1720
1721 # make it bootable
[1998]1722 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
[2462]1723 [ -e "$MINDI_DATA/memdisk" ] && cp -f $MINDI_DATA/memdisk $mountpoint 2>> $LOGFILE
[2488]1724
1725 if [ "$ARCH" = "ia64" ] ; then
1726 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1727 fi
[747]1728 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1729 echo -en "..."
[2341]1730 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
[747]1731
1732 if [ "$retval" -eq "0" ] ; then
[1885]1733 echo -en "...$DONE\n"
[2488]1734 LogAll "$BOOT_SIZE KB boot disk was created OK\n"
[747]1735 else
[1885]1736 echo -en "...failed\n"
[2488]1737 LogAll "$BOOT_SIZE KB boot disk was NOT created\n"
1738 rm -f $imagefile
[747]1739 fi
[2341]1740 [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
[747]1741 return $retval
1742}
1743
1744
[2006]1745ParseModprobeForIncludes() {
1746local MODPROBE_CONF mpincfile includes include
1747
1748MODPROBE_CONF=/etc/modprobe.conf
1749mpincfile=$1
1750touch $mpincfile
1751if [ -a $MODPROBE_CONF ]; then
[2444]1752 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
[2006]1753 if [ -n "$includes" ]; then
1754 for include in $includes
1755 do
1756 if [ -a "$include" ]; then
1757 echo $include >> $mpincfile
1758 fi
1759 done
1760 fi
1761fi
1762}
1763
1764
[747]1765PrepareDataDiskImages() {
[2006]1766 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
[747]1767
[1983]1768 imagesdir=$MINDI_CACHE
[1902]1769 rm -f $imagesdir/mindi.iso
[940]1770 needlist=$MINDI_TMP/what-we-need.txt
1771 bigdir=$MINDI_TMP/bigdir
[747]1772 mkdir -p $bigdir/usr/bin
[1983]1773 mkdir -p $bigdir/usr/sbin
[2006]1774 includefile=$MINDI_TMP/$$.includefile.txt
[747]1775
[2445]1776 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
[2412]1777 if [ -e "$DEPLIST_FILE" ]; then
[2445]1778 lfiles="$DEPLIST_FILE $lfiles"
[2412]1779 fi
[1885]1780 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
[2006]1781 ParseModprobeForIncludes $includefile
[2019]1782 lines=$(($lines+`cat $includefile | wc -l`))
[2006]1783 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
[747]1784 res=$?
[2006]1785 rm -f $includefile
[2462]1786 # This function appends to the file passed in param
1787 ListKernelModulePaths $needlist
[747]1788 if [ "$res" -ne "0" ] ; then
[1902]1789 Die "You have $res files present in dependency list\nbut absent from filesystem."
[747]1790 fi
1791 FindAndAddUserKeyboardMappingFile
1792 mkdir -p $bigdir/tmp
1793 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
1794 DropOptimizedLibraries $needlist $bigdir
1795 echo -en "Assembling dependency files"
1796
[2445]1797 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
1798
[925]1799 # also copy io.sys and msdos.sys, if we can find them
[747]1800 for i in `mount | cut -d' ' -f3` ; do
[925]1801 for j in io.sys msdos.sys ; do
[963]1802 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
[925]1803 done
[747]1804 done
1805
[925]1806 # master boot record, too
[940]1807 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
[747]1808 if [ "$i" ] ; then
[2341]1809 LogAll "Backing up $i's MBR"
[925]1810 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
1811 sleep 1
1812 sync
1813 j=$i
1814 [ -h "$j" ] && j=`readlink -f $j`
[2341]1815 LogAll "Creating /dev/boot_device ($j)"
[925]1816 mkdir -p $bigdir/dev
[2089]1817 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
[747]1818 fi
1819
1820 old_pwd=`pwd`
1821 cd $bigdir
1822
[1983]1823 # Get terminfo content
1824 ti="usr/share/terminfo/l"
1825 if [ -d /$ti ]; then
1826 mkdir -p $ti
[2341]1827 cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "WARNING - error occurred while copying terminfo"
[747]1828 fi
[1764]1829 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
[747]1830 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
[1335]1831 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
[747]1832 fi
[2291]1833 if [ -d "/lib/dev-state" ]; then
[2341]1834 tar cf - -C / ./lib/dev-state 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
[2291]1835 fi
[747]1836 cd $old_pwd
1837 echo -e "$DONE"
1838 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
[2508]1839 CheckMountlist $MINDI_TMP/mountlist.txt
[1902]1840 mkdir -p $bigdir/tmp
[2032]1841 if [ $LVM != "false" ]; then
[2462]1842 $MINDI_DATA/analyze-my-lvm > $bigdir/tmp/i-want-my-lvm
[2032]1843 if [ "$?" -ne "0" ]; then
1844 LVM="false"
1845 rm -f $bigdir/tmp/i-want-my-lvm
1846 fi
1847 fi
[2444]1848
[1902]1849 if [ _"$MONDO_SHARE" != _"" ]; then
1850 for q in filelist.full.gz biggielist.txt ; do
1851 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
1852 cp -pRdf $MINDI_TMP/$q $bigdir/tmp 2>> $LOGFILE
1853 done
1854 fi
1855
1856 echo -en "Tarring and zipping the data content..."
1857 size_of_all_tools=`du -sk $bigdir | cut -f1`
[2341]1858 (cd $bigdir ; tar -b 4096 -cf - . 2>> $MINDI_TMP/$$.log | gzip -9 > $imagesdir/all.tar.gz || LogAll "Problem creating all.tar.gz" $MINDI_TMP/$$.log)
[2462]1859 LogFile "Size of the data content"
1860 LogFile "------------------------"
[1902]1861 du -sk $imagesdir/*gz >> $LOGFILE
[2462]1862 LogFile "------------------------"
[1902]1863 echo -e "$DONE"
1864
[747]1865 FRIENDLY_OUTSTRING="Boot and data disk images were created."
[1902]1866 rm -rf $bigdir
[747]1867 rm -f $needlist
1868}
1869
1870
1871ProcessLDD() {
[1784]1872 local incoming f d nd bd bnd
[747]1873 read incoming
[1784]1874 while [ "$incoming" != "" ]; do
[859]1875 # We take the full path name of the dyn. lib. we want
[2444]1876 incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
[1526]1877 for f in $incoming ; do
[1784]1878 # echo modified file name if one of the parent dir is a link
1879 # by replacing the original dirname by the destination of the link
1880 d="`dirname $f`"
1881 found="false"
1882 while [ "$d" != "/" ]; do
1883 if [ -h "$d" ]; then
1884 nd=`readlink -f $d`
1885 bd=`basename $d`
1886 bnd=`basename $nd`
1887 f=`echo $f | sed "s~/$bd/~/$bnd/~"`
1888 echo $d
1889 fi
1890 d="`dirname $d`"
1891 done
1892
[1721]1893 echo "$f"
1894 echo "`ReadAllLink $f`"
[747]1895 done
1896 read incoming
1897 done
1898}
1899
1900
1901Prompt() {
1902 echo -en "$1"
1903 read line
1904}
1905
1906
1907ReadLine() {
1908 local i incoming
1909 read incoming
1910 i=0
1911 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
[925]1912 i=$(($i+1))
1913 read incoming
[747]1914 done
1915 echo "$incoming"
1916}
1917
1918
1919SizeOfPartition() {
1920 local devpath drive res stub
1921 device=$1
1922 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
[925]1923 res=`SizeOfRaidPartition $device`
1924 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
1925 echo "$res"
1926 return 0
[747]1927 fi
[925]1928 # patch from Bill <bill@iwizard.biz> - 2003/08/25
[960]1929 res=`$FDISK -s $device 2>> $LOGFILE`
[925]1930 # end patch
[2451]1931 # take only the first in case of multiple mount (cifs, nfs, ...)
1932 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
[747]1933 [ "$res" = "" ] && res="-1"
1934 echo $res
1935 return 0
1936}
1937
1938
1939SizeOfRaidPartition() {
1940 local real_dev smallest_size silly tmp
1941
1942 silly=999999999
1943 smallest_size=$silly
1944
1945 for real_dev in `GetRaidDevMembers $1` ; do
[925]1946 tmp=`SizeOfPartition $real_dev`
1947 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
[747]1948 done
1949
1950 if [ "$smallest_size" = "$silly" ] ; then
[925]1951 echo "-1"
1952 return 1
[747]1953 else
[925]1954 echo "$smallest_size"
1955 return 0
[747]1956 fi
1957}
1958
1959
1960StripComments()
1961{
1962 local tempfile
[925]1963
[940]1964 tempfile=$MINDI_TMP/$$.strip.txt
[963]1965 cp -f $1 $tempfile 2>> $LOGFILE
[747]1966 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
1967 rm -f $tempfile
[2341]1968 LogFile "Stripped comments from $2"
[747]1969}
1970
1971
[925]1972
[747]1973StripExecutable()
1974{
1975 local tmpfile
[925]1976
[940]1977 tmpfile=$MINDI_TMP/stripped.$$.dat
[747]1978 [ -d "$1" ] || [ -h "$1" ] && return
[963]1979 cp -f $1 $tmpfile 2>> $LOGFILE
[747]1980 strip $tmpfile 2> /dev/null
1981 if [ "$?" -eq "0" ] ; then
[963]1982 cp -f $tmpfile $1 2>> $LOGFILE
[2341]1983 LogFile "Stripped binary $2"
[747]1984 fi
1985 rm -f $tmpfile
1986}
1987
[2293]1988KernelVer() {
1989 local fkern_ver fname
[747]1990
[2293]1991 fname=$1
1992 file $fname | grep -q gzip
1993 if [ "$?" -eq "0" ] ; then
1994 # Used by ia64
1995 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
1996 else
1997 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
1998 fi
1999 echo "$fkern_ver"
2000}
2001
2002
[747]2003TryToFindKernelPath() {
2004 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
[925]2005
[2293]2006 we_want_version=$KERVERRUN
[747]2007 possible_kernels=""
2008 duff_kernels=""
2009
2010 if [ "$ARCH" = "ia64" ] ; then
2011 root="/boot/efi/efi"
2012 else
2013 root="/"
2014 fi
[1466]2015 for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
[925]2016 [ ! -e "$fname" ] && continue
[747]2017 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
[2293]2018 fkern_ver=`KernelVer $fname`
[747]2019 [ "$fkern_ver" = "" ] && continue
2020 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
[925]2021 [ -f "$fname" ] || continue
2022 [ -h "$fname" ] && continue
2023 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2024 file $fname | grep -q gzip
2025 if [ "$?" -eq "0" ] ; then
2026 # Used by ia64
2027 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[2341]2028 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
[925]2029 duff_kernels="$fname $duff_kernels"
2030 else
[747]2031 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2032 possible_kernels="$fname $possible_kernels"
[925]2033 fi
[747]2034 else
[925]2035 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[2341]2036 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
[925]2037 duff_kernels="$fname $duff_kernels"
2038 else
[747]2039 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2040 possible_kernels="$fname $possible_kernels"
[925]2041 fi
[747]2042 fi
2043 done
2044 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
[925]2045 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
[747]2046 fi
2047 if [ ! "$possible_kernels" ] ; then
[2341]2048 LogAll "No kernel matches exactly. Are there any duff kernels?"
[747]2049 possible_kernels="$duff_kernels"
2050 if [ ! "$possible_kernels" ] ; then
[2341]2051 LogAll "Sorry, no duff kernels either"
[747]2052 else
[2341]2053 LogAll "I bet you're running Debian or Gentoo, aren't you?"
2054 LogAll "Your kernel doesn't have a sane builddate. Oh well..."
[747]2055 fi
2056 fi
2057 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2058 noof_kernels=`CountItemsIn "$possible_kernels"`
2059 if [ "$noof_kernels" -eq "0" ] ; then
[2341]2060 LogAll "Could not find your kernel."
[925]2061 if [ -e "/boot/vmlinuz" ] ; then
[2341]2062 LogAll "Using /boot/vmlinuz as a last resort."
[925]2063 output=/boot/vmlinuz
[747]2064 else
[925]2065 output=""
2066 fi
[747]2067 elif [ "$noof_kernels" -eq "1" ] ; then
2068 kernelpath=`echo "$possible_kernels" | sed s/' '//`
[2341]2069 LogFile "Your kernel is $kernelpath (v$KERVERRUN)"
[747]2070 output="$kernelpath"
2071 else
2072 for i in $possible_kernels ; do
[2293]2073 if echo $i | grep "$KERVERRUN" ; then
[2341]2074 LogAll "OK, I used my initiative and found that "
2075 LogAll "$i is probably your kernel. "
[925]2076 output="$i"
2077 return
2078 fi
[747]2079 done
[925]2080 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2081 output=/boot/vmlinuz
[2341]2082 LogFile "Schlomo, this one's for you."
[925]2083 else
[2341]2084 LogAll "Two or more possible kernels found. You may specify any one of them and the "
2085 LogAll "boot disks will still work, probably. If one does not work, try another."
2086 LogAll "$possible_kernels"
[747]2087 echo ""
[925]2088 fi
[747]2089 fi
2090 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2091}
2092
2093
2094TurnTgzIntoRdz() {
[2462]2095 local tgz_dir_fname rdz_fname tempfile mountpoint old_pwd nodes kernelsize res currsize not_copied j k s w needed_modules_path
[925]2096
[747]2097 tgz_dir_fname=$1
2098 rdz_fname=$2
[1983]2099 kernelsize=$3
[2462]2100 # Compute the list of all that should be copied/created on the final mountpoint under MINDI_TMP
2101 # mkdir.lis will contain the list of directries to create
2102 # cp.lis will contain the list of files/dirs to copy
2103 # ln.lis will contain the list of files to link to existing files
2104 # rm.lis will contain the list of files to remove after the copies
[2034]2105 # AL04Oct08: Check whether /lib64 is a link and if so explicitly create one in rootfs
[2042]2106 if [ -h "/lib64" ]; then
[2462]2107 echo lib >> $MINDI_TMP/mkdir.lis
2108 echo ln -s lib lib64 >> $MINDI_TMP/ln.lis
[2042]2109 fi
[2034]2110
[2462]2111 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > $MINDI_CACHE/USE-DEVFS
2112 echo $MINDI_CACHE/USE-DEVFS >> $MIDI_TMP/cp.lis
[1914]2113
[2445]2114 # We need a minimal conf in the initial ramdisk
2115 mountlis=`grep -v "^#.*" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | cut -d: -f2 | sort -u`
[2462]2116 ReadAllLink $mountlis >> $MINDI_TMP/mnt.lis
[2446]2117 LocateDeps `cat $MINDI_TMP/mnt.lis` >> $MINDI_TMP/deps.lis
[2445]2118 # Special for libs
[2446]2119 ReadAllLink `grep -E "/lib" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | grep -v "^#.*" | cut -d: -f2` >> $MINDI_TMP/deps.lis
2120
[2462]2121 echo `cat $MINDI_TMP/mnt.lis` `sort -u $MINDI_TMP/deps.lis` >> $MINDI_TMP/cp.lis
2122 rm -f $MINDI_TMP/deps.lis $MINDI_TMP/mnt.lis
[1786]2123
[2508]2124 # Copy of files mandatory for ssh to automate mount if sshfs is used
2125 mkdir $mountpoint/.ssh
2126 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2127 echo > $mountpoint/tmp/myssh << EOF
2128ssh -o StrictHostKeyChecking=no $*
2129EOF
2130 chmod 755 $mountpoint/tmp/myssh
2131
[2039]2132 # Copy of files mandatory for ld.so
[2462]2133 echo /etc/ld.so.c* >> $MINDI_TMP/cp.lis
[2039]2134
[2164]2135 # Avoid an issue on some distro (RHEL5)
[2462]2136 echo ./etc/ld.so.conf.d/kernelcap* >> $MINDI_TMP/rm.lis
[2164]2137
[2462]2138 # Need for a tmp dir
2139 echo tmp >> $MINDI_TMP/mkdir.lis
2140
[1724]2141 # Management of udev (which includes modprobe in rules)
[1759]2142 ps auxww | grep -v grep | grep -qw udevd
[1716]2143 if [ $? -eq 0 ]; then
[2462]2144 echo "udev device manager found" > $MINDI_CACHE/USE-UDEV
2145 echo $MINDI_CACHE/USE-UDEV >> $MINDI_TMP/cp.lis
[2446]2146 LogFile "udev device manager found"
[2462]2147 echo /etc/udev /lib*/udev >> $MINDI_TMP/cp.lis
[1790]2148 # This avoids NIC remapping if on another machine at restore time on Debian at least
[2462]2149 echo ./etc/udev/rules.d/z[0-9][0-9]_persistent-net.rules >> $MINDI_TMP/rm.lis
[2145]2150 # This avoids NIC remapping if on another machine at restore time on Ubuntu at least
[2462]2151 echo ./etc/udev/rules.d/[0-9][0-9]-persistent-net.rules >> $MINDI_TMP/rm.lis
[1720]2152 if [ -x /sbin/udevd ]; then
[2462]2153 # Get only the files which exist in the udev.files list
2154 # and potentially their symlink structure and their deps
2155 mountlis=`grep -Ev "^#" $MINDI_CONF/udev.files`
2156 ReadAllLink $mountlis | sort -u >> $MINDI_TMP/udev.lis
2157 LocateDeps `cat $MINDI_TMP/udev.lis` | sort -u >> $MINDI_TMP/cp.lis
2158 cat $MINDI_TMP/udev.lis >> $MINDI_TMP/cp.lis
[1721]2159 rm -f $MINDI_TMP/udev.lis
[1720]2160 else
[2341]2161 LogAll "udevd daemon not in standard place (/sbin)"
2162 LogAll "mindi will use static devices which may cause problems"
[2462]2163 rm -f $MINDI_CACHE/USE-UDEV
[1720]2164 fi
[1716]2165 fi
[1786]2166
[1761]2167 # Management of potential HW info (Proliant only at the moment)
[1880]2168 rm -rf $MINDI_CACHE/bkphw
2169 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2170 if [ -d $MINDI_CACHE/bkphw ]; then
[2341]2171 LogAll "Hardware Information found and saved ..."
[2462]2172 echo $MINDI_CACHE/bkphw >> $MIDNDI_TMP/cp.lis
[1880]2173 if [ -f $MINDI_CACHE/tools.files ]; then
2174 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
[1863]2175 LocateDeps $lis > $MINDI_TMP/tools.lis
[2462]2176 echo $lis `sort -u $MINDI_TMP/tools.lis` >> $MINDI_TMP/cp.lis
[1863]2177 fi
[1880]2178 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
[2462]2179 chmod 755 $MINDI_CACHE/mindi-rsthw
2180 echo $MINDI_CACHE/mindi-rsthw >> $MINDI_TMP/cp.lis
[1761]2181 fi
[1880]2182 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
[1761]2183 fi
2184
[2183]2185 # Management of perl scripts delivered needed at restore time
[2462]2186 mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` >> $MINDI_TMP/cp.lis
[2183]2187
[2488]2188 echo mnt/cdrom >> $MINDI_TMP/mkdir.lis
[747]2189
[2462]2190 ls /dev/fd0*[1,2][4,7,8]* >> $MINDI_TMP/cp.lis 2> /dev/null
[1721]2191
[2462]2192 if [ "${kernelname}" != "" ]
2193 then
2194 needed_modules_path=/lib/modules/${kernelname}
[747]2195 else
[2462]2196 needed_modules_path=/lib/modules/$KERVERRUN
[747]2197 fi
[1885]2198
2199 needed_modules=""
[1993]2200 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
[1885]2201
[2382]2202 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[747]2203 # For PXE boot
2204 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2205 fi
[1715]2206 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2207 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2208 fi
[1727]2209 for i in $DENY_MODS; do
[2341]2210 LogFile "Removing $i from the list of modules to load"
[1727]2211 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2212 done
2213
[2341]2214 [ -e "$needed_modules_path" ] || LogAll "path $needed_modules_path does not exist.\n If you're not using a modular kernel then you're NUTS."
[747]2215 for i in $list_of_groovy_mods ; do
[1885]2216 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
[747]2217 done
[1914]2218
[1885]2219 for i in $needed_modules ; do
[747]2220 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
[2341]2221 LogFile "Adding $i ($s KB) to the rootfs"
[2462]2222 echo $i >> $MINDI_TMP/cp.lis
[747]2223 done
[1815]2224
2225 # Also copy modules.dep in case of udev so that normal modprobe works
[2462]2226 echo $needed_modules_path/modules.dep >> $MINDI_TMP/cp.lis
[1815]2227
[2462]2228 # Manages mountlit.txt
2229 MakeMountlist $MINDI_CACHE/mountlist.txt
2230 CheckMountlist $MINDI_CACHE/mountlist.txt
2231 echo $MINDI_CACHE/mountlist.txt >> $MINDI_TMP/cp.lis
2232 cat $MINDI_CACHE/mountlist.txt >> $LOGFILE
2233 LogFile "-----------------------------------"
2234
2235 if [ ! -e "/sbin/devfsd" ] ; then
2236 LogFile "Deleting devfsd daemon from ramdisk because /sbin/devfsd not found"
2237 echo ./sbin/devfsd >> $MINDI_TMP/rm.lis
[747]2238 fi
[2462]2239
[747]2240 cd $old_pwd
[1885]2241 if [ _"$MONDO_SHARE" != _"" ]; then
[2462]2242 MakeMondoConfigFile $MINDI_CACHE/mondorestore.cfg
2243 echo $MINDI_CACHE/mondorestore.cfg >> $MINDI_TMP/cp.lis
[747]2244 fi
[2462]2245 echo proc >> $MINDI_TMP/mkdir.lis
[2444]2246
[2462]2247 # Copy of files mandatory for ssh to automate mount if sshfs is used
2248 echo .ssh >> $MINDI_TMP/mkdir.lis
2249
2250 # Now create the container and do the job
2251 tempfile=$MINDI_TMP/temp.rd
2252 mountpoint=$MINDI_TMP/mnt1
2253 res=0
2254 echo -en "..."
2255 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk ($tempfile)"
2256 echo -en "..."
2257 LogFile "Creating ext2 filesystem on $tempfile"
2258 mke2fs -b 1024 -m 0 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2259 echo -en "..."
2260 mkdir -p $mountpoint
2261 mount -t ext2 -o loop $tempfile $mountpoint || Die "Cannot loopmount $tempfile to $mountpoint! The reason may be missing support for loopfs or ext2 (or both) in the running kernel."
2262 echo -en "..."
2263 old_pwd=`pwd`
2264
2265 # First create dirs
2266 for d in `cat $MINDI_TMP/mkdir.lis`; do
2267 mkdir -p $mountpoint/$d 2>&1 >> $LOGFILE
2268 done
2269
2270 # Then copy files needed
[2488]2271 LANGUAGE=C tar cf - `cat $MINDI_TMP/cp.lis` 2> /dev/null | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
[2462]2272
2273 # Then handle links
2274 if [ -f $MINDI_TMP/ln.lis ]; then
2275 (cd $mountpoint ; bash $MINDI_TMP/ln.lis) 2>&1 >> $LOGFILE
2276 fi
2277
2278 # Finally remove useless stff
2279 (cd $mountpoint ; rm -f `cat $MINDI_TMP/rm.lis`) 2>&1 >> $LOGFILE
2280
2281 # Copy of files mandatory for ssh to automate mount if sshfs is used
2282 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2283 cat > $mountpoint/bin/myssh << EOF
2284ssh -o StrictHostKeyChecking=no $*
2285EOF
2286 chmod 755 $mountpoint/bin/myssh
2287
2288 # Finally integrate what we provide statically as part of mindi
[2488]2289 (cd $tgz_dir_fname ; LANGUAGE=C tar cf - . ) | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
[2462]2290
2291 # Extracting devices
2292 (cd $mountpoint/dev ; tar -zxf dev-entries.tgz) || Die "Cannot untar dev-entries.tgz"
2293 rm -f $mountpoint/dev/dev-entries.tgz
2294
[2444]2295 LogFile "---------------------------"
2296 LogFile "Content of initial ramdisk:"
2297 LogFile "---------------------------"
2298 (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2299 LogFile "---------------------------"
2300
[2508]2301
2302 echo "---------------------------" >> $LOGFILE
2303 echo "Content of initial ramdisk:" >> $LOGFILE
2304 echo "---------------------------" >> $LOGFILE
2305 (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2306 echo "---------------------------" >> $LOGFILE
2307
[1230]2308 # Determine what filesystem to use for initrd image
[2341]2309 LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
[1230]2310 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2311 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
[2391]2312 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ]; then
[1230]2313 # say what will be used
[2391]2314 LogFile "Creating an $gvFileSystem initrd image..."
[1230]2315 # kernel expects linuxrc in ext2 filesystem
2316 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2317 # unmount loop filesystem and create image file using the standard approach
2318 umount $mountpoint || Die "Cannot unmount $tempfile"
[1764]2319 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
[1794]2320 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
[1764]2321 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
[1799]2322 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
[1764]2323 rm -f ${rdz_fname}.tmp
[1230]2324 # log that we are done
[2341]2325 LogFile "...done."
[2391]2326 elif [ "$gvFileSystem" = "initramfs" ]; then
[1230]2327 # say what will be used
[2341]2328 LogFile "Creating a gzip'ed cpio (AKA initramfs) initrd image..."
[1230]2329 # make sure that cpio is there
2330 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2331 # go into filesystem
2332 cd $mountpoint
2333 # kernel expects init in cpio filesystem
2334 ln -sf sbin/init init
2335 # create cpio image file and unmount loop filesystem
[1929]2336 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
[1230]2337 cd $old_pwd
2338 umount $mountpoint || Die "Cannot unmount $tempfile"
2339 # log that we are done
[2341]2340 LogFile "...done."
[2391]2341 else
[1230]2342 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
[2391]2343 fi
[2488]2344 ls -al $MINDI_TMP/initrd.img > /tmp/initrd.log
[2391]2345
[747]2346 if [ "$res" -eq "0" ] ; then
2347 echo -en "..."
2348 else
2349 echo -en "\rMade an rdz WITH ERRORS. \n"
2350 fi
2351 return 0
2352}
2353
2354
2355##############################################################################
[1021]2356#----------------------------------- Main -----------------------------------#
[747]2357##############################################################################
2358
[1885]2359# Now we can create what we need
2360mkdir -p $MINDI_TMP
[747]2361
[1885]2362# Purge from potential old run
2363if [ _"$MINDI_CACHE" = _"" ]; then
2364 Die "MINDI_CACHE undefined"
2365fi
2366
2367if [ "$1" = "--printvar" ] ; then
2368 shift
2369 if [ _"$1" != _"" ] ; then
2370 set | grep -Ew "^$1" | cut -d= -f2
2371 fi
[2183]2372 exit 0
[1885]2373fi
2374
[747]2375> $LOGFILE
[2341]2376LogFile "mindi v$MINDI_VERSION"
2377LogFile "$ARCH architecture detected"
2378LogFile "mindi called with the following arguments:"
[2446]2379LogFile "$*"
[2341]2380LogFile "Start date : `date`"
2381LogFile "-----------------------------"
[747]2382
2383[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2384
[1010]2385# Log some capital variables
2386[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
[2341]2387LogFile "MONDO_SHARE = $MONDO_SHARE"
[2462]2388LogFile "MINDI_DATA = $MINDI_DATA"
[2341]2389LogFile "MINDI_SBIN = $MINDI_SBIN"
[1010]2390[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
[2341]2391LogFile "MINDI_CONF = $MINDI_CONF"
[1885]2392if [ -f $MINDI_CONFIG ]; then
[2341]2393 LogFile "-----------------------------"
2394 LogFile " Mindi configuration file "
2395 LogFile "-----------------------------"
[1885]2396 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
[2341]2397 LogFile "-----------------------------"
[1885]2398fi
[1010]2399
[1885]2400
[747]2401trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
[1010]2402
2403# Sanity checks
2404which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2405which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2406which gawk > /dev/null 2> /dev/null || Die "Gawk is missing from your computer. Please install gawk. You may find the package on Debian's website. How did I know you're running Debian? Because only Debian would be stupid enough not to include gawk in your distribution."
2407which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2408if which awk &> /dev/null ; then
2409 if ! which gawk &> /dev/null ; then
[2341]2410 LogAll "You have awk but not gawk.\nPlease note that mindi works fine with a _sane_ awk binary.\nIf your awk binary misbehaves then please contact your vendor\nor distribution's mailing list for technical support.\n"
[1010]2411 fi
2412fi
2413which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
[2222]2414[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
[1010]2415
[2293]2416[ "`echo $KERVERRUN | grep "2.4.[0-6]" | grep -v "2.4.[0-9][0-9]"`" != "" ] && echo "WARNING! Your kernel may have buggy loopfs code. Consider upgrading to 2.4.7"
[1010]2417
2418# Update the PATH variable if incomplete
2419if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2420 PATH=$PATH:/sbin:/usr/sbin
2421 export PATH
[2341]2422 LogFile "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily."
2423 LogFile "However, you may wish to ask your vendor to provide a permanent fix..."
2424 LogFile " Or you might like to call 'su -' instead of 'su', for example."
[1010]2425fi
2426
[1737]2427if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
[1010]2428 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2429fi
2430
[925]2431### BERLIOS
[747]2432### Fix as it's not mandatory on ia64
2433if [ "$ARCH" = "ia64" ] ; then
[1010]2434 if which elilo &> /dev/null ; then
2435 LILO_EXE=elilo
2436 else
[2024]2437 LILO_EXE=`which false 2> /dev/null`
[1010]2438 fi
[747]2439else
2440 FindIsolinuxBinary
2441fi
2442trap "Aborted" SIGTERM
2443DONE="\r\t\t\t\t\t\t\t\tDone. "
2444kernelpath=""
[1010]2445MONDO_ROOT=/var/cache/mondo
[747]2446mkdir -p $MONDO_ROOT
2447
2448if [ -d "/proc/lvm" ]; then
2449 # LVM v1
2450 LVMCMD=""
2451 LVM="v1"
2452elif [ -d "/dev/mapper" ]; then
2453 # LVM v2
2454 LVMCMD="lvm"
2455 LVM="v2"
2456else
2457 LVM="false"
2458fi
[2329]2459
2460if [ -e "/proc/cmdline" ]; then
2461 CMDLINE="/proc/cmdline"
2462elif [ -e "/tmp/cmdline" ]; then
2463 CMDLINE="/tmp/cmdline"
2464else
2465 CMDLINE="/dev/null"
2466fi
2467
[2341]2468LogFile "LVM set to $LVM"
2469LogFile "----------"
2470LogFile "mount result:"
2471LogFile "-------------"
[1230]2472mount >> $LOGFILE
[2341]2473LogFile "-------------"
[1315]2474if [ -e /etc/raidtab ]; then
[2341]2475 LogFile "-------------"
2476 LogFile "/etc/raidtab content:"
2477 LogFile "-------------"
[1315]2478 cat /etc/raidtab >> $LOGFILE
2479fi
[2341]2480LogFile "-------------"
2481LogFile "cat $CMDLINE"
2482LogFile "-------------"
[2329]2483cat $CMDLINE >> $LOGFILE
[2341]2484LogFile "-------------"
2485LogFile "cat /proc/swaps:"
2486LogFile "-------------"
[2014]2487cat /proc/swaps >> $LOGFILE
[2341]2488LogFile "-------------"
2489LogFile "cat /proc/partitions:"
2490LogFile "-------------"
[2015]2491cat /proc/partitions >> $LOGFILE
[2341]2492LogFile "-------------"
2493LogFile "cat /proc/filesystems:"
2494LogFile "-------------"
[2015]2495cat /proc/filesystems >> $LOGFILE
[2341]2496LogFile "-------------"
2497LogFile "lsmod result:"
2498LogFile "-------------"
[1021]2499lsmod >> $LOGFILE
[2444]2500MODULES="`cat /proc/modules | $AWK '{print $1}'`"
[1531]2501if [ -x /usr/sbin/esxcfg-module ]; then
[2341]2502 LogFile "-------------"
2503 LogFile "VMWare ESX server detected - Enabling dedicated support"
2504 LogFile "-------------"
2505 LogFile "VMWare modules"
2506 LogFile "-------------"
[1531]2507 /usr/sbin/esxcfg-module -l >> $LOGFILE
[2444]2508 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
[1497]2509fi
[2341]2510LogFile "FORCE_MODS:"
2511LogFile "-------------"
2512LogFile $FORCE_MODS
2513LogFile "-------------"
2514LogFile "DENY_MODS:"
2515LogFile "-------------"
2516LogFile $DENY_MODS
2517LogFile "-------------"
2518LogFile "df result:"
2519LogFile "----------"
[1796]2520df -T >> $LOGFILE
[2341]2521LogFile "-------------"
2522LogFile "Liste of extra modules is:"
2523LogFile "$EXTRA_MODS"
2524LogFile "-------------"
[747]2525
[1723]2526# Compute libata version
[1797]2527laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
[1723]2528# If libata v2 is used then remove ide-generic as it will perturbate boot
[1726]2529if [ "`echo $MODULES | grep libata`" ]; then
[1727]2530 if [ "$laver" = "2" ]; then
[1726]2531 DENY_MODS="$DENY_MODS ide-generic"
[2341]2532 LogFile "ide-generic removed from module list as your system uses libata v2+"
2533 LogFile "-------------"
[1726]2534 fi
[1723]2535fi
2536
[2460]2537# Check for ISO_CMD command
2538if [ ! -x $ISO_CMD ]; then
2539 echo "NOTE: No CD image (ISO file) utility found" >> $LOGFILE
2540fi
2541
[747]2542FLOPPY_WAS_MOUNTED=""
2543for mtpt in /media/floppy /mnt/floppy /floppy ; do
2544 if mount | grep -w $mtpt &> /dev/null ; then
2545 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2546 umount $mtpt
2547 fi
2548done
2549
[1684]2550#
2551# If we have a USB device we need to store info
2552# and remove it from the parameters line
2553#
[747]2554if [ "$#" -ne "0" ] ; then
[1684]2555 if [ "$1" = "--usb" ] ; then
2556 shift
2557 USBDEVICE=$1
2558 if [ _"$USBDEVICE" = _"" ]; then
2559 Die "No USB device specified"
2560 fi
2561 shift
2562 fi
2563fi
2564
2565if [ "$#" -ne "0" ] ; then
[747]2566 if [ "$1" = "--findkernel" ] ; then
2567 res=`TryToFindKernelPath`
[1336]2568 # Avoids logfile content for mondo
2569 export MONDO_SHARE=""
[747]2570 if [ "$res" = "" ] ; then
[925]2571 MindiExit -1
[747]2572 else
2573 echo "$res"
[925]2574 MindiExit 0
[747]2575 fi
[1720]2576 elif [ "$1" = "--locatedeps" ] ; then
2577 [ ! "$2" ] && Die "Please specify the binary to look at"
[2444]2578 LocateDeps $*
[1720]2579 # Avoids logfile content for mondo
2580 export MONDO_SHARE=""
2581 MindiExit $?
[1815]2582 elif [ "$1" = "--readalllink" ] ; then
2583 [ ! "$2" ] && Die "Please specify the binary to look at"
[2446]2584 shift
2585 ReadAllLink $*
[1815]2586 # Avoids logfile content for mondo
2587 export MONDO_SHARE=""
2588 MindiExit $?
[747]2589 elif [ "$1" = "--makemountlist" ] ; then
2590 [ ! "$2" ] && Die "Please specify the output file"
2591 MakeMountlist $2
[2444]2592 CheckMountlist $2
[1336]2593 # Avoids logfile content for mondo
2594 export MONDO_SHARE=""
[925]2595 MindiExit $?
2596 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2597 echo "Mindi v$MINDI_VERSION"
[1336]2598 # Avoids logfile content for mondo
2599 export MONDO_SHARE=""
[925]2600 MindiExit 0
[747]2601 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
[940]2602 MONDO_TMP=$2
2603 # Change MINDI_TMP for the one provided by mondo
2604 # So that it can get back the built files
[2153]2605 if [ _"$MONDO_TMP" = _"" ]; then
2606 Die "MONDO_TMP is empty, aborting"
2607 fi
2608 if [ _"$MONDO_TMP" = _"/" ]; then
2609 Die "MONDO_TMP is /, aborting"
2610 fi
[2092]2611 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2>> $LOGFILE
[1010]2612 rmdir $MINDI_TMP
[1486]2613 export MINDI_TMP=$MONDO_TMP
[953]2614 mkdir -p $MINDI_TMP
[2238]2615
[1696]2616 # This is the scratch dir in mondo - subdir images
[1880]2617 MINDI_CACHE=$3
[2238]2618
[925]2619 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
[747]2620###
2621### Sq-Modification...
2622### Attempt to locate kernel specific module path
2623### if module path is found then use it other wise use uname -r to set it...
2624###
2625 kernelname=`echo $kernelpath | cut -d'-' -f2-`
[2341]2626 LogAll "kernelname = $kernelname"
2627 LogAll "kernelpath = $kernelpath"
[2462]2628 if [ ! -d "/lib/modules/$kernelname" ]
[747]2629 then
[2341]2630 LogAll "Module path for ${kernelpath} not found..."
2631 LogAll "using running kernel\'s modules."
[2293]2632 kernelname=$KERVERRUN
[747]2633 else
[2341]2634 LogAll "Using modules for kernel: ${kernelname}"
[747]2635 fi
2636###
2637### end of Sq-Modification
2638###
[925]2639 TAPEDEV=$5
2640 TAPESIZE=$6
2641 FILES_IN_FILELIST=$7
2642 USE_LZO=$8
2643 CDRECOVERY=$9
[747]2644 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
2645 IMAGE_DEVS=""
2646 else
2647 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
2648 fi
[925]2649 if [ "${11}" ] ; then
2650 LILO_OPTIONS=""
[2341]2651 # LogAll "LILO will use conservative settings, to be compatible with older BIOSes."
[925]2652 fi
[2462]2653 ESTIMATED_TOTAL_NOOF_SLICES=${12}
2654 export EXCLUDE_DEVS="${13}"
2655 USE_COMP="${14}"
2656 USE_LILO="${15}"
2657 USE_STAR="${16}"
2658 INTERNAL_TAPE_BLOCK_SIZE="${17}"
2659 DIFFERENTIAL="${18}"
2660 USE_GZIP="${19}"
2661 USE_LZMA="${20}"
[747]2662 [ "$USE_COMP" = "" ] && USE_COMP=yes
[998]2663 [ "$USE_GZIP" = "" ] && USE_GZIP=no
[2338]2664 [ "$USE_LZMA" = "" ] && USE_LZMA=no
[2341]2665 [ "$TAPEDEV" ] && LogAll "This is a tape-based backup. Fine."
[925]2666 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
[747]2667 kernelname=`echo $kernelpath | cut -d'-' -f2-`
[2462]2668 if [ ! -d "/lib/modules/$kernelname" ]
[747]2669 then
[2341]2670 LogAll "Module path for ${kernelpath} not found..."
2671 LogAll "using running kernel\'s modules."
[2293]2672 kernelname=$KERVERRUN
[747]2673 else
[2341]2674 LogAll "Using modules for kernel: ${kernelname}"
[747]2675 fi
[1696]2676 # MONDO_ROOT is the real scratchdir
[1880]2677 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
[938]2678 if [ _"$MONDO_ROOT" != _"" ]; then
2679 mkdir -p $MONDO_ROOT
2680 else
2681 Die "MONDO_ROOT is undefined"
2682 fi
[747]2683 else
[2341]2684 LogScreen "Syntax: mindi (--custom ....)"
[925]2685 MindiExit -1
[747]2686 fi
2687fi
[2238]2688
2689if [ _"$MINDI_CACHE" != _"" ]; then
2690 rm -rf $MINDI_CACHE/* 2> /dev/null
2691 mkdir -p $MINDI_CACHE
2692fi
2693
[747]2694[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2695
[2462]2696LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
2697LogAll "Latest Mindi is available from http://www.mondorescue.org"
2698LogAll "------------------------------------------------------------------------------"
[2341]2699LogFile "DIFFERENTIAL = $DIFFERENTIAL"
2700LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
[747]2701
[1690]2702if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[2341]2703 LogAll "Including the generation of a Bootable USB device on $USBDEVICE"
[1684]2704fi
2705
[747]2706if [ "$kernelpath" = "" ] ; then
[1335]2707 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
[966]2708 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2709 read ch
2710 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2711 USE_OWN_KERNEL="yes"
[1809]2712 else
2713 USE_OWN_KERNEL="no"
[747]2714 fi
2715 if [ "$USE_OWN_KERNEL" = "yes" ]; then
[925]2716 kernelpath=`TryToFindKernelPath`
2717 if [ "$kernelpath" = "" ] ; then
2718 echo -n "Please enter kernel path : "
2719 read kernelpath
2720 fi
[747]2721 fi
2722fi
[2341]2723LogFile "Mindi's temp dir=$MINDI_TMP"
2724LogFile "Mindi's output dir=$MINDI_CACHE"
2725[ "$(($RANDOM%64))" -eq "0" ] && LogAll "Dude, I've looked inside your computer and it's really dusty..."
[747]2726
[1983]2727PrepareDataDiskImages
2728
[2462]2729export ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
[747]2730
[2341]2731LogFile "Ramdisk will be $ramdisk_size KB"
[2488]2732PrepareBootDiskImage $kernelpath || Die "Failed to create $ramdisk_size MB disk image."
[747]2733
[2462]2734[ -e "$MINDI_DATA/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
[747]2735...Or type 'memtest' to test your PC's RAM thoroughly.\n"
2736
[1684]2737if [ _"$MONDO_SHARE" = _"" ]; then
[1983]2738 ListImagesForUser
2739 OfferToMakeBootableISO
[1684]2740 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
[1983]2741 OfferToMakeBootableUSB
[1684]2742 fi
[2341]2743 LogAll "Finished."
[747]2744elif [ "$TAPEDEV" ] ; then
[2078]2745 if [ "$ARCH" != "ia64" ] ; then
2746 # We need to keep the img file as boot file for ia64 platform
2747 rm -f $MINDI_CACHE/{*img,*iso}
2748 else
2749 rm -f $MINDI_CACHE/*iso
2750 fi
[1898]2751 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1983]2752 OfferToMakeBootableUSB
[1898]2753 fi
[1983]2754 OfferToMakeBootableISO
[1880]2755 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
2756 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
[747]2757 else
[925]2758 Die "Cannot find all.tar.gz, to be written to tape"
[747]2759 fi
[1695]2760elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1983]2761 OfferToMakeBootableUSB
[747]2762else
[1983]2763 OfferToMakeBootableISO
[747]2764fi
2765# cleanup
[2341]2766LogAll "$FRIENDLY_OUTSTRING"
[747]2767for mtpt in $FLOPPY_WAS_MOUNTED ; do
2768 mount $mtpt
2769done
[925]2770MindiExit 0
Note: See TracBrowser for help on using the repository browser.