-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bart Sjerps
committed
Apr 6, 2018
1 parent
873c6b6
commit 215d7d0
Showing
12 changed files
with
1,926 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#============================================================================ | ||
# Title : Makefile | ||
# Description : Makefile for asmdisks | ||
# Author : Bart Sjerps <bart@outrun.nl> | ||
# License : GPLv3+ | ||
# --------------------------------------------------------------------------- | ||
|
||
prefix = /usr/local | ||
bindir = $(prefix)/bin | ||
mandir = $(prefix)/share/man | ||
docdir = $(prefix)/share/doc | ||
|
||
sysconfdir = /etc | ||
|
||
all: | ||
|
||
install: | ||
install -d 0755 $(bindir) | ||
install -d 0755 $(sysconfdir)/bash_completion.d | ||
install -d 0755 $(mandir)/man1 | ||
install -d 0755 $(docdir) | ||
install -m 0755 bin/asm bin/asmstat bin/diskheader bin/wipedisk $(bindir) | ||
install -m 0644 bin/asm.bash $(sysconfdir)/bash_completion.d | ||
install -m 0644 man/* $(mandir)/man1/ | ||
install -m 0444 doc/* $(docdir)/ | ||
|
||
.PHONY: install | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#============================================================================ | ||
# Title : asm.bash | ||
# Description : bash_completion file for asm script | ||
# Author : Bart Sjerps <bart@outrun.nl> | ||
# License : GPLv3+ | ||
# --------------------------------------------------------------------------- | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License at <http://www.gnu.org/licenses/> for | ||
# more details. | ||
# --------------------------------------------------------------------------- | ||
# Revision history: | ||
# 2016-10-20 : Added DSSD support | ||
# 2015-03-10 : Updated for Powerpath support | ||
# 2014-11-06 : Updated for new asm options | ||
# 2014-10-24 : Created | ||
# --------------------------------------------------------------------------- | ||
_asm() { | ||
local cur prev opts cmd | ||
lsvols() { awk '$1!="#" && NF==3 {print $1}' /etc/asmtab 2>/dev/null ; } | ||
lsdevs() { | ||
find /dev/mapper -type l 2>/dev/null | ||
find /dev -maxdepth 1 -type b -name "sd[b-z]" -o -name "sd[a-z][a-z]" -o -name "emcpower*" -o -name "dssd[0-9][0-9][0-9][0-9]" | ||
} | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
cmd="${COMP_WORDS[1]}" | ||
(( $COMP_CWORD > 3)) && return 0 | ||
if (( $COMP_CWORD == 2 )); then | ||
case $cmd in | ||
createdisk) ;; | ||
deletedisk|renamedisk) COMPREPLY=($(compgen -W "$(lsvols)" -- ${cur})) ; return 0 ;; | ||
*) return 0 ;; | ||
esac | ||
fi | ||
if (( $COMP_CWORD == 3 )); then | ||
case $cmd in | ||
createdisk) COMPREPLY=($(compgen -W "$(lsdevs)" -- ${cur})) ; return 0 ;; | ||
*) return 0 ;; | ||
esac | ||
fi | ||
opts="createdisk deletedisk renamedisk rescan scandisks listdisks disks list multi import" | ||
case ${prev} in | ||
createdisk) return 0 ;; | ||
*) ;; | ||
esac | ||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
return 0 | ||
} | ||
complete -F _asm asm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
#============================================================================ | ||
# Title : asmstat | ||
# Description : Wrapper for iostat that maps ASM devices | ||
# Author : Bart Sjerps <bart@outrun.nl> | ||
# License : GPLv3+ | ||
# --------------------------------------------------------------------------- | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License at <http://www.gnu.org/licenses/> for | ||
# more details. | ||
# --------------------------------------------------------------------------- | ||
# Revision history: | ||
# 2016-10-20 : Minor update | ||
# 2015-03-08 : Fixed alignment | ||
# 2014-10-24 : Updated template | ||
# 2014-05-02 : Created | ||
# --------------------------------------------------------------------------- | ||
# Additional info: | ||
# Man page: : Yes | ||
# Bash completion : No | ||
#============================================================================ | ||
# Configuration parameters: | ||
# --------------------------------------------------------------------------- | ||
|
||
#============================================================================ | ||
# Initialization - Logging - Etc. | ||
# --------------------------------------------------------------------------- | ||
# Filter device-mapper and non-disk devices | ||
sedstring="/dm-/d;/scd/d;" | ||
#============================================================================ | ||
# Usage: | ||
# --------------------------------------------------------------------------- | ||
usage() { | ||
cat <<- EOF | ||
$(basename $0) [ options ] | ||
A wrapper for iostat that translates /dev/sdXX devices into their | ||
ASM device names. Example: asmstat -xm 2 | ||
Any options will be directly passed on to iostat. | ||
See man asmstat(1) and asm(1) for more info. | ||
EOF | ||
} | ||
#============================================================================ | ||
# Main | ||
# --------------------------------------------------------------------------- | ||
# Normal getopts doesn't work as we need to pass everything to iostat... | ||
case $1 in | ||
-h) usage ; exit 0 ;; | ||
-?) usage ; exit 0 ;; | ||
esac | ||
|
||
if ! ls /dev/oracleasm/* &>/dev/null ; then | ||
iostat $@ | ||
else | ||
for asmdev in /dev/oracleasm/* | ||
do | ||
maj=$(echo "ibase=16; $(stat -Lc '%t' ${asmdev}|tr 'a-z' 'A-Z')"|bc) | ||
min=$(echo "ibase=16; $(stat -Lc '%T' ${asmdev}|tr 'a-z' 'A-Z')"|bc) | ||
# get location of dev | ||
# old method: | ||
# dev=$(egrep -l "${maj}:${min}$" /sys/devices/{*,*/*,*/*/*}/host*/{*/*,*/*/*}/block/*/dev 2>/dev/null | head -1) | ||
# better method (!?): | ||
dev=$(readlink $(find /sys/dev/block -name "${maj}:${min}" | sed -n "1p" )|sed "s/.*\///") | ||
[[ "$dev" == "" ]] && continue | ||
disk=$(echo $dev | awk -F'/' '{print $(NF-1)}') | ||
asmvol=${asmdev##*/} | ||
# get size of largest string | ||
len=${#disk} ; (( ${#asmvol} > len)) && len=${#asmvol} | ||
# align asm volume name to 6 chars | ||
# translate /dev/sdX into /dev/oracleasm/<vol> | ||
sedstring="${sedstring}$(printf "s/%-${len}s/%-${len}s/;\n" $disk $asmvol)" | ||
done | ||
# run iostat command with translation | ||
iostat $@ | sed -u "$sedstring" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
#============================================================================ | ||
# Title : diskheader | ||
# Description : Shows hexdump of the first 1k block of a disk | ||
# Author : Bart Sjerps <bart@outrun.nl> | ||
# License : GPLv3+ | ||
# --------------------------------------------------------------------------- | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License at <http://www.gnu.org/licenses/> for | ||
# more details. | ||
# --------------------------------------------------------------------------- | ||
# Revision history: | ||
# 2017-02-01 : First version | ||
#============================================================================ | ||
# Configuration parameters: | ||
# --------------------------------------------------------------------------- | ||
#============================================================================ | ||
# Initialization - Logging - Etc. | ||
# --------------------------------------------------------------------------- | ||
die() { echo "$(basename $0): [die] $@" >&2 ; exit 10 ; } | ||
|
||
test -x /usr/bin/xxd || die "Requires xxd (vim-common)" | ||
|
||
#============================================================================ | ||
# Usage: | ||
# --------------------------------------------------------------------------- | ||
usage() { | ||
cat <<- EOF | ||
$(basename $0) [-c blocks] [-w width] <disk> | ||
Shows a hexdump of the header of the given disk. | ||
-c blocks - show <blocks> (default 1 block of 1024 bytes) | ||
-w width - Hexdump with <width> (default 32) | ||
EOF | ||
} | ||
#============================================================================ | ||
# Functions | ||
# --------------------------------------------------------------------------- | ||
|
||
|
||
#============================================================================ | ||
# Main section - parsing options etc | ||
# --------------------------------------------------------------------------- | ||
while getopts ":hb:c:w:" OPT; do | ||
case "$OPT" in | ||
b) blksz=${OPTARG} ;; | ||
c) count=${OPTARG} ;; | ||
w) width=${OPTARG} ;; | ||
\?|h) usage ; exit 0 ;; | ||
esac | ||
done | ||
shift $(expr $OPTIND - 1) | ||
|
||
test -z "$1" && usage && exit | ||
test -b "$1" || die "$1 is not a block device" | ||
|
||
dd if="$1" bs=${blksz:-1024} count=${count:-1} status=none | xxd -c ${width:-32} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
#============================================================================ | ||
# Title : wipedisk | ||
# Description : Wipes first 1MB of a disk and makes backup in /tmp | ||
# Author : Bart Sjerps <bart@outrun.nl> | ||
# License : GPLv3+ | ||
# --------------------------------------------------------------------------- | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License at <http://www.gnu.org/licenses/> for | ||
# more details. | ||
# --------------------------------------------------------------------------- | ||
# Revision history: | ||
# 2016-10-20 : Update | ||
# 2014-10-27 : Bugfix, added nowait | ||
# 2014-10-22 : Created | ||
# --------------------------------------------------------------------------- | ||
# Additional info: | ||
# Man page: : Yes | ||
# Bash completion : No | ||
#============================================================================ | ||
# Configuration parameters: | ||
# --------------------------------------------------------------------------- | ||
|
||
#============================================================================ | ||
# Initialization - Logging - Etc. | ||
# --------------------------------------------------------------------------- | ||
DATE=$(date +'%Y-%m-%d') # $(date +"%F-%H:%M:%S") | ||
#============================================================================ | ||
# Usage: | ||
# --------------------------------------------------------------------------- | ||
usage() { | ||
cat <<- EOF | ||
$(basename $0) -f [-n] <device> | ||
Zeroes out the first 1 MiB of the give device (to clear all kinds of disk signatures). | ||
The "-f" option is required as a safeguard. | ||
-n - nowait (skips 5 seconds safety delay) | ||
In case of emergency you can restore this first megabyte from backup in /tmp. | ||
Run the manpage for mor info (man $(basename $0)) | ||
EOF | ||
} | ||
#============================================================================ | ||
# Functions | ||
# --------------------------------------------------------------------------- | ||
#============================================================================ | ||
# Main section - parsing options etc | ||
# --------------------------------------------------------------------------- | ||
while getopts ":hfn" OPT; do | ||
case "$OPT" in | ||
f) FORCE=Y ;; | ||
n) NOWAIT=Y ;; | ||
h) usage >&2 ; exit 1 ;; | ||
\?) usage >&2 ; exit 1 ;; | ||
esac | ||
done | ||
shift $(expr $OPTIND - 1) | ||
test $# -lt 1 && { usage ; exit 10 ; } | ||
|
||
if [ "$FORCE" == "Y" ]; then | ||
DISK=${1:-nodisk} | ||
if [ ! -b $DISK ]; then | ||
echo "$DISK not found" | ||
exit 1 | ||
fi | ||
BKUP=$(echo $DISK | tr '/' '_') | ||
echo "Backing up 1st MB of $DISK in /tmp/$BKUP, restore with dd if=/tmp/$BKUP of=/dev/$DISK bs=1M count=1" | ||
dd if=$1 of=/tmp/backup_$BKUP bs=1M count=1 | ||
echo "Wiping 1st mb of disk $DISK" | ||
[[ -z $NOWAIT ]] && for i in {5..1}; do echo $i ; sleep 1 ; done | ||
dd if=/dev/zero of=$DISK bs=1M count=1 | ||
fi |
Oops, something went wrong.