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