Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #!/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 #
- # #
- # Tab width: 8 spaces #
- # #
- ################################################################################
- ## 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" insudo
- -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
- }
RAW Paste Data

