<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nexxes open source blog &#187; System Administration</title>
	<atom:link href="http://blog.nexxes.org/category/sysadm/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nexxes.org</link>
	<description>Open information provided by nexxes Informationstechnik GmbH</description>
	<lastBuildDate>Thu, 13 Aug 2009 01:58:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Save hot remove SATA drives under linux</title>
		<link>http://blog.nexxes.org/2009/08/09/save-hot-remove-sata-drives-under-linux/</link>
		<comments>http://blog.nexxes.org/2009/08/09/save-hot-remove-sata-drives-under-linux/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 01:46:50 +0000</pubDate>
		<dc:creator>Dennis Birkholz</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[hot swap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[SATA]]></category>

		<guid isPermaLink="false">http://blog.nexxes.org/?p=45</guid>
		<description><![CDATA[I bought a trayless mobile SATA rack and explored the linux SATA hot-swap capabilities. My mainboard (with a quite new AHCI compatible chipset) does support hot-swap and so I put a hdd into my mobile rack, watched dmesg to show it settle down and apear under /dev. After that, I removed the drive and noted [...]]]></description>
			<content:encoded><![CDATA[<p>I bought a trayless mobile SATA rack and explored the linux SATA hot-swap capabilities. My mainboard (with a quite new AHCI compatible chipset) does support hot-swap and so I put a hdd into my mobile rack, watched <code>dmesg</code> to show it settle down and apear under <code>/dev</code>. After that, I removed the drive and noted the following <code>dmesg</code>output:</p>

<code>ata3.00: detaching (SCSI 2:0:0:0)
sd 2:0:0:0: [sdf] Synchronizing SCSI cache
sd 2:0:0:0: [sdf] Result: hostbyte=0x04 driverbyte=0x00
sd 2:0:0:0: [sdf] Stopping disk
sd 2:0:0:0: [sdf] START_STOP FAILED
sd 2:0:0:0: [sdf] Result: hostbyte=0x04 driverbyte=0x00
ata3: exception Emask 0x10 SAct 0x0 SErr 0x40c0000 action 0xe frozen
ata3: irq_stat 0x00000040, connection status changed
ata3: SError: { CommWake 10B8B DevExch }
ata3: hard resetting link
ata3: SATA link down (SStatus 0 SControl 300)
ata3: EH complete
</code>

<p>That looked rather ill to me so I startet digging around to learn how to tell the system that I soon will remove the harddrive so that all cached data can be written safely to disk. I discovered how to disable SCSI devices via the /proc interface and tried it and now my <code>dmesg</code> looked a lot nicer to me:</p>

<code>sd 2:0:0:0: [sdf] Synchronizing SCSI cache
sd 2:0:0:0: [sdf] Stopping disk
ata3.00: disabled
</code>

<p>The nasty thing is that you need to know the SCSI id of the drive to remove. So I created a small bash script that can shut down a drive by using its <code>/dev/sdX</code> name:</p>

<code>#!/bin/bash
# (c) 2009 by Dennis Birkholz (firstname DOT lastname [at] nexxes.net)
#
# 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 2 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 for more details.
#
# You can received a copy of the GNU General Public License at 
# &lt;http://www.gnu.org/licenses/&gt;.

function usage {
	echo "Usage $0 [device]"
	echo
	echo "Disable supplied SCSI device"
	exit
}

# Need a parameter
[ "$1" == "" ] &#038;&#038;
	usage

# Verify parameter exists
( [ ! -e "$1" ] || [ ! -b "$1" ] ) &#038;&#038;
	echo "Supplied devices does not exist or is not a block device." >/dev/stderr &#038;&#038;
	exit 1

# Verify SCSI disk entries exist in /sys
[ ! -d "/sys/class/scsi_disk/" ] &#038;&#038;
	echo "Could not find SCSI disk entries in sys, aborting." >/dev/stderr &#038;&#038;
	exit 2

# Get major/minor device string of device
major=$(stat --dereference --format='%t' "$1")
major=$(printf '%d\n' "0x${major}")
minor=$(stat --dereference --format='%T' "$1")
minor=$(printf '%d\n' "0x${minor}")
deviceID="${major}:${minor}"

echo "Major/Minor number for device '$1' is '${deviceID}'..."

for device in /sys/class/scsi_disk/*; do
	[ "$(< ${device}/device/block*/dev)" != "${deviceID}" ] &#038;&#038; continue
	
	scsiID=$(basename "${device}")
	echo "Found SCSI ID '${scsiID}' for device '${1}'..."
	
	echo 1 > ${device}/device/delete
	echo "SCSI device removed."
	exit 0
done

echo "Could not identify device as SCSI device, aborting." >/dev/stderr
exit 4
</code>

<p>Put it under <code>/usr/local/sbin</code> and name it like <code>hotremove</code> and you can remove your devices by calling <code>hotremove /dev/sdX</code> without the pain of knowing SCSI ids.</p>

<p>(<span style="color:red">Warning</span>: don&#8217;t forget to unmount first! Maybe later I will add auto unmounting also &#8230;)</p>]]></content:encoded>
			<wfw:commentRss>http://blog.nexxes.org/2009/08/09/save-hot-remove-sata-drives-under-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Syslog-ng and /dev/null</title>
		<link>http://blog.nexxes.org/2009/07/11/syslog-ng-and-devnull/</link>
		<comments>http://blog.nexxes.org/2009/07/11/syslog-ng-and-devnull/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 01:11:29 +0000</pubDate>
		<dc:creator>Dennis Birkholz</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[/dev/null]]></category>
		<category><![CDATA[drop target]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[syslog-ng]]></category>

		<guid isPermaLink="false">http://blog.nexxes.org/?p=5</guid>
		<description><![CDATA[Beware to try to use /dev/null as a drop target for syslog-ng by using something like the following in your syslog-ng.conf:

destination d_drop {
	file("/dev/null");
};

This will chmod your /dev/null file to 0600 (also known as crw-------) at every startup and cause many failures on your system/server. Use an empty target to drop your log messages:

destination d_drop {
};]]></description>
			<content:encoded><![CDATA[<p>Beware to try to use <code>/dev/null</code> as a drop target for syslog-ng by using something like the following in your syslog-ng.conf:</p>

<code>destination d_drop {
	file("/dev/null");
};</code>

<p>This will chmod your <code>/dev/null</code> file to <code>0600 </code>(also known as <code>crw-------</code>) at every startup and cause many failures on your system/server. Use an empty target to drop your log messages:</p>

<code>destination d_drop {
};</code>]]></content:encoded>
			<wfw:commentRss>http://blog.nexxes.org/2009/07/11/syslog-ng-and-devnull/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

