1 | 31 | simandl | #!/usr/bin/env sh |
2 | | | |
3 | | | if ! [ -e settings ]; then OUTFILE="settings"; else OUTFILE="settings.new"; fi |
4 | | | |
5 | | | OSTYPE=`uname` |
6 | | | VERSION=`uname -r|awk -F "\." '{ if ( $2 < 3 ) { vrs = "2" ; } else { vrs = "4"; }; print $1"."vrs}'` |
7 | | | |
8 | | | cat > $OUTFILE << EOF |
9 | | | # kernel version |
10 | | | # KERNEL="2.2" for 2.1.x and 2.2.x kernels |
11 | | | # KERNEL="2.4" for 2.3.x and 2.4.x kernels |
12 | | | # |
13 | | | EOF |
14 | | | |
15 | | | echo "KERNEL=\"$VERSION\"" >> $OUTFILE |
16 | | | |
17 | | | cat >> $OUTFILE << EOF |
18 | | | |
19 | | | # all entries have to be of the form: |
20 | | | # DEV=<device>,<device name> |
21 | | | # |
22 | | | # <device> the device-number as in /proc/stat -> disk_io |
23 | | | # for kernels < 2.3 "0" is the first drive, "1" the second ... |
24 | | | # <2.3 kernels support (unless patched) only 4 drives. |
25 | | | # |
26 | | | # <device name> a description for the device |
27 | | | # |
28 | | | # Example for Kernel >= 2.3: |
29 | | | # DEV=8_0,sda |
30 | | | # DEV=3_0,hda |
31 | | | # DEV=22_0,hdc |
32 | | | # |
33 | | | # Example for Kernel <= 2.2: |
34 | | | # DEV=0,hda |
35 | | | # DEV=1,hdb |
36 | | | # |
37 | | | EOF |
38 | | | |
39 | | | if [ "$OUTFILE" = "settings" ]; then |
40 | | | if [ "$OSTYPE" = "NetBSD" ]; then |
41 | | | /usr/sbin/iostat -Ix | perl -ne 'chomp; ($drv,$rest) = split / /, $_; next if ($drv =~ /device/ || $drv =~ /md?/ ||$drv =~ /fd?/); print "DEV=$drv,$drv\n";' >> $OUTFILE |
42 | | | fi |
43 | | | if [ "$OSTYPE" = "FreeBSD" -o "$OSTYPE" = "OpenBSD" ]; then |
44 | | | echo "not supported yet, sorry" |
45 | | | exit 1 |
46 | | | fi |
47 | | | if [ "$OSTYPE" = "Linux" ]; then |
48 | | | DEVS=$(cat /proc/stat |grep disk_io | sed -e "s/):([0-9,]*//g; s/[()]//g; s/disk_io: //g") |
49 | | | for DEV in $DEVS; do |
50 | | | ENTRY=$(echo $DEV | sed -e "s/,/_/g") |
51 | | | NAME="(unknown)" |
52 | | | case $ENTRY in |
53 | | | 3_0) NAME="/dev/hda";; |
54 | | | 3_64) NAME="/dev/hdb";; |
55 | | | 22_0) NAME="/dev/hdc";; |
56 | | | 22_64) NAME="/dev/hdd";; |
57 | | | 33_0) NAME="/dev/hde";; |
58 | | | 33_64) NAME="/dev/hdf";; |
59 | | | 34_0) NAME="/dev/hdg";; |
60 | | | 34_64) NAME="/dev/hdh";; |
61 | | | 8_0) NAME="/dev/sda";; |
62 | | | 8_1) NAME="/dev/sdb";; |
63 | | | 8_2) NAME="/dev/sdc";; |
64 | | | 8_3) NAME="/dev/sdd";; |
65 | | | 8_4) NAME="/dev/sde";; |
66 | | | 8_5) NAME="/dev/sdf";; |
67 | | | 8_6) NAME="/dev/sdg";; |
68 | | | 8_7) NAME="/dev/sdh";; |
69 | | | 8_8) NAME="/dev/sdi";; |
70 | | | 8_9) NAME="/dev/sdj";; |
71 | | | 8_10) NAME="/dev/sdk";; |
72 | | | 8_11) NAME="/dev/sdl";; |
73 | | | 8_12) NAME="/dev/sdm";; |
74 | | | 8_13) NAME="/dev/sdn";; |
75 | | | 8_14) NAME="/dev/sdo";; |
76 | | | esac |
77 | | | echo "found: $DEV - $ENTRY - $NAME" |
78 | | | echo "DEV=$ENTRY,$NAME" >> $OUTFILE |
79 | | | done |
80 | | | fi |
81 | | | |
82 | | | fi |
83 | | | if [ "$OUTFILE" = "settings.new" ]; then |
84 | | | cat settings | grep "^DEV=" >> $OUTFILE |
85 | | | fi |
86 | | | |
87 | | | echo |
88 | | | echo "Please check the settings file and adapt it to satisfy your needs." |
89 | | | if [ "$OUTFILE" = "settings.new" ]; then |
90 | | | mkdir -p backup |
91 | | | NOW=`date +%Y%m%d-%H%M%S` |
92 | | | mv -f settings backup/settings-$NOW |
93 | | | mv -f settings.new settings |
94 | | | echo "a backup of the previous settings has been saved." |
95 | | | fi |
96 | | | echo |
97 | | | |
98 | | | # kernel2.4 source-snip (/usr/src/linux/fs/proc/proc_misc.c) : |
99 | | | # |
100 | | | # proc_sprintf(page, &off, &len, "\ndisk_io: "); |
101 | | | # |
102 | | | # for (major = 0; major < DK_MAX_MAJOR; major++) { |
103 | | | # for (disk = 0; disk < DK_MAX_DISK; disk++) { |
104 | | | # int active = kstat.dk_drive[major][disk] + |
105 | | | # kstat.dk_drive_rblk[major][disk] + |
106 | | | # kstat.dk_drive_wblk[major][disk]; |
107 | | | # if (active) |
108 | | | # proc_sprintf(page, &off, &len, "(%u,%u):(%u,%u,%u,%u,%u) ", major, disk, |
109 | | | # kstat.dk_drive[major][disk], kstat.dk_drive_rio[major][disk], kstat.dk_drive_rblk[major][disk], |
110 | | | # kstat.dk_drive_wio[major][disk], kstat.dk_drive_wblk[major][disk]); |
111 | | | # } |
112 | | | # } |