Skip to content

Commit 215d7d0

Browse files
author
Bart Sjerps
committed
initial sources
1 parent 873c6b6 commit 215d7d0

File tree

12 files changed

+1926
-0
lines changed

12 files changed

+1926
-0
lines changed

SOURCES/testfile

Whitespace-only changes.

src/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#============================================================================
2+
# Title : Makefile
3+
# Description : Makefile for asmdisks
4+
# Author : Bart Sjerps <[email protected]>
5+
# License : GPLv3+
6+
# ---------------------------------------------------------------------------
7+
8+
prefix = /usr/local
9+
bindir = $(prefix)/bin
10+
mandir = $(prefix)/share/man
11+
docdir = $(prefix)/share/doc
12+
13+
sysconfdir = /etc
14+
15+
all:
16+
17+
install:
18+
install -d 0755 $(bindir)
19+
install -d 0755 $(sysconfdir)/bash_completion.d
20+
install -d 0755 $(mandir)/man1
21+
install -d 0755 $(docdir)
22+
install -m 0755 bin/asm bin/asmstat bin/diskheader bin/wipedisk $(bindir)
23+
install -m 0644 bin/asm.bash $(sysconfdir)/bash_completion.d
24+
install -m 0644 man/* $(mandir)/man1/
25+
install -m 0444 doc/* $(docdir)/
26+
27+
.PHONY: install
28+

src/bin/asm

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

src/bin/asm.bash

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#============================================================================
2+
# Title : asm.bash
3+
# Description : bash_completion file for asm script
4+
# Author : Bart Sjerps <[email protected]>
5+
# License : GPLv3+
6+
# ---------------------------------------------------------------------------
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License at <http://www.gnu.org/licenses/> for
16+
# more details.
17+
# ---------------------------------------------------------------------------
18+
# Revision history:
19+
# 2016-10-20 : Added DSSD support
20+
# 2015-03-10 : Updated for Powerpath support
21+
# 2014-11-06 : Updated for new asm options
22+
# 2014-10-24 : Created
23+
# ---------------------------------------------------------------------------
24+
_asm() {
25+
local cur prev opts cmd
26+
lsvols() { awk '$1!="#" && NF==3 {print $1}' /etc/asmtab 2>/dev/null ; }
27+
lsdevs() {
28+
find /dev/mapper -type l 2>/dev/null
29+
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]"
30+
}
31+
COMPREPLY=()
32+
cur="${COMP_WORDS[COMP_CWORD]}"
33+
prev="${COMP_WORDS[COMP_CWORD-1]}"
34+
cmd="${COMP_WORDS[1]}"
35+
(( $COMP_CWORD > 3)) && return 0
36+
if (( $COMP_CWORD == 2 )); then
37+
case $cmd in
38+
createdisk) ;;
39+
deletedisk|renamedisk) COMPREPLY=($(compgen -W "$(lsvols)" -- ${cur})) ; return 0 ;;
40+
*) return 0 ;;
41+
esac
42+
fi
43+
if (( $COMP_CWORD == 3 )); then
44+
case $cmd in
45+
createdisk) COMPREPLY=($(compgen -W "$(lsdevs)" -- ${cur})) ; return 0 ;;
46+
*) return 0 ;;
47+
esac
48+
fi
49+
opts="createdisk deletedisk renamedisk rescan scandisks listdisks disks list multi import"
50+
case ${prev} in
51+
createdisk) return 0 ;;
52+
*) ;;
53+
esac
54+
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
55+
return 0
56+
}
57+
complete -F _asm asm

src/bin/asmstat

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
#============================================================================
3+
# Title : asmstat
4+
# Description : Wrapper for iostat that maps ASM devices
5+
# Author : Bart Sjerps <[email protected]>
6+
# License : GPLv3+
7+
# ---------------------------------------------------------------------------
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License at <http://www.gnu.org/licenses/> for
17+
# more details.
18+
# ---------------------------------------------------------------------------
19+
# Revision history:
20+
# 2016-10-20 : Minor update
21+
# 2015-03-08 : Fixed alignment
22+
# 2014-10-24 : Updated template
23+
# 2014-05-02 : Created
24+
# ---------------------------------------------------------------------------
25+
# Additional info:
26+
# Man page: : Yes
27+
# Bash completion : No
28+
#============================================================================
29+
# Configuration parameters:
30+
# ---------------------------------------------------------------------------
31+
32+
#============================================================================
33+
# Initialization - Logging - Etc.
34+
# ---------------------------------------------------------------------------
35+
# Filter device-mapper and non-disk devices
36+
sedstring="/dm-/d;/scd/d;"
37+
#============================================================================
38+
# Usage:
39+
# ---------------------------------------------------------------------------
40+
usage() {
41+
cat <<- EOF
42+
$(basename $0) [ options ]
43+
44+
A wrapper for iostat that translates /dev/sdXX devices into their
45+
ASM device names. Example: asmstat -xm 2
46+
Any options will be directly passed on to iostat.
47+
See man asmstat(1) and asm(1) for more info.
48+
49+
EOF
50+
}
51+
#============================================================================
52+
# Main
53+
# ---------------------------------------------------------------------------
54+
# Normal getopts doesn't work as we need to pass everything to iostat...
55+
case $1 in
56+
-h) usage ; exit 0 ;;
57+
-?) usage ; exit 0 ;;
58+
esac
59+
60+
if ! ls /dev/oracleasm/* &>/dev/null ; then
61+
iostat $@
62+
else
63+
for asmdev in /dev/oracleasm/*
64+
do
65+
maj=$(echo "ibase=16; $(stat -Lc '%t' ${asmdev}|tr 'a-z' 'A-Z')"|bc)
66+
min=$(echo "ibase=16; $(stat -Lc '%T' ${asmdev}|tr 'a-z' 'A-Z')"|bc)
67+
# get location of dev
68+
# old method:
69+
# dev=$(egrep -l "${maj}:${min}$" /sys/devices/{*,*/*,*/*/*}/host*/{*/*,*/*/*}/block/*/dev 2>/dev/null | head -1)
70+
# better method (!?):
71+
dev=$(readlink $(find /sys/dev/block -name "${maj}:${min}" | sed -n "1p" )|sed "s/.*\///")
72+
[[ "$dev" == "" ]] && continue
73+
disk=$(echo $dev | awk -F'/' '{print $(NF-1)}')
74+
asmvol=${asmdev##*/}
75+
# get size of largest string
76+
len=${#disk} ; (( ${#asmvol} > len)) && len=${#asmvol}
77+
# align asm volume name to 6 chars
78+
# translate /dev/sdX into /dev/oracleasm/<vol>
79+
sedstring="${sedstring}$(printf "s/%-${len}s/%-${len}s/;\n" $disk $asmvol)"
80+
done
81+
# run iostat command with translation
82+
iostat $@ | sed -u "$sedstring"
83+
fi
84+

src/bin/diskheader

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
#============================================================================
3+
# Title : diskheader
4+
# Description : Shows hexdump of the first 1k block of a disk
5+
# Author : Bart Sjerps <[email protected]>
6+
# License : GPLv3+
7+
# ---------------------------------------------------------------------------
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License at <http://www.gnu.org/licenses/> for
17+
# more details.
18+
# ---------------------------------------------------------------------------
19+
# Revision history:
20+
# 2017-02-01 : First version
21+
#============================================================================
22+
# Configuration parameters:
23+
# ---------------------------------------------------------------------------
24+
#============================================================================
25+
# Initialization - Logging - Etc.
26+
# ---------------------------------------------------------------------------
27+
die() { echo "$(basename $0): [die] $@" >&2 ; exit 10 ; }
28+
29+
test -x /usr/bin/xxd || die "Requires xxd (vim-common)"
30+
31+
#============================================================================
32+
# Usage:
33+
# ---------------------------------------------------------------------------
34+
usage() {
35+
cat <<- EOF
36+
$(basename $0) [-c blocks] [-w width] <disk>
37+
38+
Shows a hexdump of the header of the given disk.
39+
40+
-c blocks - show <blocks> (default 1 block of 1024 bytes)
41+
-w width - Hexdump with <width> (default 32)
42+
43+
EOF
44+
}
45+
#============================================================================
46+
# Functions
47+
# ---------------------------------------------------------------------------
48+
49+
50+
#============================================================================
51+
# Main section - parsing options etc
52+
# ---------------------------------------------------------------------------
53+
while getopts ":hb:c:w:" OPT; do
54+
case "$OPT" in
55+
b) blksz=${OPTARG} ;;
56+
c) count=${OPTARG} ;;
57+
w) width=${OPTARG} ;;
58+
\?|h) usage ; exit 0 ;;
59+
esac
60+
done
61+
shift $(expr $OPTIND - 1)
62+
63+
test -z "$1" && usage && exit
64+
test -b "$1" || die "$1 is not a block device"
65+
66+
dd if="$1" bs=${blksz:-1024} count=${count:-1} status=none | xxd -c ${width:-32}

src/bin/wipedisk

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
#============================================================================
3+
# Title : wipedisk
4+
# Description : Wipes first 1MB of a disk and makes backup in /tmp
5+
# Author : Bart Sjerps <[email protected]>
6+
# License : GPLv3+
7+
# ---------------------------------------------------------------------------
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License at <http://www.gnu.org/licenses/> for
17+
# more details.
18+
# ---------------------------------------------------------------------------
19+
# Revision history:
20+
# 2016-10-20 : Update
21+
# 2014-10-27 : Bugfix, added nowait
22+
# 2014-10-22 : Created
23+
# ---------------------------------------------------------------------------
24+
# Additional info:
25+
# Man page: : Yes
26+
# Bash completion : No
27+
#============================================================================
28+
# Configuration parameters:
29+
# ---------------------------------------------------------------------------
30+
31+
#============================================================================
32+
# Initialization - Logging - Etc.
33+
# ---------------------------------------------------------------------------
34+
DATE=$(date +'%Y-%m-%d') # $(date +"%F-%H:%M:%S")
35+
#============================================================================
36+
# Usage:
37+
# ---------------------------------------------------------------------------
38+
usage() {
39+
cat <<- EOF
40+
$(basename $0) -f [-n] <device>
41+
Zeroes out the first 1 MiB of the give device (to clear all kinds of disk signatures).
42+
The "-f" option is required as a safeguard.
43+
-n - nowait (skips 5 seconds safety delay)
44+
In case of emergency you can restore this first megabyte from backup in /tmp.
45+
Run the manpage for mor info (man $(basename $0))
46+
EOF
47+
}
48+
#============================================================================
49+
# Functions
50+
# ---------------------------------------------------------------------------
51+
#============================================================================
52+
# Main section - parsing options etc
53+
# ---------------------------------------------------------------------------
54+
while getopts ":hfn" OPT; do
55+
case "$OPT" in
56+
f) FORCE=Y ;;
57+
n) NOWAIT=Y ;;
58+
h) usage >&2 ; exit 1 ;;
59+
\?) usage >&2 ; exit 1 ;;
60+
esac
61+
done
62+
shift $(expr $OPTIND - 1)
63+
test $# -lt 1 && { usage ; exit 10 ; }
64+
65+
if [ "$FORCE" == "Y" ]; then
66+
DISK=${1:-nodisk}
67+
if [ ! -b $DISK ]; then
68+
echo "$DISK not found"
69+
exit 1
70+
fi
71+
BKUP=$(echo $DISK | tr '/' '_')
72+
echo "Backing up 1st MB of $DISK in /tmp/$BKUP, restore with dd if=/tmp/$BKUP of=/dev/$DISK bs=1M count=1"
73+
dd if=$1 of=/tmp/backup_$BKUP bs=1M count=1
74+
echo "Wiping 1st mb of disk $DISK"
75+
[[ -z $NOWAIT ]] && for i in {5..1}; do echo $i ; sleep 1 ; done
76+
dd if=/dev/zero of=$DISK bs=1M count=1
77+
fi

0 commit comments

Comments
 (0)