This file is indexed.

/usr/share/bootcd/bootcd2disk.lib is in bootcd 4.04.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# bootcd2disk.lib
# vim: set filetype=sh :

### Functions ###

cleanup()
{
  echo "ignoring trap"
}

check_kern()
{
  KERN_YES="y"
  [ "$INITRD" ] && KERN_YES="[m|y]" # if initrd is used, a kernel-module is enough

  date "+--- $0 %d.%m.%Y ---" > $ERRLOG
  [ "$SCRIPT" ] || echo "To see full output: tail -f $ERRLOG" | tee -a $ERRLOG

  # only call the function, if it is defined
  doit=$(egrep "^[[:space:]]*(function)*[[:space:]]*do_first" $CONFDIR/bootcd2disk.conf)
  if [ ! -z "$doit" ]; then
    echo "--- do function do_first ---" | tee -a $ERRLOG
    do_first
  fi
}

check_auto()
{
  if [ "$GRUB2" -a \
       -f /usr/sbin/grub-install -a ! -f /usr/sbin/grub -a ! -f /sbin/grub ]; then
    GRUB=""
    LILO=""
  elif [ "$GRUB" -a \( -f /sbin/grub -o -f /usr/sbin/grub \) ]; then
    GRUB2=""
    LILO=""
  elif [ "$LILO" ]; then
    GRUB2=""
    GRUB=""
  else
    warn "No GRUB2, GRUB, LILO installed/defined. System may not be bootable"
  fi
  
  if [ "$GRUB" = "auto" ]; then
    [ "$DISK0" = "auto" ] || err "If you define GRUB=auto, you have to define DISK0=auto too."
  fi

  if [ "$GRUB2" = "auto" ]; then
    [ "$DISK0" = "auto" ] || err "If you define GRUB=auto, you have to define DISK0=auto too."
  fi
  
  if [ "$SFDISK0" != "auto" ]; then
    [ "$EXT2FS" = "auto" ] && warn "To define EXT2FS=auto makes only sence if you define SFDISK0=auto too"
    [ "$EXT3FS" = "auto" ] && warn "To define EXT3FS=auto makes only sence if you define SFDISK0=auto too"
    [ "$EXT4FS" = "auto" ] && warn "To define EXT4FS=auto makes only sence if you define SFDISK0=auto too"
    [ "$SWAP" = "auto" ] && warn "To define SWAP=auto makes only sence if you define SFDISK0=auto too"
  fi
  
  if [ "$EXT2FS" != "auto" -a "$EXT3FS" != "auto" -a "$EXT4FS" != "auto" ]; then
    [ "$MOUNT" = "auto" ] && warn "To define MOUNT=auto makes only sence if you define EXT[2|3|4]FS=auto too"
    [ "$FSTAB" = "auto" ] && warn "To define FSTAB=auto makes only sence if you define EXT[2|3|4]FS=auto too"
    [ "$LILO" = "auto" ] && warn "To define LILO=auto makes only sence if you define EXT[2|3|4]FS=auto too"
    [ "$GRUB" = "auto" ] && warn "To define GRUB=auto makes only sence if you define EXT[2|3|4]FS=auto too"
    [ "$GRUB2" = "auto" ] && warn "To define GRUB2=auto makes only sence if you define EXT[2|3|4]FS=auto too"
  fi

  if [ "$MOUNT" != "auto" ]; then
    [ "$UMOUNT" = "auto" ] && warn "To define UMOUNT=auto makes only sence if you define MOUNT=auto too"
  fi
}

check_DISK0()
{
  if [ "$DISK0" = "auto" ]; then
    get_disk
    for i in $DISKVARS; do 
      eval "SFDISKOPTS$i=\"\""
      [ "$(eval "echo \"\$DISK$i\"")" ] || err "Could not automatically calculate DISK$i"
    done
    eval dbg "echo \"DISK$i=<\$DISK$i>\""
  else
    s="\([^[:space:]]\+\)[[:space:]]*\(.*\)"
    for i in $DISKVARS; do
      eval "DISK$i=\"$(eval "echo \"\$DISK$i\"" | sed "s/$s/\1/")\""
      eval "SFDISKOPTS$i=\"$(eval "echo \"\$DISK$i\"" | sed "s/$s/\2/")\""
      if [ "$(eval "echo \"\$SFDISKOPTS$i\"")" ]; then
        eval "echo \"DISK$i=<\$DISK$i> SFDISKOPTS$i=<\$SFDISKOPTS$i>\"" >>$ERRLOG
        eval dbg "echo \"DISK$i=<\$DISK$i> SFDISKOPTS$i=<\$SFDISKOPTS$i>\""
      fi
    done
  fi
}

check_SFDISK0()
{
  BOOTS=50
  if [ "$SFDISK0" = "auto" ]; then
    [ -b "$DISK0" ] || err \
      "If you define SFDISK=auto, please define DISK as auto or <block-device>"
    MEMS=`free | grep Mem | awk '{print $2}'`
    SWAPS=$(expr 2 \* $MEMS / 1024)

    # To add a 2 MB post-MBR gap for grub-2 we have to specify sices in sectors 
    # instead of megabytes
    S1A=2048
    S1S=$(expr $BOOTS \* 2048)
    S1B=$(expr $S1A + $S1S)
    S2A=$(expr $S1B + 1)
    S2S=$(expr $SWAPS \* 2048)
    S2B=$(expr $S2A + $S2S)
    S3A=$(expr $S2B + 1)
    SFDISK0="
unit: sectors
$S1A,$S1S,L
$S2A,$S2S,S
$S3A,+,L
"
    echo "auto SFDISK0=<$SFDISK0>" >>$ERRLOG
    dbg "SFDISK0=<$SFDISK0>"
  fi
}

check_EXT()
{
  local KCONF
  local EXT4PROBLEM
  local EXT3PROBLEM
  local EXT2PROBLEM

  KCONF=`echo "$KERNEL" | sed "s/vmlinu./config/"`
  EXT4PROBLEM=""
  EXT3PROBLEM=""
  EXT2PROBLEM=""

  # Give me a problem 

  [ ! -f /sbin/mkfs.ext4 ] && EXT4PROBLEM="$EXT4PROBLEM
/sbin/mkfs.ext4 not found. To use EXT4 a new version of e2fsprogs has to be
installed."

  if [ "$KCONF" ]; then
    for i in \
      "CONFIG_EXT4_FS=$KERN_YES"
    do
      [ "$(grep "^$i" $KCONF)" ] || EXT4PROBLEM="$EXT4PROBLEM
$i is not configured.  To use EXT4 some kernel options are needed. It seems
not all needed Options are build in the kernel."
    done
  fi

  [ "$RESTORECMD" = "" -a  "$GRUB2" = "" ] && EXT4PROBLEM="$EXT4PROBLEM
GRUB1 may not work with ext4. EXT4=auto. Also no special 
RESTORECMD is defined. If you really want ext4 define EXT4=yes.
"

  [ ! -f /sbin/mkfs.ext3 ] && EXT3PROBLEM="$EXT3PROBLEM
/sbin/mkfs.ext3 not found. To use EXT3 a new version of e2fsprogs has to be
installed."

echo "KCONF=<$KCONF>"
  if [ "$KCONF" ]; then
    for i in \
      "CONFIG_EXT3_FS=$KERN_YES"
    do
      [ "$(grep "^$i" $KCONF)" ] || EXT3PROBLEM="$EXT3PROBLEM
$i is not configured. To use EXT3 some kernel options are needed.
It seems not all needed Options are build in the kernel."
    done
  fi

  [ "$RESTORECMD" = "" -a  "$GRUB2" = "" ] && EXT3PROBLEM="$EXT3PROBLEM
GRUB1 may not work with ext3. EXT3=auto. Also no special 
RESTORECMD is defined. If you really want ext3 define EXT3=yes.
"
  [ ! -f /sbin/mkfs.ext2 ] && EXT2PROBLEM="$EXT2PROBLEM
/sbin/mkfs.ext2 not found. To use EXT2 a new version of e2fsprogs has to be
installed."

  if [ "$KCONF" ]; then
    for i in \
      "CONFIG_EXT2_FS=$KERN_YES"
    do
      [ "$(grep "^$i" $KCONF)" ] || EXT2PROBLEM="$EXT2PROBLEM
$i is not configured.  To use EXT2 some kernel options are needed. It seems
not all needed Options are build in the kernel."
    done
  fi

  # check if auto configuration make sence

  if [ "$EXT4FS" = "auto" -o "$EXT3FS" = "auto" -o "$EXT2FS" = "auto" ]; then
    PROBLEM="
If you define one of EXT4FS, EXT3FS or EXT2FS as auto you have to define
all of them as auto.
"
    if [ "$EXT4FS" != "auto" -o "$EXT3FS" != "auto" -o "$EXT2FS" != "auto" ]; then
      err "$PROBLEM"
    fi

    [ "$DISK0" ] || err "If you define EXT[4|3|2]FS=auto, please define DISK0 as auto or <block-device>"
  fi

  # try EXT4

  if [ "$EXT4PROBLEM" ]; then
    if [ "$EXT4FS" = "auto" ]; then
      echo "$EXT4PROBLEM => EXT4=no" >>$ERRLOG
      EXT4FS=""
    elif [ "$EXT4FS" ]; then
      warn "$EXT4PROBLEM"
    fi
  elif [ "$EXT4FS" = "auto" ]; then
    EXT4FS="DISK0P1 DISK0P3"
    EXT3FS=""
    EXT2FS=""
  fi

  # try EXT3

  if [ "$EXT3PROBLEM" ]; then
    if [ "$EXT3FS" = "auto" ]; then
      echo "$EXT3PROBLEM => EXT3=no" >>$ERRLOG
      EXT3FS=""
    elif [ "$EXT3FS" ]; then
      warn "$EXT3PROBLEM"
    fi
  elif [ "$EXT3FS" = "auto" ]; then
    EXT3FS="DISK0P1 DISK0P3"
    EXT2FS=""
  fi

  # try EXT2

  if [ "$EXT2PROBLEM" ]; then
    if [ "$EXT2FS" ]; then
      err "$EXT2PROBLEM"
    fi
  elif [ "$EXT2FS" = "auto" ]; then
    EXT2FS="DISK0P1 DISK0P3"
  fi

  EXT4FS=$(disk2real "$EXT4FS")
  EXT3FS=$(disk2real "$EXT3FS")
  EXT2FS=$(disk2real "$EXT2FS")
  echo "EXT4FS=<$EXT4FS>" >>$ERRLOG
  dbg "EXT4FS=<$EXT4FS>"
  echo "EXT3FS=<$EXT3FS>" >>$ERRLOG
  dbg "EXT3FS=<$EXT3FS>"
  echo "EXT2FS=<$EXT2FS>" >>$ERRLOG
  dbg "EXT2FS=<$EXT2FS>"
}


read_thisboot()
{
  # GRUBBOOTDIR is no longer required. (Not needed by grub-install)
  [ "$(set | grep ^GRUBBOOTDIR=)" ] || GRUBBOOTDIR=""

  # RESTORECMD may be not defined in bootcd2disk.conf
  [ "$(set | grep ^RESTORECMD=)" ] || RESTORECMD=""

  CREATEVARS="KERNEL INITRD DISABLE_CRON"
  unset $CREATEVARS
  
  [ -f /etc/bootcd/thisbootcd.conf ] && . /etc/bootcd/thisbootcd.conf

  
  [ ! -f /etc/bootcd/thisbootcd.conf ] &&
    err "No file /etc/bootcd/thisbootcd.conf"
  
  for i in $CREATEVARS; do
    [ "`set | grep ^$i=`" ] || err "$i is not set in /etc/bootcd/thisbootcd.conf"
  done
}


# This function calculates a list of disks used in bootcd2disk.conf 
# For example if DISK0, DISK1 and DISK2 it will calculate DISKVARS will
# contain 0, 1 and 2
getdiskvars()
{
  DISKVARS="$(set | sed -n "s/^DISK\([[:digit:]]\+\)=.*/\1/p")"
}
#DISK0="auto" DISK3="auto" DISK7="auto" getdiskvars
#echo "expected: DISKVARS=0 3 7"
#echo "result:   DISKVARS=$DISKVARS"
#exit 0

# replace parameter DISK to the real disk-device
disk2real()
{
  local d h1 h2 p

  h1="$1"
  for d in $DISKVARS; do

    # /dev/hda has partitions /dev/hda1 /dev/hda2 ... => p=""
    # /dev/sda has partitions /dev/sda1 /dev/sda2 ... => p=""
    # /dev/ida/c0d0 has partitions /dev/ida/c0d0p1 /dev/ida/c0d0p2 ... => p="p"
    if [ -b "$(eval "echo \"\${DISK$d}p1\"")" ]; then
      # We really found a device ending with p1 
      p="p"
    elif [ -b "$(eval "echo \"\${DISK$d}1\"")" ]; then
      # We really found a device ending with <not-p>1 
      p=""
    elif [ "$(eval "echo \"\${DISK$d}\"" | grep "[[:digit:]]$")" ]; then
      # because of udev not all devicefilese may be present
      # We guess the devicename ends with p1
      p="p"
    else
      # We guess the devicename ends not with p1
      p=""
    fi

    h2="$h1"
    h1="$(eval "echo \"$h2\" | sed -e \"s|\<DISK$d\>|\$DISK$d|g\" -e \"s|\<DISK${d}P|\${DISK$d}${p}|g\"")"
  done
  echo "$h1"
}
#echo "Expected Result: /dev/hda /dev/hda1 /dev/hda3"
#DISK0=/dev/hda; getdiskvars
#disk2real "Test Result....: DISK0 DISK0P1 DISK0P3"
#echo 
#
#echo "Expected Result: /dev/cciss/p0d0 /dev/cciss/p0d0p1 /dev/cciss/p0d0p3"
#DISK0=/dev/cciss/p0d0 ; getdiskvars
#disk2real "Test Result....: DISK0 DISK0P1 DISK0P3"
#echo
#
#echo "Expected Result: /dev/cciss/p0d0 /dev/cciss/p0d0p1 /dev/cciss/p0d0p2"
#DISK0=/dev/cciss/p0d0; getdiskvars
#disk2real "Test Result....: DISK0 DISK0P1 DISK0P2"
#echo
#
#echo "Expected Result: /dev/hda /dev/hdb1 /dev/hdc2"
#DISK0=/dev/hda; DISK1=/dev/hdb; DISK2=/dev/hdc; getdiskvars
#disk2real "Test Result....: DISK0 DISK1P1 DISK2P2"
#echo
#exit 0

# real2uuid
# Change real devices defined as UUID!<real device> to 
# <uuid of real device>
real2uuid()
{
  local h1 realdevs realdev uuid
  h1="$1"

  realdevs="$(echo "$h1" | sed -n "s/.*UUID!\([^:[:space:]]\+\).*/\1/p")"

  for realdev in $realdevs ;do
    uuid="$(blkid -o value "$realdev" | head -1)"
    if [ ! "$uuid" ]; then
      err "can not get uuid for <$realdev> with blkid"
    fi
    h1="$(echo "$h1" | sed "s|UUID!$realdev\>|$uuid|g")"
  done 

  echo "$h1"
}

get_disk()
{
  local n i
  # sfdisk -l does not allways show all disks.
  # but cat /proc/partitions shows too much.
  # If it is not found automatically it has to be defined in bootcd2disk.conf

  # exp: system with one disk /dev/sda
  AUTODISK="$(sfdisk -l 2>/dev/null | # exp: Disk /ram1/dev/sda: 1044 cylin...
    sed -n "s/^Disk \([^[:space:]]\+\):.*/\1/p" | # exp: /ram1/dev/sda
    sed "s|^/ram1/|/|" | # exp: /dev/sda
    grep -v "^/dev/fd0$" )" 

  echo "AUTODISK=<$AUTODISK>" >>$ERRLOG

  n=0
  for i in $DISKVARS; do
    n=$(($n+1))
    eval "DISK$i=\"$(echo $AUTODISK |awk "{print \$$n}")\""
  done
  for i in $DISKVARS; do eval "echo \"DISK$i=\$DISK$i\""; done >>$ERRLOG
}
#DISK0="auto"; DISK3="auto"; getdiskvars; ERRLOG=/dev/null; get_disk
#echo "expected: DISK0=/dev/...\nDISK3=/dev/..."
#echo "result:"
#for i in $DISKVARS; do eval "echo \"DISK$i=\$DISK$i\""; done
#exit 0

check_SWAP_MD_MOUNT_UMOUNT_VFAT_OPT_FSTAB_PARTITIONLABEL()
{
  local OPT

  if [ "$SWAP" = "auto" ]; then
    [ -b "$DISK0" ] || err "If you define SWAP=auto, please define DISK0 as auto or <block-device>"
    SWAP="DISK0P2"
  fi
  SWAP="$(disk2real "$SWAP")"
  echo "SWAP=<$SWAP>" >>$ERRLOG
  dbg "SWAP=<$SWAP>"

  [ "$MD" = "auto" ] && MD=""
  MD="$(disk2real "$MD")"
  echo "MD=<$MD>" >>$ERRLOG
  dbg "MD=<$MD>"
  
  if [ "$MOUNT" = "auto" ]; then
    [ -b "$DISK0" ] || err "If you define MOUNT=auto, please define DISK0 as auto or <block-device>"
    MOUNT="mount DISK0P3 /mnt/bootcd.disc; mkdir -p /mnt/bootcd.disc/boot; mount DISK0P1 /mnt/bootcd.disc/boot"
  fi
  MOUNT="$(disk2real "$MOUNT")"
  echo "MOUNT=<$MOUNT>" >>$ERRLOG
  dbg "MOUNT=<$MOUNT>"
  
  if [ "$UMOUNT" = "auto" ]; then
    [ -b "$DISK0" ] || err "If you define UMOUNT=auto, please define DISK0 as auto or <block-device>"
    UMOUNT="umount /mnt/bootcd.disc/boot; umount /mnt/bootcd.disc"
    echo "auto UMOUNT=<$UMOUNT>" >>$ERRLOG
    dbg "UMOUNT=<$UMOUNT>"
  fi
  
  VFAT="$(disk2real "$VFAT")"
  echo "VFAT=<$VFAT>" >>$ERRLOG
  dbg "VFAT=<$VFAT>"
  
  if [ "$FSTAB" = "auto" ]; then
    OPT="ext2"
    [ "$EXT3FS" ] && OPT="ext3"
    [ "$EXT4FS" ] && OPT="ext4"
    [ -b "$DISK0" ] || err "If you define FSTAB=auto, please define DISK0 as auto or <block-device>"
    FSTAB="
DISK0P1 /boot $OPT defaults 0 1
DISK0P2 none  swap sw 0 0
DISK0P3 /     $OPT defaults,errors=remount-ro 0 1
proc      /proc proc defaults 0 0
"
  fi

  FSTAB="$(disk2real "$FSTAB")"
  echo "FSTAB=<$FSTAB>" >>$ERRLOG
  dbg "FSTAB=<$FSTAB>"


  PARTITIONLABEL="$(disk2real "$PARTITIONLABEL")"
  echo "PARTITIONLABEL=<$PARTITIONLABEL>" >>$ERRLOG
  dbg "PARTITIONLABEL=<$PARTITIONLABEL>"
}

check_GRUB2_GRUB_LILO()
{
  if [ "$GRUB2" = "auto" ]; then
    GRUB2="
set lang=en
insmod gettext
set timeout=5
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue

menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os {
        insmod ext2
        set root='(hd0,1)'
        linux   /$(basename $KERNEL) root=DISK0P3 ro
        initrd  /$(basename $INITRD)
}

"
  fi

  if [ "$GRUB" = "auto" ]; then

    GRUB="
default 0
timeout 5
color   cyan/blue white/blue
title	Debian GNU/Linux
root	(hd0,0)
kernel  /$(basename $KERNEL) root=DISK0P3 ro
initrd  /$(basename $INITRD)
boot
"
  
  fi 

  GRUBDEVICEMAP="$(disk2real "$GRUBDEVICEMAP")"

  GRUB2="$(disk2real "$GRUB2")"
  echo "GRUB2=<$GRUB2>" >>$ERRLOG
  dbg GRUB2="<$GRUB2>"

  GRUB="$(disk2real "$GRUB")"
  echo "GRUB=<$GRUB>" >>$ERRLOG
  dbg GRUB="<$GRUB>"

  if [ "$LILO" = "auto" ]; then
    [ -b "$DISK0" ] || err "If you define LILO=auto, please define DISK0 as auto or <block-device>"

    LILOINITRD=""
    [ "$INITRD" ] && LILOINITRD="initrd=$INITRD"

    LILO="
boot=DISK0
delay=20
vga=0
lba32
read-only

image=/vmlinuz
  label=linux
  root=DISK0P3
  $LILOINITRD
"
  fi
  LILO="$(disk2real "$LILO")"
  echo "LILO=<$LILO>" >>$ERRLOG
  dbg LILO="<$LILO>"
}

check_OPT_LVM()
{
  if [ "$LVMGRP" -a "$LVMVOL" ]; then
    LVMGRP="$(disk2real "$LVMGRP")"
    LVMVOL="$(disk2real "$LVMVOL")"
  fi

  if [ "$IMAGEURL" ]; then  
    [ "$SWAP" ] || err "If you define IMAGEURL or \"-url\" a swap partition must be defined!"
    echo "Please verify the size of the swap partition. It must be greater then the image!" >>$ERRLOG
  fi
}