Tag Archives: linux

Remove a deleted virtual disk LUN on a Linux system (MD3000i SAN array)

When you delete a Virtual Disk on a MD3000i array, that was previously used by a Linux system, the device is not removed from the system, and Linux will still try to access it (if you use LVM for example, you’ll see lots of errors while the system scans the disks to identify PVs). This can be very inconvenient if you reassign a previously assigned LUN, as the system won’t detect the new parameters of the device.
I did not find a command similar to hot_add (used to detect new devices) to automatically remove deleted disks.

By trial and error, though, I understood that you can delete a scsi device with this method:
echo "1" > /sys/class/scsi_device/adapter:bus:target:lun/device/delete

I also wrote a small script that will try and guess the paths to your devices, when you tell it the LUN number you just deleted on the SAN array :
md300i_delete_lun bash script
Warning: this script comes with no guarantee and I won’t take any responsibility if you try to use it :-). I could just test it on two RHEL 5.3 systems, and I don’t know if it will work anywhere else. Since it can be a little bit dangerous, it won’t actually delete anything, just tell you what commands you could use to delete the devices. At your own risk. 🙂

Get the ip address in a shell script

Using ifconfig was not a good idea at all.
Here is a more distro-agnostic way:

ip addr show eth0 | grep "inet "| awk '{ print $2}' | awk -F '/' '{ print $1 }'


# set the language to English, to avoid translation problems with ifconfig
export LANG=C
# get IP address of eth0 network interface
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'


source

Disable a Linux module

The RHEL / Centos way:
edit /etc/modprobe.conf, and add :
alias <modulename> off

The Debian way:
Create a file ‘/etc/modprobe.d/<modulename>’ containing ‘blacklist <modulename>’.
Run ‘depmod -ae’ as root
Recreate your initrd with ‘update-initramfs -u’
/!\ Read http://wiki.debian.org/KernelModuleBlacklisting, then do not use ‘/etc/modprobe.d/blacklist’ and remove ‘/etc/modprobe.conf’ as it supersedes anything in /etc/modprobe.d/*.
source : Debian wiki

The Tobi way:
edit /etc/modprobe.conf, and add :
install <modulename> /bin/true

inspiration: DotMana

Redirecting output of the bash keyword time

time command > timelog doesn’t work, because time outputs to stderr
time command 2> timelog doesn’t work either, because time actually is a bash keyword, and it’s always run in a subshell

Redirecting the output of time can be achieved by executing the whole command in a block, then redirecting its output:
{ time command; } 2> timelog

Note: Linux also provides a time binary (/usr/bin/time), but with a different output (and might be less efficient ?)

source