-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootinfoscript
executable file
·3221 lines (2427 loc) · 111 KB
/
bootinfoscript
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
VERSION='0.61';
RELEASE_DATE='1 April 2012';
LAST_GIT_COMMIT='';
RETRIEVAL_DATE='';
################################################################################
# #
# Copyright (c) 2009-2010 Ulrich Meierfrankenfeld #
# Copyright (c) 2011-2012 Gert Hulselmans #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to #
# deal in the Software without restriction, including without limitation the #
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or #
# sell copies of the Software, and to permit persons to whom the Software is #
# furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS #
# IN THE SOFTWARE. #
# #
################################################################################
# #
# Current developer: Gert Hulselmans #
# #
# Past developer: Ulrich Meierfrankenfeld (meierfra) (ubuntuforums.org) #
# Past contributor: caljohnsmith (ubuntuforums.org) #
# #
# Hosted at: http://sourceforge.net/projects/bootinfoscript/ #
# #
# The birth of Boot Info Script: #
# http://ubuntuforums.org/showthread.php?t=837791 #
# #
################################################################################
## Check if the script is run with bash as shell interpreter.
if [ -z "$BASH_VERSION" ] ; then
echo 'Boot Info Script needs to be run with bash as shell interpreter.' >&2;
exit 1;
fi
## Display help text ##
#
# ./bootinfoscript -h
# ./bootinfoscript -help
# ./bootinfoscript --help
help () {
cat <<- HELP
Usage Boot Info Script:
-----------------------
Run the script as sudoer:
sudo ${0} <outputfile>
or if your operating system does not use sudo:
su -
${0} <outputfile>
When running the script, without specifying an output file, all the output
is written to the file "RESULTS.txt" in the same folder as the script.
But when run from /bin, /sbin, /usr/bin, or another system folder, the file
"RESULTS.txt" is written to the home directory of the user.
When the file "RESULTS.txt" already exists, the results will be written to
"RESULTS1.txt". If "RESULTS1.txt" exists, the results will be written to
"RESULTS2.txt", ...
To get version number, release date, last git commit and git retrieval date
of this script, use (no root rights needed):
${0} -v
${0} -V
${0} --version
To get this help text, use (no root rights needed):
${0} -h
${0} -help
${0} --help
To automatically gzip a copy of the output file, use (root rights needed):
${0} -g <outputfile>
${0} --gzip <outputfile>
To write the output to stdout instead of a file, use (root rights needed):
${0} --stdout
The last development version of Boot Info Script can be downloaded, with:
(no root rights needed)
${0} --update <filename>
If no filename is specified, the file will be saved in the home dir as
"bootinfoscript_YYYY-MM-DD_hh:mm:ss".
If multiple versions of Boot Info Script are detected in the same directory,
Boot Info Script will list all versions found.
In that case you need to force Boot Info Script to run a certain version,
by adding "--this" as first argument (root rights needed):
${0} --this <outputfile>
HELP
exit 0;
}
## Download the last development version of BIS from git: ##
#
# ./bootinfoscript --update <filename>
#
# If no filename is specified, the file will be saved in the home dir as
# "bootinfoscript_YYYY-MM-DD_hh:mm:ss".
update () {
local git_bis_url='http://bootinfoscript.git.sourceforge.net/git/gitweb.cgi?p=bootinfoscript/bootinfoscript;a=blob_plain;f=bootinfoscript;hb=HEAD';
local git_commit_url='http://bootinfoscript.sourceforge.net/bis-last-commit.txt'
# Check if date is available.
if [ $(type date > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
echo '"date" could not be found.' >&2;
exit 1;
fi
# Get current UTC time in YYYY-MM-DD-hh:mm:ss format.
UTC_TIME=$(date --utc "+%Y-%m-%d %T");
if [ ! -z "$1" ] ; then
GIT_BIS_FILENAME="$1";
else
GIT_BIS_FILENAME="${HOME}/bootinfoscript_${UTC_TIME/ /_}"
fi
# Check if wget or curl is available
if [ $(type wget > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
printf '\nDownloading last development version of Boot Info Script from git:\n\n';
wget -O "${GIT_BIS_FILENAME}" "${git_bis_url}";
LAST_GIT_COMMIT=$(wget -O - "${git_commit_url}" 2> /dev/null);
elif [ $(type curl > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
printf 'Downloading last development version of Boot Info Script from git:\n\n';
curl -o "${GIT_BIS_FILENAME}" "${git_bis_url}";
LAST_GIT_COMMIT=$(curl "${git_commit_url}");
else
printf '"wget" or "curl" could not be found.\nInstall at least one of them and try again.\n' >&2;
exit 1;
fi
# Set the retrieval date in just downloaded script.
sed -i -e "4,0 s@LAST_GIT_COMMIT='';@LAST_GIT_COMMIT='${LAST_GIT_COMMIT}';@" \
-e "5,0 s/RETRIEVAL_DATE='';/RETRIEVAL_DATE='${UTC_TIME}';/" \
"${GIT_BIS_FILENAME}";
printf '\nThe development version of Boot Info Script is saved as:\n"%s"\n\n' "${GIT_BIS_FILENAME}";
exit 0;
}
## Display version, release, last git commit and git retrieval date of the script when asked: ##
#
# ./bootinfoscript -v
# ./bootinfoscript -V
# ./bootinfoscript --version
version () {
printf '\nBoot Info Script version: %s\nRelease date: %s' "${VERSION}" "${RELEASE_DATE}";
if [ ! -z "${LAST_GIT_COMMIT}" ] ; then
printf '\nLast git commit: %s\nRetrieved from git on: %s' "${LAST_GIT_COMMIT}" "${RETRIEVAL_DATE}";
fi
printf '\n\n';
exit 0;
}
## Run this version of BIS even when multiple versions are detected in the same directory?
this_BIS=0; # no=0
## Gzip a copy of the output file? ##
gzip_output=0; # off=0
## Write the output to the standard output instead of to a file? ##
stdout_output=0; # off=0
## Get arguments passed to the script. ##
process_args () {
if [ ${#@} -ge 1 ] ; then
if [ $1 = '--this' ] ; then
this_BIS=1; # run this version of BIS even if multiple versions are detected.
if [ ${#@} -ge 2 ] ; then
shift; # shift the command line parameters ($2 -> $1), so they can be processed.
else
return 0; # exit this function when only '--this' was passed.
fi
fi
# Process other arguments.
case "$1" in
-g ) gzip_output=1; if [ ! -z "$2" ] ; then LogFile_cmd="$2"; fi;;
--gzip ) gzip_output=1; if [ ! -z "$2" ] ; then LogFile_cmd="$2"; fi;;
-h ) help;;
-help ) help;;
--help ) help;;
--stdout ) stdout_output=1;;
--update ) update "$2";;
-v ) version;;
-V ) version;;
--version ) version;;
-* ) help;;
* ) LogFile_cmd="$1";;
esac
fi
}
## Get arguments passed to the script. ##
process_args ${@};
## Display version number, release and git retrieval date. ##
printf '\nBoot Info Script %s [%s]' "${VERSION}" "${RELEASE_DATE}";
if [ ! -z "${LAST_GIT_COMMIT}" ] ; then
printf '\n Last git commit: %s\n Retrieved from git on: %s' "${LAST_GIT_COMMIT}" "${RETRIEVAL_DATE}";
fi
printf '\n\n';
## Check whether Boot Info Script is run with root rights or not. ##
if [ $(type whoami > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
echo 'Please install "whoami" and run Boot Info Script again.' >&2;
exit 1;
elif [ $(whoami) != 'root' ] ; then
cat <<- EOF >&2
Please use "sudo" or become "root" to run this script.
Run the script as sudoer:
sudo ${0} <outputfile>
or if your operating system does not use sudo:
su -
${0} <outputfile>
For more info, see the help:
${0} --help
EOF
exit 1;
fi
## Check if all necessary programs are available. ##
# Programs that are in /bin or /usr/bin.
Programs='
basename
cat
chown
dd
dirname
expr
fold
grep
gzip
hexdump
ls
mkdir
mktemp
mount
printf
pwd
rm
sed
sort
umount
wc'
# Programs that are in /usr/sbin or /sbin.
Programs_SBIN='
blkid
fdisk
filefrag
losetup'
Check_Prog=1;
for Program in ${Programs} ${Programs_SBIN}; do
if [ $(type ${Program} > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
echo "\"${Program}\" could not be found." >&2;
Check_Prog=0;
fi
done
## Can we decompress a LZMA stream? ##
#
# The Grub2 (v1.99) core_dir string is contained in a LZMA stream.
# See if we have xz or lzma installed to decompress the stream.
#
if [ $(type xz > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
UNLZMA='xz --format=lzma --decompress';
elif [ $(type lzma > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
UNLZMA='lzma -cd';
else
UNLZMA='none';
fi
## Do we have gawk? ##
#
# If we don't have gawk, look for "busybox awk".
#
# Make a variable named ${TAB}, needed for setting the separator for awk to a tab.
TAB=$(printf "\t");
# Set awk binary to gawk.
AWK='gawk';
if [ $(type gawk > /dev/null 2>&1 ; echo $?) -ne 0 ] ; then
# Do we have a busybox version?
for BUSYBOX in 'busybox' '/usr/lib/initramfs-tools/bin/busybox' ; do
# And if we have one, does is support "awk"?
if [ $(type ${BUSYBOX} > /dev/null 2>&1 ; echo $?) -eq 0 ] && [ $(echo 'test' | ${BUSYBOX} awk '{ print $0 }' > /dev/null 2>&1; echo $?) -eq 0 ] ; then
printf '\n"gawk" could not be found, using "%s awk" instead.\nThis may lead to unreliable results.\n\n' "${BUSYBOX}" >&2;
# Set awk binary to busybox's awk.
AWK="${BUSYBOX} awk";
break;
fi
done
# If no busybox (or one without awk support) is found, "${AWK}" is still set to "gawk".
if [ "${AWK}" == 'gawk' ] ; then
echo '"gawk" could not be found.' >&2;
Check_Prog=0;
fi
fi
if [ ${Check_Prog} -eq 0 ] ; then
printf '\nPlease install the missing program(s) and run Boot Info Script again.\n' >&2;
exit 1;
fi
## Check if there are other bootinfoscript files in the same directory. ##
#
# This can be useful when BIS was downloaded multiple times with Firefox, Chromium, ...
# Those browsers will add a suffix to the filename, when there was already
# a file with the same name:
#
# bootinfoscript(<number>)
#
# To force BIS to run a certain version, add "--this" as first argument:
#
# ./bootinfoscript --this <outputfile>
#
if [ ${this_BIS} -eq 0 ] ; then
declare -a BIS_files;
BIS_files=( $(ls "$(dirname "$0")/bootinfoscript" "$(dirname \"$0\")"/bootinfoscript\(*\) 2> /dev/null) );
if [ "${#BIS_files[*]}" -ge 2 ] ; then
printf 'Multiple bootinfoscript files where found:\n\n';
for i in ${!BIS_files[@]} ; do
eval $(echo 'BIS_'$(grep -m1 '^VERSION' "${BIS_files[$i]}") );
printf " - ${BIS_files[$i]}:\tversion ${BIS_VERSION}\n";
done
printf '\nAre you sure you want to run this version? If so, run:\n\n %s --this %s\n\n' "$0" "$*";
exit 1;
fi
fi
## List of folders which might contain files used for chainloading. ##
Boot_Codes_Dir='
/
/NST/
'
## List of files whose names will be displayed, if found. ##
Boot_Prog_Normal='
/bootmgr /BOOTMGR
/boot/bcd /BOOT/bcd /Boot/bcd /boot/BCD /BOOT/BCD /Boot/BCD
/Windows/System32/winload.exe /WINDOWS/system32/winload.exe /WINDOWS/SYSTEM32/winload.exe /windows/system32/winload.exe
/Windows/System32/Winload.exe /WINDOWS/system32/Winload.exe /WINDOWS/SYSTEM32/Winload.exe /windows/system32/Winload.exe
/grldr /GRLDR /grldr.mbr /GRLDR.MBR
/ntldr /NTLDR
/NTDETECT.COM /ntdetect.com
/NTBOOTDD.SYS /ntbootdd.sys
/wubildr /ubuntu/winboot/wubildr
/wubildr.mbr /ubuntu/winboot/wubildr.mbr
/ubuntu/disks/root.disk
/ubuntu/disks/home.disk
/ubuntu/disks/swap.disk
/core.img /grub/core.img /boot/grub/core.img /grub2/core.img /boot/grub2/core.img
/burg/core.img /boot/burg/core.img
/ldlinux.sys /syslinux/ldlinux.sys /boot/syslinux/ldlinux.sys
/extlinux.sys /extlinux/extlinux.sys /boot/extlinux/extlinux.sys
/boot/map /map
/DEFAULT.MNU /default.mnu
/IO.SYS /io.sys
/MSDOS.SYS /msdos.sys
/KERNEL.SYS /kernel.sys
/DELLBIO.BIN /dellbio.bin /DELLRMK.BIN /dellrmk.bin
/COMMAND.COM /command.com
'
Boot_Prog_Fat='
/bootmgr
/boot/bcd
/Windows/System32/winload.exe
/grldr
/grldr.mbr
/ntldr
/freeldr.sys
/NTDETECT.COM
/NTBOOTDD.SYS
/wubildr
/wubildr.mbr
/ubuntu/winboot/wubildr
/ubuntu/winboot/wubildr.mbr
/ubuntu/disks/root.disk
/ubuntu/disks/home.disk
/ubuntu/disks/swap.disk
/core.img /grub/core.img /boot/grub/core.img /grub2/core.img /boot/grub2/core.img
/burg/core.img /boot/burg/core.img
/ldlinux.sys /syslinux/ldlinux.sys /boot/syslinux/ldlinux.sys
/extlinux.sys /extlinux/extlinux.sys /boot/extlinux/extlinux.sys
/boot/map /map
/DEFAULT.MNU
/IO.SYS
/MSDOS.SYS
/KERNEL.SYS
/DELLBIO.BIN /DELLRMK.BIN
/COMMAND.COM
'
## List of files whose contents will be displayed. ##
Boot_Files_Normal='
/menu.lst /grub/menu.lst /boot/grub/menu.lst /NST/menu.lst
/grub.cfg /grub/grub.cfg /boot/grub/grub.cfg /grub2/grub.cfg /boot/grub2/grub.cfg
/burg.cfg /burg/burg.cfg /boot/burg/burg.cfg
/grub.conf /grub/grub.conf /boot/grub/grub.conf /grub2/grub.conf /boot/grub2/grub.conf
/ubuntu/disks/boot/grub/menu.lst /ubuntu/disks/install/boot/grub/menu.lst /ubuntu/winboot/menu.lst
/boot.ini /BOOT.INI
/etc/fstab
/etc/lilo.conf /lilo.conf
/syslinux.cfg /syslinux/syslinux.cfg /boot/syslinux/syslinux.cfg
/extlinux.conf /extlinux/extlinux.conf /boot/extlinux/extlinux.conf
/grldr /grub.exe
'
Boot_Files_Fat='
/menu.lst /grub/menu.lst /boot/grub/menu.lst /NST/menu.lst
/grub.cfg /grub/grub.cfg /boot/grub/grub.cfg /grub2/grub.cfg /boot/grub2/grub.cfg
/burg.cfg /burg/burg.cfg /boot/burg/burg.cfg
/grub.conf /grub/grub.conf /boot/grub/grub.conf /grub2/grub.conf /boot/grub2/grub.conf
/ubuntu/disks/boot/grub/menu.lst /ubuntu/disks/install/boot/grub/menu.lst /ubuntu/winboot/menu.lst
/boot.ini
/freeldr.ini
/etc/fstab
/etc/lilo.conf /lilo.conf
/syslinux.cfg /syslinux/syslinux.cfg /boot/syslinux/syslinux.cfg
/extlinux.conf /extlinux/extlinux.conf /boot/extlinux/extlinux.conf
/grldr /grub.exe
'
## List of files whose end point (in GiB / GB) will be displayed. ##
GrubError18_Files='
menu.lst grub/menu.lst boot/grub/menu.lst NST/menu.lst
ubuntu/disks/boot/grub/menu.lst
grub.conf grub/grub.conf boot/grub/grub.conf grub2/grub.conf boot/grub2/grub.conf
grub.cfg grub/grub.cfg boot/grub/grub.cfg grub2/grub.cfg boot/grub2/grub.cfg
burg.cfg burg/burg.cfg boot/burg/burg.cfg
core.img grub/core.img boot/grub/core.img grub2/core.img boot/grub2/core.img
burg/core.img boot/burg/core.img
stage2 grub/stage2 boot/grub/stage2
boot/vmlinuz* vmlinuz* ubuntu/disks/boot/vmlinuz*
boot/initrd* initrd* ubuntu/disks/boot/initrd*
boot/kernel*.img
initramfs* boot/initramfs*
'
SyslinuxError_Files='
syslinux.cfg syslinux/syslinux.cfg boot/syslinux/syslinux.cfg
extlinux.conf extlinux/extlinux.conf boot/extlinux/extlinux.conf
ldlinux.sys syslinux/ldlinux.sys boot/syslinux/ldlinux.sys
extlinux.sys extlinux/extlinux.sys boot/extlinux/extlinux.sys
*.c32 syslinux/*.c32 boot/syslinux/*.c32
extlinux/*.c32 boot/extlinux/*.c32
'
## Set output filename ##
if [ ${stdout_output} -eq 1 ] ; then
# The LogFile name is not used when --stdout is specified.
LogFile="";
elif ( [ ! -z "${LogFile_cmd}" ]) ; then
# The RESULTS filename is specified on the commandline.
LogFile=$(basename "${LogFile_cmd}");
# Directory where the RESULTS file will be stored.
Dir=$(dirname "${LogFile_cmd}");
# Check if directory exists.
if [ ! -d "${Dir}" ] ; then
echo "The directory \"${Dir}\" does not exist.";
echo 'Create the directory or specify another path for the output file.';
exit 1;
fi
Dir=$(cd "${Dir}"; pwd);
LogFile="${Dir}/${LogFile}";
else
# Directory containing this script.
Dir=$(cd "$(dirname "$0")"; pwd);
# Set ${Dir} to the home folder of the current user if the script is
# in one of the system folders.
# This allows placement of the script in /bin, /sbin, /usr/bin, ...
# while still having a normal location to write the output file to.
for systemdir in /bin /boot /cdrom /dev /etc /lib /lost+found /opt /proc /sbin /selinux /srv /sys /usr /var; do
if [ $(expr "${Dir}" : ${systemdir}) -ne 0 ] ; then
Dir="${HOME}";
break;
fi
done
# To avoid overwriting existing files, look for a non-existing file:
# RESULT.txt, RESULTS1.txt, RESULTS2.txt, ...
LogFile="${Dir}/RESULTS";
while ( [ -e "${LogFile}${j}.txt" ] ) ; do
if [ x"${j}" = x'' ]; then
j=0;
fi
j=$((${j}+1));
wait;
done
LogFile="${LogFile}${j}.txt"; ## The RESULTS file. ##
fi
## Redirect stdout to RESULT File ##
#
# exec 6>&1
# exec > "${LogFile}"
## Create temporary directory ##
Folder=$(mktemp -t -d BootInfo-XXXXXXXX);
## Create temporary filenames. ##
cd ${Folder}
Log=${Folder}/Log # File to record the summary.
Log1=${Folder}/Log1 # Most of the information which is not part of
# the summary is recorded in this file.
Error_Log=${Folder}/Error_Log # File to catch all unusal Standar Errors.
Trash=${Folder}/Trash # File to catch all usual Standard Errors these
# messagges will not be included in the RESULTS.
Mount_Error=${Folder}/Mount_Error # File to catch Mounting Errors.
Unknown_MBR=${Folder}/Unknown_MBR # File to record all unknown MBR and Boot sectors.
Tmp_Log=${Folder}/Tmp_Log # File to temporarily hold some information.
core_img_file=${Folder}/core_img # File to temporarily store an embedded core.img of grub2.
core_img_file_unlzma=${Folder}/core_img_unlzma # File to temporarily store the uncompressed part of core.img of grub2.
PartitionTable=${Folder}/PT # File to store the Partition Table.
FakeHardDrives=${Folder}/FakeHD # File to list devices which seem to have no corresponding drive.
BLKID=${Folder}/BLKID # File to store the output of blkid.
## Redirect all standard error to the file Error_Log. ##
exec 2> ${Error_Log};
## List of all hard drives ##
#
# Support more than 26 drives.
All_Hard_Drives=$(ls /dev/hd[a-z] /dev/hd[a-z][a-z] /dev/sd[a-z] /dev/sd[a-z][a-z] 2>> ${Trash});
## Add found RAID disks to list of hard drives. ##
if [ $(type dmraid >> ${Trash} 2>> ${Trash} ; echo $?) -eq 0 ] ; then
InActiveDMRaid=$(dmraid -si -c);
if [ x"${InActiveDMRaid}" = x"no raid disks" ] ; then
InActiveDMRaid='';
fi
if [ x"${InActiveDMRaid}" != x'' ] ; then
dmraid -ay ${InActiveDMRaid} >> ${Trash};
fi
if [ x"$(dmraid -sa -c)" != x"no raid disks" ] ; then
All_DMRaid=$(dmraid -sa -c | ${AWK} '{ print "/dev/mapper/"$0 }');
All_Hard_Drives="${All_Hard_Drives} ${All_DMRaid}";
fi
fi
## Arrays to hold information about Partitions: ##
#
# name, starting sector, ending sector, size in sector, partition type,
# filesystem type, UUID, kind(Logical, Primary, Extended), harddrive,
# boot flag, parent (for logical partitions), label,
# system(the partition id according the partition table),
# the device associated with the partition.
declare -a NamesArray StartArray EndArray SizeArray TypeArray FileArray UUIDArray KindArray DriveArray BootArray ParentArray LabelArray SystemArray DeviceArray;
## Arrays to hold information about the harddrives. ##
declare -a HDName FirstPartion LastPartition HDSize HDMBR HDHead HDTrack HDCylinder HDPT HDStart HDEnd HDUUID;
## Array for hard drives formatted as filesystem. ##
declare -a FilesystemDrives;
PI=-1; ## Counter for the identification number of a partition. (each partition gets unique number) ##
HI=0; ## Counter for the identification number of a hard drive. (each hard drive gets unique number) ##
PTFormat='%-10s %4s%14s%14s%14s %3s %s\n'; ## standard format (hexdump) to use for partition table. ##
## Get total number of blocks on a device. ##
#
# Sometimes "fdisk -s" seems to malfunction or isn't supported (busybox fdisk),
# so use "sfdisk -s" if available.
# If sfdisk isn't available, calculate the number of blocks from the number of
# sectors (divide by 2).
fdisks () {
if [ $(type sfdisk >> ${Trash} 2>> ${Trash} ; echo $?) -eq 0 ] ; then
sfdisk -s "$1" 2>> ${Trash};
else
# Calculate the number of blocks from the number of sectors (divide by 2).
fdisk -lu "$1" 2>> ${Trash} | awk '$0 ~ /, .*, .*, .*/ { print $(NF - 1) / 2 }';
fi
}
## A function which checks whether a file is on a mounted partition. ##
# List of mount points for devices: also allow mount points with spaces.
MountPoints=$(mount \
| ${AWK} -F "${TAB}" '{ if ( ($1 ~ "^/dev") && ($3 != "/") ) { sub(" on ", "\t", $0); sub(" type ", "\t", $0); print $2 } }' \
| sort -u);
FileNotMounted () {
local File=$1 curmp=$2;
IFS_OLD="${IFS}"; # Save original IFS.
IFS=$'\012'; # Set IFS temporarily to newline only, so mount points with spaces can be processed too.
for mp in ${MountPoints}; do
if [ $(expr match "${File}" "${mp}/" ) -ne 0 ] && [ "${mp}" != "${curmp}" ] ; then
IFS="${IFS_OLD}"; # Restore original IFS.
return 1;
fi
done
IFS="${IFS_OLD}"; # Restore original IFS.
return 0;
}
## Function which converts the two digit hexcode to the partition type. ##
#
# The following list is taken from sfdisk -T and
# http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
# is work in progress.
HexToSystem () {
local type=$1 system;
case ${type} in
0) system='Empty';;
1) system='FAT12';;
2) system='XENIX root';;
3) system='XENIX /usr';;
4) system='FAT16 <32M';;
5) system='Extended';;
6) system='FAT16';;
7) system='NTFS / exFAT / HPFS';;
8) system='AIX bootable';;
9) system='AIX data';;
a) system='OS/2 Boot Manager';;
b) system='W95 FAT32';;
c) system='W95 FAT32 (LBA)';;
e) system='W95 FAT16 (LBA)';;
f) system='W95 Extended (LBA)';;
10) system='OPUS';;
11) system='Hidden FAT12';;
12) system='Compaq diagnostics';;
14) system='Hidden FAT16 < 32M';;
16) system='Hidden FAT16';;
17) system='Hidden NTFS / HPFS';;
18) system='AST SmartSleep';;
1b) system='Hidden W95 FAT32';;
1c) system='Hidden W95 FAT32 (LBA)';;
1e) system='Hidden W95 FAT16 (LBA)';;
24) system='NEC DOS';;
27) system='Hidden NTFS (Recovery Environment)';;
2a) system='AtheOS File System';;
2b) system='SyllableSecure';;
32) system='NOS';;
35) system='JFS on OS/2';;
38) system='THEOS';;
39) system='Plan 9';;
3a) system='THEOS';;
3b) system='THEOS Extended';;
3c) system='PartitionMagic recovery';;
3d) system='Hidden NetWare';;
40) system='Venix 80286';;
41) system='PPC PReP Boot';;
42) system='SFS';;
44) system='GoBack';;
45) system='Boot-US boot manager';;
4d) system='QNX4.x';;
4e) system='QNX4.x 2nd part';;
4f) system='QNX4.x 3rd part';;
50) system='OnTrack DM';;
51) system='OnTrack DM6 Aux1';;
52) system='CP/M';;
53) system='OnTrack DM6 Aux3';;
54) system='OnTrack DM6 DDO';;
55) system='EZ-Drive';;
56) system='Golden Bow';;
57) system='DrivePro';;
5c) system='Priam Edisk';;
61) system='SpeedStor';;
63) system='GNU HURD or SysV';;
64) system='Novell Netware 286';;
65) system='Novell Netware 386';;
70) system='DiskSecure Multi-Boot';;
74) system='Scramdisk';;
75) system='IBM PC/IX';;
78) system='XOSL filesystem';;
80) system='Old Minix';;
81) system='Minix / old Linux';;
82) system='Linux swap / Solaris';;
83) system='Linux';;
84) system='OS/2 hidden C: drive';;
85) system='Linux extended';;
86) system='NTFS volume set';;
87) system='NTFS volume set';;
88) system='Linux plaintext';;
8a) system='Linux Kernel (AiR-BOOT)';;
8d) system='Free FDISK hidden Primary FAT12';;
8e) system='Linux LVM';;
90) system='Free FDISK hidden Primary FAT16 <32M';;
91) system='Free FDISK hidden Extended';;
92) system='Free FDISK hidden Primary FAT16';;
93) system='Amoeba/Accidently Hidden Linux';;
94) system='Amoeba bad block table';;
97) system='Free FDISK hidden Primary FAT32';;
98) system='Free FDISK hidden Primary FAT32 (LBA)';;
9a) system='Free FDISK hidden Primary FAT16 (LBA)';;
9b) system='Free FDISK hidden Extended (LBA)';;
9f) system='BSD/OS';;
a0) system='IBM Thinkpad hibernation';;
a1) system='Laptop hibernation';;
a5) system='FreeBSD';;
a6) system='OpenBSD';;
a7) system='NeXTSTEP';;
a8) system='Darwin UFS';;
a9) system='NetBSD';;
ab) system='Darwin boot';;
af) system='HFS / HFS+';;
b0) system='BootStar';;
b1 | b3) system='SpeedStor / QNX Neutrino Power-Safe';;
b2) system='QNX Neutrino Power-Safe';;
b4 | b6) system='SpeedStor';;
b7) system='BSDI fs';;
b8) system='BSDI swap';;
bb) system='Boot Wizard hidden';;
bc) system='Acronis BackUp';;
be) system='Solaris boot';;
bf) system='Solaris';;
c0) system='CTOS';;
c1) system='DRDOS / secured (FAT-12)';;
c2) system='Hidden Linux (PowerBoot)';;
c3) system='Hidden Linux Swap (PowerBoot)';;
c4) system='DRDOS secured FAT16 < 32M';;
c5) system='DRDOS secured Extended';;
c6) system='DRDOS secured FAT16';;
c7) system='Syrinx';;
cb) system='DR-DOS secured FAT32 (CHS)';;
cc) system='DR-DOS secured FAT32 (LBA)';;
cd) system='CTOS Memdump?';;
ce) system='DR-DOS FAT16X (LBA)';;
cf) system='DR-DOS secured EXT DOS (LBA)';;
d0) system='REAL/32 secure big partition';;
da) system='Non-FS data / Powercopy Backup';;
db) system='CP/M / CTOS / ...';;
dd) system='Dell Media Direct';;
de) system='Dell Utility';;
df) system='BootIt';;
e1) system='DOS access';;
e3) system='DOS R/O';;
e4) system='SpeedStor';;
e8) system='LUKS';;
eb) system='BeOS BFS';;
ec) system='SkyOS';;
ee) system='GPT';;
ef) system='EFI (FAT-12/16/32)';;
f0) system='Linux/PA-RISC boot';;
f1) system='SpeedStor';;
f2) system='DOS secondary';;
f4) system='SpeedStor';;
fb) system='VMware VMFS';;
fc) system='VMware VMswap';;
fd) system='Linux raid autodetect';;
fe) system='LANstep';;
ff) system='Xenix Bad Block Table';;
*) system='Unknown';;
esac
echo "${system}";
}
## Function to convert GPT's Partition Type. ##
#
# List from http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
#
# ABCDEFGH-IJKL-MNOP-QRST-UVWXYZabcdef is stored as
# GHEFCDAB-KLIJ-OPMN-QRST-UVWXYZabcdef (without the dashes)
#
# For easy generation of the following list:
# - Save list in a file "Partition_type_GUIDs.txt" in the folowing format:
#
# Partition Type (OS) <TAB> GUID
# Partition Type (OS) <TAB> GUID
# Partition Type (OS) <TAB> GUID
#
# - Then run the following:
#
# gawk -F '\t' '{ GUID=tolower($2); printf " %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s) system=\"%s\";;\n", substr(GUID,7,1), substr(GUID,8,1), substr(GUID,5,1), substr(GUID,6,1), substr(GUID,3,1), substr(GUID,4,1), substr(GUID,1,1), substr(GUID,2,1), substr(GUID,12,1), substr(GUID,13,1), substr(GUID,10,1), substr(GUID,11,1), substr(GUID,17,1), substr(GUID,18,1), substr(GUID,15,1), substr(GUID,16,1), substr(GUID,20,4), substr(GUID,25,12), $1 } END { print " *) system='-';" }' Partition_type_GUIDs.txt
#
# - Some GUIDs are not unique for one OS. To find them, you can run:
#
# gawk -F "\t" '{print $2}' GUID_Partition_Table_list.txt | sort | uniq -d | grep -f - GUID_Partition_Table_list.txt
#
# Basic data partition (Windows) EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
# Data partition (Linux) EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
# ZFS (Mac OS X) 6A898CC3-1DD2-11B2-99A6-080020736631
# /usr partition (Solaris) 6A898CC3-1DD2-11B2-99A6-080020736631
#
UUIDToSystem () {
local type=$1 system;
case ${type} in
00000000000000000000000000000000) system='Unused entry';;
41ee4d02e733d3119d690008c781f39f) system='MBR partition scheme';;
28732ac11ff8d211ba4b00a0c93ec93b) system='EFI System partition';;
4861682149646f6e744e656564454649) system='BIOS Boot partition';;
## GUIDs that are not unique for one OS ##
a2a0d0ebe5b9334487c068b6b72699c7) system='Data partition (Windows/Linux)';;
c38c896ad21db21199a6080020736631) system='ZFS (Mac OS X) or /usr partition (Solaris)';;
## Windows GUIDs ##
16e3c9e35c0bb84d817df92df00215ae) system='Microsoft Reserved Partition (Windows)';;
# Same GUID as old GUID for "Basic data partition (Linux)"
# a2a0d0ebe5b9334487c068b6b72699c7) system='Basic data partition (Windows)';;
aac808588f7ee04285d2e1e90434cfb3) system='Logical Disk Manager metadata partition (Windows)';;
a0609baf3114624fbc683311714a69ad) system='Logical Disk Manager data partition (Windows)';;
a4bb94ded106404da16abfd50179d6ac) system='Windows Recovery Environment (Windows)';;
90fcaf377def964e91c32d7ae055b174) system='IBM General Parallel File System (GPFS) partition (Windows)';;
## HP-UX GUIDs ##
1e4c8975eb3ad311b7c17b03a0000000) system='Data partition (HP-UX)';;
28e7a1e2e332d611a6827b03a0000000) system='Service Partition (HP-UX)';;
## Linux GUIDs ##
# Same GUID as "Basic data partition (Windows)" GUID
# a2a0d0ebe5b9334487c068b6b72699c7) system='Data partition (Linux)';;
# New GUID to avoid that Linux partitions show up as unformatted partitions in Windows.
af3dc60f838472478e793d69d8477de4) system='Data partition (Linux)';;
0f889da1fc053b4da006743f0f84911e) system='RAID partition (Linux)';;
6dfd5706aba4c44384e50933c84b4f4f) system='Swap partition (Linux)';;
79d3d6e607f5c244a23c238f2a3df928) system='Logical Volume Manager (LVM) partition (Linux)';;
3933a68d0700c060c436083ac8230908) system='Reserved (Linux)';;
## FreeBSD GUIDs ##
9d6bbd83417fdc11be0b001560b84f0f) system='Boot partition (FreeBSD)';;
b47c6e51cf6ed6118ff800022d09712b) system='Data partition (FreeBSD)';;
b57c6e51cf6ed6118ff800022d09712b) system='Swap partition (FreeBSD)';;
b67c6e51cf6ed6118ff800022d09712b) system='Unix File System (UFS) partition (FreeBSD)';;
b87c6e51cf6ed6118ff800022d09712b) system='Vinum volume manager partition (FreeBSD)';;
ba7c6e51cf6ed6118ff800022d09712b) system='ZFS partition (FreeBSD)';;
## Mac OS X GUIDs ##
005346480000aa11aa1100306543ecac) system='Hierarchical File System Plus (HFS+) partition (Mac OS X)';;
005346550000aa11aa1100306543ecac) system='Apple UFS (Mac OS X)';;
# c38c896ad21db21199a6080020736631) system='ZFS (Mac OS X)';;
444941520000aa11aa1100306543ecac) system='Apple RAID partition (Mac OS X)';;
444941524f5faa11aa1100306543ecac) system='Apple RAID partition offline (Mac OS X)';;
746f6f420000aa11aa1100306543ecac) system='Apple Boot partition (Mac OS X)';;
6562614c006caa11aa1100306543ecac) system='Apple Label (Mac OS X)';;
6f6365526576aa11aa1100306543ecac) system='Apple TV Recovery partition (Mac OS X)';;
## Solaris GUIDs ##
45cb826ad21db21199a6080020736631) system='Boot partition (Solaris)';;