<?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/"
	>

<channel>
	<title>Random Bits</title>
	<atom:link href="http://blog.shadypixel.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.shadypixel.com</link>
	<description>tech, politics, etc.</description>
	<pubDate>Tue, 06 Jan 2009 20:45:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Firefox 3 Native Form Widgets Look Terrible</title>
		<link>http://blog.shadypixel.com/firefox-3-native-form-widgets-look-terrible/</link>
		<comments>http://blog.shadypixel.com/firefox-3-native-form-widgets-look-terrible/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 19:03:38 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[development]]></category>

		<category><![CDATA[firefox]]></category>

		<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=149</guid>
		<description><![CDATA[Firefox 3 added native form widgets on Linux. Most of the time they look great, but on some sites including mine, they look awful. Here's how I styled my forms to avoid native widgets.]]></description>
			<content:encoded><![CDATA[<p>Actually, the native widgets only look terrible if you&#8217;re on Linux with certain gtk+ themes and you&#8217;re viewing a web site with a dark background. Unfortunately, all of those conditions apply to me. See below:</p>
<div id="attachment_151" class="wp-caption alignnone" style="width: 256px"><a href="https://blog.shadypixel.com/wp-content/uploads/2009/01/native_widgets.png"><img class="size-full wp-image-151" title="Firefox 3 native widgets on Linux" src="https://blog.shadypixel.com/wp-content/uploads/2009/01/native_widgets.png" alt="Firefox 3 native widgets on Linux" width="246" height="111" /></a><p class="wp-caption-text">Firefox 3 native widgets on Linux</p></div>
<p>As you can see, there&#8217;s an ugly white box around the otherwise rounded widgets. Originally, I thought my CSS was lacking, but after hours&#8211;literally&#8211;of googling I determined that Firefox&#8217;s implementation of gtk+ widgets is just shoddy. Of course, on a site with a white background, they look great. I&#8217;m reminded of that Henry Ford quote: <em>&#8220;Any customer can have a car painted any colour that he wants as long as it is black.&#8221;</em></p>
<p>Applying any styling to the input elements will completely disable the native widgets. I ended up writing some basic CSS:</p>
<pre>input, textarea { border: 2px solid #888888; }
input:focus, textarea:focus {
	border-color: #D9D27C;
	background-color: #FFFBC4;
}</pre>
<p>They don&#8217;t look nearly as good as native widgets on a white background, but they look a whole lot better than native widgets on my site. See below:</p>
<div id="attachment_154" class="wp-caption alignnone" style="width: 255px"><a href="https://blog.shadypixel.com/wp-content/uploads/2009/01/styled_widgets.png"><img class="size-full wp-image-154" title="Basic styled widgets" src="https://blog.shadypixel.com/wp-content/uploads/2009/01/styled_widgets.png" alt="Basic styled widgets" width="245" height="103" /></a><p class="wp-caption-text">Basic styled widgets</p></div>
<p>I also added some input focus bling to the form:</p>
<div id="attachment_158" class="wp-caption alignnone" style="width: 255px"><a href="https://blog.shadypixel.com/wp-content/uploads/2009/01/styled_widget_with_focus.png"><img class="size-full wp-image-158" title="Text input with keyboard focus" src="https://blog.shadypixel.com/wp-content/uploads/2009/01/styled_widget_with_focus.png" alt="Text input with keyboard focus" width="245" height="103" /></a><p class="wp-caption-text">Text input with keyboard focus</p></div>
<p>Even though they look alright now, I&#8217;ve decided that my next major project on my blog should be a complete theme redesign. Traditional color schemes are easier to work with and I&#8217;ll also get familiar with a lot of Wordpress PHP code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/firefox-3-native-form-widgets-look-terrible/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Safely Removing External Drives in Linux</title>
		<link>http://blog.shadypixel.com/safely-removing-external-drives-in-linux/</link>
		<comments>http://blog.shadypixel.com/safely-removing-external-drives-in-linux/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:47:20 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[admin]]></category>

		<category><![CDATA[backup]]></category>

		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=128</guid>
		<description><![CDATA[Simply unmounting a filesystem is not the ideal way to remove an external USB/firewire/SATA drive in Linux. This tutorial explains why and gives a solution.]]></description>
			<content:encoded><![CDATA[<h3>Backstory</h3>
<p>About a year ago I bought an external SATA drive for backups. My normal usage consisted of:</p>
<ol>
<li>Power on and connect the drive</li>
<li>mount /media/backup</li>
<li>Run my backup script</li>
<li>umount /media/backup</li>
<li>Power off and unplug the drive</li>
</ol>
<p>This seemed to work pretty well&#8211;at the very least, I wasn&#8217;t losing data&#8211;except the drive made a strange sound when I powered it off. It wasn&#8217;t a normal drive spin down sound; it was louder and shorter. So, I googled for authoritative instructions on using external drives with Linux. While most sources suggest doing exactly what I did, it&#8217;s not ideal.</p>
<p>It turns out that most cheap external USB/SATA/firewire enclosures don&#8217;t properly issue a stop command to the drive when you flick the power switch. Instead, the power switch simply cuts power to the drive, which forces the drive to do an emergency head retract. If you think that sounds bad, you&#8217;re right. Emergency retracts aren&#8217;t going to brick your drive immediately, but if they occur regularly they&#8217;re putting a lot of unnecessary wear and tear on the drive. In fact, some drives monitor how often this happens with S.M.A.R.T. attribute 192. (Check <a href="http://en.wikipedia.org/wiki/S.M.A.R.T." onclick="javascript:pageTracker._trackPageview ('/outbound/en.wikipedia.org');">Wikipedia&#8217;s S.M.A.R.T. page</a> for a comprehensive list of attributes)</p>
<h3>Solution</h3>
<p>The solution is to spin down the drive via software before turning it off and unplugging it. The best way to do this is with a utility called <a href="http://llg.cubic.org/tools/" onclick="javascript:pageTracker._trackPageview ('/outbound/llg.cubic.org');">scsiadd</a>. This program can add and remove drives to Linux&#8217;s SCSI subsystem. Additionally, with fairly modern kernels, removing a device will issue a stop command, which is exactly what we&#8217;re looking for. Run:</p>
<p><code>$ sudo scsiadd -p</code></p>
<p>which should print something like:</p>
<pre>Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: SAMSUNG HD300LJ  Rev: ZT10
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: LITE-ON  Model: DVDRW LH-20A1L   Rev: BL05
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi5 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: WDC WD10EACS-00Z Rev: 01.0
  Type:   Direct-Access                    ANSI  SCSI revision: 05</pre>
<p>Identify the drive you want to remove and then issue:</p>
<p><code>$ sudo scsiadd -r <em>host</em> <em>channel</em> <em>id</em> <em>lun</em></code></p>
<p>substituting the corresponding values from the scsiadd -p output. For example, if I wanted to remove &#8220;WDC WD10EACS-00Z&#8221;, I would run:</p>
<p><code>$ sudo scsiadd -r 5 0 0 0</code></p>
<p>If everything works, scsiadd should print:</p>
<pre>Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: SAMSUNG HD300LJ  Rev: ZT10
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: LITE-ON  Model: DVDRW LH-20A1L   Rev: BL05
  Type:   CD-ROM                           ANSI  SCSI revision: 05</pre>
<p>You can double-check the end of dmesg. You should see:</p>
<pre>[608188.235216] sd 5:0:0:0: [sdb] Synchronizing SCSI cache
[608188.235362] sd 5:0:0:0: [sdb] Stopping disk
[608188.794296] ata6.00: disabled</pre>
<p>At this point, the drive is removed from Linux&#8217;s SCSI subsystem and it should not be spinning. It&#8217;s safe to unplug and turn off.</p>
<p>Using scsiadd directly can be inconvenient because it requires looking up the host, channel, id, and lun of the drive. I wrote a short script that will take a normal Linux device file like /dev/sdb, figure out the correct arguments to scsiadd, and run scsiadd -r. I use this script in my larger backup script.</p>
<pre>#!/bin/sh

if [ $# -ne 1 ]; then
    echo "Usage: $0 &lt;device&gt;"
    exit 1
fi

if ! which lsscsi &gt;/dev/null 2&gt;&amp;1; then
    echo "Error: lsscsi not installed";
    exit 1
fi

if ! which scsiadd &gt;/dev/null 2&gt;&amp;1; then
    echo "Error: scsiadd not installed"
    exit 1
fi

device=`lsscsi | grep $1`
if [ -z "$device" ]; then
    echo "Error: could not find device: $1"
    exit 1
fi

hcil=`echo $device | awk \
    '{split(substr($0, 2, 7),a,":"); print a[1], a[2], a[3], a[4]}'`

scsiadd -r $hcil</pre>
<p>It does require the lsscsi command to be present on the system.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/safely-removing-external-drives-in-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Monitoring Hard Drive Health on Linux with smartmontools</title>
		<link>http://blog.shadypixel.com/monitoring-hard-drive-health-on-linux-with-smartmontools/</link>
		<comments>http://blog.shadypixel.com/monitoring-hard-drive-health-on-linux-with-smartmontools/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 11:18:09 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[admin]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[smart]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=83</guid>
		<description><![CDATA[S.M.A.R.T. is a system in modern hard drives designed to report conditions that may indicate impending failure. smartmontools is a free software package that can monitor S.M.A.R.T. attributes and run hard drive self-tests. Although smartmontools runs on a number of platforms, I will only cover installing and configuring it on Linux.

Why Use S.M.A.R.T.?
Basically, S.M.A.R.T. may [...]]]></description>
			<content:encoded><![CDATA[<p><abbr title="Self-Monitoring, Analysis, and Reporting Technology">S.M.A.R.T.</abbr> is a system in modern hard drives designed to report conditions that may indicate impending failure. <a href="http://smartmontools.sourceforge.net/" onclick="javascript:pageTracker._trackPageview ('/outbound/smartmontools.sourceforge.net');">smartmontools</a> is a free software package that can monitor S.M.A.R.T. attributes and run hard drive self-tests. Although smartmontools runs on a number of platforms, I will only cover installing and configuring it on Linux.</p>
<p><span id="more-83"></span></p>
<h3>Why Use S.M.A.R.T.?</h3>
<p>Basically, S.M.A.R.T. may give you enough of a warning that you can safely backup all your data before your hard drive dies. There is some amount of conflicting information on the internet about how reliable the warnings are. The best source of research that I found is a <a href="http://labs.google.com/papers/disk_failures.pdf" onclick="javascript:pageTracker._trackPageview ('/outbound/labs.google.com');">paper from Google</a> that describes an internal study of hard drive failure. A quick summary: certain events greatly increase the chance of hard drive failure including reallocation events and failed self-tests, but only about 60% of the drives that failed in the study had any negative S.M.A.R.T. attributes. Obviously, nothing replaces regular backups.</p>
<p>A good source for more information is the <a href="http://en.wikipedia.org/wiki/S.M.A.R.T." onclick="javascript:pageTracker._trackPageview ('/outbound/en.wikipedia.org');">S.M.A.R.T. wikipedia page</a>.</p>
<h3>Installation</h3>
<p>On Debian or Ubuntu systems:</p>
<p><code>$ sudo apt-get install smartmontools</code></p>
<p>On Fedora:</p>
<p><code>$ sudo yum install smartmontools</code></p>
<h3>Capabilities and Initial Tests</h3>
<p>smartmontools comes with two programs: smartctl which is meant for interactive use and smartd which continuously monitors S.M.A.R.T. Let&#8217;s look at smartctl first:</p>
<p><code>$ sudo smartctl -i /dev/sda</code></p>
<p>Replace /dev/sda with your hard drive&#8217;s device file in this command and all subsequent commands. If there&#8217;s only one hard drive in the system, it should be /dev/sda or /dev/hda. If this command fails, you may need to let smartctl know what type of hard drive interface you&#8217;re using:</p>
<p><code>$ sudo smartctl -d TYPE -i /dev/sda</code></p>
<p>where TYPE is usually one of ata, scsi, or sat (for serial ata). See the smartctl man page for more information. Note that if you need -d here, you will need to add it to all smartctl commands. This should print information similar to:</p>
<pre>=== START OF INFORMATION SECTION ===
Model Family:     SAMSUNG SpinPoint T133 series
Device Model:     SAMSUNG HD300LJ
Serial Number:    S0D7J1UL303628
Firmware Version: ZT100-12
User Capacity:    300,067,970,560 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  ATA/ATAPI-7 T13 1532D revision 4a
Local Time is:    Fri Jan  2 03:08:20 2009 EST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled</pre>
<p>Now that smartctl can access the drive, let&#8217;s turn on some features. Run the following command:</p>
<p><code>$ sudo smartctl -s on -o on -S on /dev/sda</code></p>
<ul>
<li><strong>-s on</strong>: This turns on S.M.A.R.T. support or does nothing if it&#8217;s already enabled.</li>
<li><strong>-o on</strong>: This turns on offline data collection. Offline data collection periodically updates certain S.M.A.R.T. attributes. Theoretically this could have a performance impact. However, from the smartctl man page:<br />
<blockquote><p>Normally, the disk will suspend offline testing while disk accesses are taking place, and then automatically resume it when the disk would otherwise be idle, so  in  practice  it has little effect.</p></blockquote>
</li>
<li><strong>-S on</strong>: This enables &#8220;autosave of device vendor-specific Attributes&#8221;.</li>
</ul>
<p>The command should return:</p>
<pre>=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.
SMART Attribute Autosave Enabled.
SMART Automatic Offline Testing Enabled every four hours.</pre>
<p>Next, let&#8217;s check the overall health:</p>
<p><code>$ sudo smartctl -H /dev/sda</code></p>
<p>This command should return:</p>
<pre>=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED</pre>
<p>If it doesn&#8217;t return PASSED, you should immediately backup all your data. Your hard drive is probably failing. Next, let&#8217;s make sure that the drive supports self-tests. I have yet to see a drive that doesn&#8217;t, but the following command also gives time estimates for each test:</p>
<p><code>$ sudo smartctl -c /dev/sda</code></p>
<p>I won&#8217;t list the complete output because it&#8217;s somewhat lengthy. Make sure &#8220;Self-test supported&#8221; appears in the &#8220;Offline data collection capabilities&#8221; section. Also, look for output similar to:</p>
<pre>Short self-test routine
recommended polling time: 	 (   2) minutes.
Extended self-test routine
recommended polling time: 	 ( 127) minutes.</pre>
<p>These are rough estimates of how long the short and long self-test&#8217;s will take respectively. Let&#8217;s run the short test:</p>
<p><code>$ sudo smartctl -t short /dev/sda</code></p>
<p>On my drive, this test should take 2 minutes, but this obviously varies. You can run:</p>
<p><code>$ sudo smartctl -l selftest /dev/sda</code></p>
<p>to check results. Unfortunately, there&#8217;s no way to check progress, so just keep running that command until the results show up. A successful run will look like:</p>
<pre>=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%     21472         -</pre>
<p>Now, do the same for the long self-test:</p>
<p><code>$ sudo smartctl -t long /dev/sda</code></p>
<p>The long test can take a significant amount of time. You might want to run it overnight and check for the results in the morning. If either test fails, you should immediately backup all your data and read the last section of this guide.</p>
<h3>Configuring smartd</h3>
<p>We&#8217;ve now enabled some features and run the basic tests. Instead of repeating the previous section daily, we can setup smartd to do it all automatically. If your system has an /etc/smartd.conf file, check for a line that begins with DEVICESCAN. If you find one comment it out by adding a &#8216;#&#8217; to the beginning of the line. DEVICESCAN doesn&#8217;t work on my system and specifying a device file is easy. Add the following line to /etc/smartd.conf:</p>
<pre>/dev/sda -a -d sat -o on -S on -s (S/../.././02|L/../../6/03) -m root -M exec /usr/share/smartmontools/smartd-runner</pre>
<p>Here&#8217;s what each option does:</p>
<ul>
<li><strong>/dev/sda</strong>: Replace this with the device file you&#8217;ve been using in smartctl commands.</li>
<li><strong>-a</strong>: This enables some common options. You almost certainly want to use it.</li>
<li><strong>-d sat</strong>: On my system, smartctl correctly guesses that I have a serial ata drive. smartd on the other hand does not. If you had to add a &#8220;-d TYPE&#8221; parameter to the smartctl commands, you&#8217;ll almost certainly have to do the same here. If you didn&#8217;t, try leaving it out initially. You can add it later if smartd fails to start.</li>
<li><strong>-o on, -S on</strong>: These have the same meaning as the smartctl equivalents</li>
<li><strong>-s (S/../.././02|L/../../6/03)</strong>: This schedules the short and long self-tests. In this example, the short self-test will run daily at 2:00 A.M. The long test will run on Saturday&#8217;s at 3:00 A.M. For more information, see the smartd.conf man page.</li>
<li><strong>-m root</strong>: If any errors occur, smartd will send email to root. On my system, mail for root is forwarded to my normal email account. If you don&#8217;t have a similar setup, replace root with your normal email address. This option also requires a working email setup. Most Linux distributions automatically have working outbound email.</li>
<li><strong>-M exec /usr/share/smartmontools/smartd-runner</strong>: This last part may be specific to the Debian and Ubuntu smartmontools packages. Check if your system has /usr/share/smartmontools/smartd-runner. If it doesn&#8217;t, remove this option. Instead of sending email directly, &#8220;-M exec&#8221; makes smartd run a different command when errors occur. On Debian, smartd-runner will run each script in /etc/smartmontools/run.d/, one of which emails the user specified by the &#8220;-m&#8221; option.</li>
</ul>
<p>If you have more than one hard drive in your system, add a line for each one replacing /dev/sda with a different device file.</p>
<div class="update">
<p><strong>Update on 2009-01-06:</strong></p>
<p>Thanks to commenter robert for pointing out an omission on my part. If your system has the file /etc/default/smartmontools, uncomment the &#8220;#start_smartd=yes&#8221; line by removing the &#8220;#&#8221;.</p></div>
<p>Finally, restart smartd:</p>
<p><code>$ sudo /etc/init.d/smartmontools restart</code></p>
<p>If this command fails, the end of /var/log/daemon.log should have some diagnostic information. If smartd started fine, we should still test that email notifications are working. Add &#8220;-M test&#8221; to the end of the configuration line in /etc/smartd.conf. This will make smartd send out a test notification when it&#8217;s next started. Once again, restart smartd:</p>
<p><code>$ sudo /etc/init.d/smartmontools restart</code></p>
<p>You should receive an email similar to:</p>
<pre>This email was generated by the smartd daemon running on:

   host name: polar
  DNS domain: shadypixel.com
  NIS domain: (none)

The following warning/error was logged by the smartd daemon:

TEST EMAIL from smartd for device: /dev/sda

For details see host's SYSLOG (default: /var/log/syslog).</pre>
<p>Afterward, you can delete &#8220;-M test&#8221;.</p>
<h3>What To Do If smartd Detects Problems</h3>
<p>First, immediately backup everything. Depending on the error, your drive might be close to death or it may still have a long life ahead. Consult the <a href="http://smartmontools.sourceforge.net/faq.html" onclick="javascript:pageTracker._trackPageview ('/outbound/smartmontools.sourceforge.net');">smartmontools FAQ</a>. It has some recommendations for specific errors. Otherwise, ask for help on the <a href="https://lists.sourceforge.net/lists/listinfo/smartmontools-support" onclick="javascript:pageTracker._trackPageview ('/outbound/lists.sourceforge.net');">smartmontools-support mailing list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/monitoring-hard-drive-health-on-linux-with-smartmontools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Updated awstats for Debian</title>
		<link>http://blog.shadypixel.com/updated-awstats-for-debian/</link>
		<comments>http://blog.shadypixel.com/updated-awstats-for-debian/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 06:19:00 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[awstats]]></category>

		<category><![CDATA[debian]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=67</guid>
		<description><![CDATA[The awstats package in Debian is pretty outdated. Etch has version 6.5. Sid has 6.7. Version 6.9 was released on December 28, 2008. I&#8217;m a statistics junky and the new version has better robot detection so I built an updated package on my lenny/sid machine: awstats_69-1_all.deb. This package also works perfectly on my etch server without [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://awstats.sourceforge.net/" onclick="javascript:pageTracker._trackPageview ('/outbound/awstats.sourceforge.net');">awstats</a> package in Debian is pretty outdated. Etch has version 6.5. Sid has 6.7. Version 6.9 was released on December 28, 2008. I&#8217;m a statistics junky and the new version has better robot detection so I built an updated package on my lenny/sid machine: <a href="https://blog.shadypixel.com/wp-content/uploads/2008/12/awstats_69-1_all.deb" onclick="javascript:pageTracker._trackPageview ('/download/awstats_69-1_all.deb');">awstats_69-1_all.deb</a>. This package also works perfectly on my etch server without changes.</p>
<p>I did apply all the Debian patches that were still relevant so it should be the equivalent of the official Debian package.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/updated-awstats-for-debian/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Shrink an LVM Volume Safely</title>
		<link>http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/</link>
		<comments>http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 10:38:04 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[admin]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[lvm]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=63</guid>
		<description><![CDATA[Logical Volume Management is a vast improvement over standard partitioning schemes. Among many other things, it allows you to decrease the size of a volume without recreating it completely. Here&#8217;s how.

First, as is always the case when you&#8217;re modifying disk volumes, partitions, or file systems, you should really have a recent backup. A typo in [...]]]></description>
			<content:encoded><![CDATA[<p>Logical Volume Management is a vast improvement over standard partitioning schemes. Among many other things, it allows you to decrease the size of a volume without recreating it completely. Here&#8217;s how.</p>
<p><span id="more-63"></span></p>
<p>First, as is always the case when you&#8217;re modifying disk volumes, partitions, or file systems, you should really have a recent backup. A typo in one the following commands could easily destroy data. You have been warned!</p>
<p>All of the required steps must be performed on an unmounted volume. If want to reduce the size of a non-root volume, simply unmount it. For a root volume, you&#8217;ll have to boot from a CD. Any modern live or rescue CD should work fine. I prefer <a href="http://www.sysresccd.org/Main_Page" onclick="javascript:pageTracker._trackPageview ('/outbound/www.sysresccd.org');">SystemRescueCD</a>. It includes almost any disk management programs you might need. After booting from a CD, you may have to issue:</p>
<p><code># vgchange -a y</code></p>
<p>This makes any logical volumes available to the Linux. Most boot CD&#8217;s will do it automatically some time during the boot process, but repeating the command won&#8217;t hurt. Next, force a file system check on the volume in question:</p>
<p><code># e2fsck -f /dev/polar/root</code></p>
<p>Device names for LVM volumes follow the convention: <code>/dev/&lt;volume group&gt;/&lt;logical volume&gt;</code>. In this case, my volume group is named polar and the volume I&#8217;m going to shrink is named root. This is a critical step; resizing a file system in an inconsistent state could have disastrous consequences. Next, resize the actual file system:</p>
<p><code># resize2fs /dev/polar/root 180G</code></p>
<p>Replace 180G with about 90% of the size you want the final volume to be. For example, in this case, I want the final volume to be 200 gigabytes, so I&#8217;ll reduce the file system to 180 gigabytes. Why is this necessary? When we reduce the size of the actual volume in the next step, it&#8217;s critical that the new size is greater than or equal to the size of the file system. After reading the documentation for both <code>resizefs</code> and <code>lvreduce</code>, I still haven&#8217;t been able to find out whether they&#8217;re using standard computer gigabytes (1024^3 bytes) or drive manufacturer gigabytes (1000^3 bytes). In this case, the difference is very important. To be on the safe side, we&#8217;ll just shrink the file system a bit more than necessary and expand it to use the full space available later. Next, reduce the size of the logical volume:</p>
<p><code># lvreduce -L 200G /dev/polar/root</code></p>
<p>In this case, use the actual size you want to the volume to be. Finally, grow the file system so that it uses all available space on the logical volume:</p>
<p><code># resize2fs /dev/polar/root</code></p>
<p>That&#8217;s it. Enjoy your newly acquired free space.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fixing uTorrent File Associations in Linux</title>
		<link>http://blog.shadypixel.com/fixing-utorrent-file-associations-in-linux/</link>
		<comments>http://blog.shadypixel.com/fixing-utorrent-file-associations-in-linux/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 13:13:14 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[gnome]]></category>

		<category><![CDATA[utorrent]]></category>

		<category><![CDATA[wine]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=55</guid>
		<description><![CDATA[Running uTorrent under wine works pretty well in Linux. For a quick overview of installation, see this HowTo Ubuntu blog post. One problem with installing under wine is that file associations are not set correctly. This means that double-clicking a .torrent file or opening a .torrent link in your browser won&#8217;t automatically start uTorrent. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Running uTorrent under wine works pretty well in Linux. For a quick overview of installation, see <a href="http://www.howtoubuntu.com/2007/10/21/how-to-install-utorrent-in-ubuntu-with-wine.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.howtoubuntu.com');">this HowTo Ubuntu blog post</a>. One problem with installing under wine is that file associations are not set correctly. This means that double-clicking a .torrent file or opening a .torrent link in your browser won&#8217;t automatically start uTorrent. Here&#8217;s how to solve that.</p>
<p><span id="more-55"></span></p>
<p>First, create a file called utorrent with the following content:</p>
<pre>#!/bin/sh

if [ "$1" ]; then
    torrent_file="Z:`echo $1 | sed 's/\//\\\/g'`"
    env WINEPREFIX="/home/avery/.wine" wine \
        "C:\\Program Files\\uTorrent\\uTorrent.exe" "$torrent_file"
else
    env WINEPREFIX="/home/avery/.wine" wine \
        "C:\\Program Files\\uTorrent\\uTorrent.exe"
fi</pre>
<p>Replace /home/avery with the path to your home directory. Make sure to make the file executable:</p>
<p><code>$ chmod +x utorrent</code></p>
<p>This is the main script that we&#8217;ll start uTorrent with. Basically, if given a file path on the command line, it will transform it from a linux path to a wine path. <code>/tmp/sample.torrent</code> will become <code>Z:\tmp\sample.torrent</code>. The sed bit comes from <a href="http://ubuntuforums.org/showthread.php?t=587040" onclick="javascript:pageTracker._trackPageview ('/outbound/ubuntuforums.org');">an Ubuntu forums thread</a>.</p>
<p>Next, we need to fix the .desktop file. It should be located at <code>~/.local/share/applications/wine/µTorrent.desktop</code> and contain something like:</p>
<pre>[Desktop Entry]
Name=µTorrent
Exec=env WINEPREFIX="/home/avery/.wine" wine \
    "C:\\Program Files\\uTorrent\\uTorrent.exe"
Type=Application
StartupWMClass=Wine
Icon=6948_utorrent.0</pre>
<p>Add the following two lines to the end of the file:</p>
<pre>Categories=Network;FileTransfer;P2P
MimeType=application/x-bittorrent</pre>
<p>The first line makes uTorrent show up correctly in the GNOME menu system. The next associates uTorrent with the BitTorrent MIME type. Also, change the Exec line to:</p>
<pre>Exec=/home/avery/bin/utorrent %f</pre>
<p>Obviously, replace the path with wherever you put the utorrent script from above. The .desktop file should now contain:</p>
<pre>[Desktop Entry]
Name=µTorrent
Exec=/home/avery/bin/utorrent %f
Type=Application
StartupWMClass=Wine
Icon=6948_utorrent.0
Categories=Network;FileTransfer;P2P
MimeType=application/x-bittorrent</pre>
<p>To make uTorrent the default BitTorrent client, edit <code>~/.local/share/applications/defaults.list</code>:</p>
<pre>[Default Applications]
application/x-bittorrent=µTorrent.desktop</pre>
<p>This file might already exist, in which case you can just add the second line. Finally, we need to update GNOME&#8217;s file associations database:</p>
<p><code>$ update-desktop-database ~/.local/share/applications</code></p>
<p>Success:</p>
<div id="attachment_56" class="wp-caption alignnone" style="width: 472px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/08/utorrent-iceweasel.png"><img class="size-full wp-image-56" title="start uTorrent from iceweasel" src="https://blog.shadypixel.com/wp-content/uploads/2008/08/utorrent-iceweasel.png" alt="Iceweasel offers to open a torrent with uTorrent running under wine." width="462" height="339" /></a><p class="wp-caption-text">Iceweasel offers to open a torrent with uTorrent running under wine.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/fixing-utorrent-file-associations-in-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>RealPlayer on x86_64 (amd64) Debian Linux</title>
		<link>http://blog.shadypixel.com/realplayer-on-x86_64-amd64-linux/</link>
		<comments>http://blog.shadypixel.com/realplayer-on-x86_64-amd64-linux/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 07:34:53 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[amd64]]></category>

		<category><![CDATA[debian]]></category>

		<category><![CDATA[realplayer]]></category>

		<category><![CDATA[x86_64]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=41</guid>
		<description><![CDATA[There are a few tricks to getting RealPlayer to work right under x86_64 Linux. Realplayer is a 32-bit application and needs a bit of coercing to run smoothly.

First, get the installer from Real&#8217;s site. Download the normal installer, named something like RealPlayer11GOLD.bin, instead of the RPM version. To use the installer and RealPlayer, you&#8217;ll need [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few tricks to getting RealPlayer to work right under x86_64 Linux. Realplayer is a 32-bit application and needs a bit of coercing to run smoothly.</p>
<p><span id="more-41"></span></p>
<p>First, get the installer from <a href="http://www.real.com/linux" onclick="javascript:pageTracker._trackPageview ('/outbound/www.real.com');">Real&#8217;s site</a>. Download the normal installer, named something like RealPlayer11GOLD.bin, instead of the RPM version. To use the installer and RealPlayer, you&#8217;ll need to get 32-bit versions of some common libraries.</p>
<p><code>$ sudo apt-get install ia32-lib ia32-libs-gtk</code></p>
<p>Navigate to the directory where you saved the installer and run:</p>
<p><code>$ chmod +x ./RealPlayer11GOLD.bin<br />
$ ./RealPlayer11GOLD.bin</code></p>
<p>The installation is self-explanatory. I installed to ~/software/RealPlayer. The installer adds a link in the GNOME Sound &amp; Video menu. It doesn&#8217;t work though.</p>
<div id="attachment_42" class="wp-caption alignnone" style="width: 350px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-error.png"><img class="size-full wp-image-42" title="RealPlayer error" src="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-error.png" alt="Error after running RealPlayer from the menu entry" width="340" height="173" /></a><p class="wp-caption-text">Error after running RealPlayer from the menu entry</p></div>
<p>This is because I installed as a normal user instead of root. It didn&#8217;t add a link to RealPlayer in the system path. To solve this problem, add a shell script like the following to a directory in your path:</p>
<pre>#!/bin/bash
exec /home/avery/software/RealPlayer/realplay $@</pre>
<p>Name the script realplay and make it executable. Obviously, replace /home/avery/software/RealPlayer with whatever directory you installed RealPlayer to. I put this script in ~/bin, which is in my path. Now, you should be able to launch RealPlayer from the command line, but the menu item still might not work. If you added the script to a location in the system path, like /usr/bin, it will work fine. In my case, I put it in ~/bin, which is in my path, but not the system path. To fix this, you can modify the .desktop entry for RealPlayer, which is installed as ~/.local/share/applications/realplay.desktop. Replace the line:</p>
<pre>Exec=realplay %U</pre>
<p>with:</p>
<pre>Exec=/home/avery/bin/realplay %U</pre>
<p>The GNOME menu doesn&#8217;t expand ~, so you need to enter the full path to the script. Now, the menu item should work. The next thing you might notice is that while RealPlayer works, it looks awful.</p>
<div id="attachment_45" class="wp-caption alignnone" style="width: 338px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-ugly.png"><img class="size-full wp-image-45" title="Ugly RealPlayer" src="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-ugly.png" alt="RealPlayer with image loader errors" width="328" height="349" /></a><p class="wp-caption-text">RealPlayer with image loader errors</p></div>
<p>This happens because Debian&#8217;s version of ia32-libs-gtk has some packaging bugs. See <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484581" onclick="javascript:pageTracker._trackPageview ('/outbound/bugs.debian.org');">Debian bug #484581</a>. To solve this, we&#8217;ll run RealPlayer in a 32-bit chroot instead of using 32-bit libraries in a normal x86_64 installation. I&#8217;m not going to get into setting up a 32-bit chroot here. Instead follow <a href="http://alioth.debian.org/docman/view.php/30192/21/debian-amd64-howto.html#id292281" onclick="javascript:pageTracker._trackPageview ('/outbound/alioth.debian.org');">the instructions</a> in the <a href="http://alioth.debian.org/docman/view.php/30192/21/debian-amd64-howto.html" onclick="javascript:pageTracker._trackPageview ('/outbound/alioth.debian.org');">Debian GNU/linux AMD64 HOW-TO</a>. Be sure to setup schroot. schroot makes using a 32-bit chroot very simple. Once the chroot is setup and schroot is working, modify the realplay script as follows:</p>
<pre>#!/bin/bash
real_path=/home/avery/software/RealPlayer/realplay
if [ -f /etc/debian_chroot ]; then
    exec $real_path $@
else
    exec schroot -p $real_path $@
fi</pre>
<p>Basically, if the /etc/debian_chroot file exists, it runs RealPlayer directly. Otherwise, it runs RealPlayer using schroot.  I don&#8217;t think standard chroot creates the /etc/debian_chroot file, but schroot does. The reason the script doesn&#8217;t always run RealPlayer using schroot is that applications that are already in a chroot, like firefox, may need to run RealPlayer. There&#8217;s no point in creating yet another chroot if we&#8217;re already in one.</p>
<div id="attachment_46" class="wp-caption alignnone" style="width: 296px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-working.png"><img class="size-full wp-image-46" title="RealPlayer working" src="https://blog.shadypixel.com/wp-content/uploads/2008/08/realplayer-working.png" alt="Running RealPlayer in a chroot" width="286" height="209" /></a><p class="wp-caption-text">Running RealPlayer in a chroot</p></div>
<p>It works!</p>
<p>Update: After a bit of testing, I think it&#8217;s better to add a link to the realplay script system-wide. In addition to the GNOME menus, firefox only looks in system-wide paths. You&#8217;ll probably want to add a link in your chroot as well:</p>
<p><code>$ sudo ln -s /home/avery/bin/realplay /usr/bin/realplay<br />
$ sudo ln -s /home/avery/bin/realplay /var/chroot/lenny-ia32/usr/bin/realplay</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/realplayer-on-x86_64-amd64-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Making KDE Play Nice on a GNOME Desktop</title>
		<link>http://blog.shadypixel.com/making-kde-play-nice-on-a-gnome-desktop/</link>
		<comments>http://blog.shadypixel.com/making-kde-play-nice-on-a-gnome-desktop/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 01:07:37 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[debian]]></category>

		<category><![CDATA[gnome]]></category>

		<category><![CDATA[kde]]></category>

		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=30</guid>
		<description><![CDATA[I prefer GNOME for the most part, but some KDE applications are simply better than their GNOME counterparts. That said, there are some problems getting them to work well together. I recently discovered that installing k3b cause my GNOME menus to, for lack of a better word, explode. Here&#8217;s how I went about fixing them.

First, [...]]]></description>
			<content:encoded><![CDATA[<p>I prefer GNOME for the most part, but some KDE applications are simply better than their GNOME counterparts. That said, there are some problems getting them to work well together. I recently discovered that installing k3b cause my GNOME menus to, for lack of a better word, explode. Here&#8217;s how I went about fixing them.</p>
<p><span id="more-30"></span></p>
<p>First, to give you some idea of what I mean by explode, take a look at this:</p>
<div id="attachment_32" class="wp-caption alignnone" style="width: 202px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/07/kde-explosion.png"><img class="size-medium wp-image-32" title="KDE explosion" src="https://blog.shadypixel.com/wp-content/uploads/2008/07/kde-explosion-192x300.png" alt="KDE explosion in the GNOME menus" width="192" height="300" /></a><p class="wp-caption-text">KDE explosion in the GNOME menus</p></div>
<p>All of that comes from installing k3b. The problem is that KDE doesn&#8217;t honor the freedesktop.org <a href="http://standards.freedesktop.org/menu-spec/latest/" onclick="javascript:pageTracker._trackPageview ('/outbound/standards.freedesktop.org');">Desktop Menu Specification</a>. Specifically, KDE should be putting <a href="http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html" onclick="javascript:pageTracker._trackPageview ('/outbound/standards.freedesktop.org');">OnlyShowIn</a> entries into their .desktop files that shouldn&#8217;t be displayed in GNOME. This isn&#8217;t exactly a new problem. Given the fact that <a href="http://bugs.kde.org/show_bug.cgi?id=63933" onclick="javascript:pageTracker._trackPageview ('/outbound/bugs.kde.org');">kicker bug #63933</a> was logged in 2003 and still isn&#8217;t fixed, I figured I&#8217;d have to fix it myself.</p>
<p>Here&#8217;s my solution. For each .desktop file in each package specified, this script will add OnlyShowIn=KDE if it isn&#8217;t already present.</p>
<pre>#!/bin/bash

package_list="kamera kcontrol kdebase-data kdebase-kio-plugins \
              kdemultimedia-kio-plugins libkcddb1"

for package in $package_list; do
    for desktop_file in `dpkg -L $package | grep 'applications/.*\.desktop'`; do
        count=`grep -c -i OnlyShowIn $desktop_file`
        if [ $count -eq 0 ]; then
            echo "Modifying $package: $desktop_file"
            echo 'OnlyShowIn=KDE;' &gt;&gt; $desktop_file
        fi
    done
done</pre>
<p>It needs to be run with sudo or as root since it&#8217;s modifying system files. Also, the list of packages I provided are not comprehensive. They&#8217;re simply the ones that I noticed didn&#8217;t honor the specification. If you aren&#8217;t using Debian or Ubuntu, you&#8217;ll have to modify the dpkg command to the equivalent rpm command.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/making-kde-play-nice-on-a-gnome-desktop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Monitoring a UPS with nut on Debian or Ubuntu Linux</title>
		<link>http://blog.shadypixel.com/monitoring-a-ups-with-nut-on-debian-or-ubuntu-linux/</link>
		<comments>http://blog.shadypixel.com/monitoring-a-ups-with-nut-on-debian-or-ubuntu-linux/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 20:26:07 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[debian]]></category>

		<category><![CDATA[nut]]></category>

		<category><![CDATA[ubuntu]]></category>

		<category><![CDATA[ups]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=6</guid>
		<description><![CDATA[There are two different ways to monitor a UPS with nut: either expose the UPS hardware to GNOME Power Manager through hal or monitor the UPS directly with upsmon and upsd. There are trade-offs with each approach. Let&#8217;s take a look at both.

Use GNOME Power Manager and hal
On Debian or Ubuntu systems, install the nut-hal-drivers [...]]]></description>
			<content:encoded><![CDATA[<p>There are two different ways to monitor a <abbr title="Uninterruptible Power Supply">UPS</abbr> with <a href="http://eu1.networkupstools.org/" title="Network UPS Tools" onclick="javascript:pageTracker._trackPageview ('/outbound/eu1.networkupstools.org');">nut</a>: either expose the UPS hardware to GNOME Power Manager through hal or monitor the UPS directly with upsmon and upsd. There are trade-offs with each approach. Let&#8217;s take a look at both.</p>
<p><span id="more-6"></span></p>
<h3>Use GNOME Power Manager and hal</h3>
<p>On Debian or Ubuntu systems, install the nut-hal-drivers package.</p>
<p><code>$ sudo apt-get install nut-hal-drivers</code></p>
<p>GNOME Power Manager should already be running and should automatically detect the UPS. If it&#8217;s not running, you can start it from the command line or set it to start automatically in each session with the Sessions system preference. An icon will appear in the system tray if everything is working.</p>
<div id="attachment_8" class="wp-caption alignnone" style="width: 267px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/07/gpm-tooltip.png"><img class="size-full wp-image-8" title="system tray icon and tooltip" src="https://blog.shadypixel.com/wp-content/uploads/2008/07/gpm-tooltip.png" alt="GNOME Power Manager system tray icon and tooltip." width="257" height="104" /></a><p class="wp-caption-text">GNOME Power Manager system tray icon and tooltip.</p></div>
<p>Clicking the system tray icon and selecting UPS from the menu will give detailed information.</p>
<div id="attachment_11" class="wp-caption alignnone" style="width: 459px"><a href="https://blog.shadypixel.com/wp-content/uploads/2008/07/gpm-ups.png"><img class="size-full wp-image-11" title="UPS details" src="https://blog.shadypixel.com/wp-content/uploads/2008/07/gpm-ups.png" alt="GNOME Power Manager UPS details." width="449" height="254" /></a><p class="wp-caption-text">GNOME Power Manager UPS details.</p></div>
<p>GNOME Power Manager can be configured to shutdown or hibernate the computer when the UPS battery level drops below certain thresholds. There are also gconf keys to change which thresholds are used, percentage or time left, and what those thresholds are.</p>
<p>This method of monitoring a UPS is useful for a workstation, but there are three significant disadvantages:</p>
<ol>
<li>GNOME Power Manager is not running when you aren&#8217;t logged in. If your machine loses power at the login screen, it will not shutdown automatically.</li>
<li>Currently, the nut-hal-drivers package only supports USB-based UPS&#8217;s. Many older and higher-end UPS&#8217;s are serial-based.</li>
<li>GNOME Power Manager&#8217;s UPS support is buggy. While it displays notifications of low battery and critically low battery, it doesn&#8217;t take any actions. See <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482431" onclick="javascript:pageTracker._trackPageview ('/outbound/bugs.debian.org');">Debian bug #482431</a> and <a href="http://bugzilla.gnome.org/show_bug.cgi?id=539843" onclick="javascript:pageTracker._trackPageview ('/outbound/bugzilla.gnome.org');">GNOME bug #539843</a>.</li>
</ol>
<div class="update">
<p><strong>Update on 2009-01-06:</strong></p>
<p>Arnaud Quette, the nut project leader, informed me of two other significant disadvantages with using nut-hal-drivers:</p>
<ol>
<li>gnome-power-manager will not power off the UPS at the end of a shutdown from power failure. This means that either the UPS will be fully drained, or worse, power will be restored before the battery is fully drained and the computer will not automatically start up again.</li>
<li>No further work will be done on nut-hal-drivers. HAL is going to be replaced with DeviceKit and nut-hal-drivers will be replaced with DeviceKit-power.</li>
</ol>
<p>Conclusion: Don&#8217;t use nut-hal-drivers unless you really, really want a fancy notification icon.</p></div>
<h3>Use nutd and upsmon</h3>
<p>Install the nut package. This should conflict with nut-hal-drivers if it&#8217;s already installed.</p>
<p><code>$ sudo apt-get install nut</code></p>
<p>Installing the nut package, should add the nut user and group. If it doesn&#8217;t, you have to add those manually. Next, create or edit /etc/nut/ups.conf:</p>
<pre># /etc/nut/ups.conf

[apc]
    driver = usbhid-ups
    port = auto</pre>
<p>The label in the square brackets can be anything. It identifies the UPS to upsd and upsmon. Find your UPS model on the <a href="http://eu1.networkupstools.org/compat/stable.html" onclick="javascript:pageTracker._trackPageview ('/outbound/eu1.networkupstools.org');">NUT hardware compatibility list</a> and substitute the corresponding driver for usbhid-ups above. If your UPS isn&#8217;t listed, find similar ones. They probably use the same driver. If you have a USB-based UPS, you can leave the port as auto; it&#8217;s ignored. Otherwise, the port will usually be /dev/ttyS0, the first serial port, or /dev/ttyS1, the second. If your UPS is connected via the serial port, you&#8217;ll need to modify the permissions on the serial port device so that nut can access it. Create the file /etc/udev/rules.d/99_nut-serialups.rules:</p>
<pre># /etc/udev/rules.d/99_nut-serialups.rules
KERNEL=="ttyS0", GROUP="nut"</pre>
<p>Replace ttyS0 with ttyS1 if your UPS is connected to the second serial port. Next, issue the following two commands to force udev to make the necessary permissions change:</p>
<p><code>$ sudo udevadm control --reload_rules<br />
$ sudo udevadm control trigger</code></p>
<p>Note that the preceding two steps are unnecessary if you have USB-based UPS. Finally, we can make sure that nut properly detects the UPS:</p>
<p><code>$ sudo upsdrvctl start</code></p>
<p>You should see something like the following:</p>
<pre>Network UPS Tools - UPS driver controller 2.2.2
Network UPS Tools: 0.29 USB communication driver - core 0.33 (2.2.2)

Using subdriver: APC HID 0.92</pre>
<p>Now, we need to configure upsd and upsmon. upsd communicates with the UPS driver that we just started. upsmon communicates with upsd and actually shuts down the machine in the event of a power failure. Why the extra level of indirection? Multiple instances of upsmon can be started on different machines. They can all share the same physical UPS. Create the file /etc/nut/upsd.conf as follows:</p>
<pre># /etc/nut/upsd.conf
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
ACCEPT localhost
REJECT all</pre>
<p>This rejects all connections not originating from the local machine. If you need to monitor from multiple machines, see the man page for upsd.conf. Next, create /etc/nut/upsd.users:</p>
<pre># /etc/nut/upsd.users
[local_mon]
    password = PASSWORD_HERE
    allowfrom = localhost
    upsmon master</pre>
<p>Replace PASSWORD_HERE with a real password. You should add multiple users if you are monitoring from multiple machines. See the man page for upsd.users for more information. Now we need to configure upsmon. Create /etc/nut/upsmon.conf as follows:</p>
<pre># /etc/nut/upsmon.conf
MONITOR apc@localhost 1 local_mon PASSWORD_HERE master
POWERDOWNFLAG /etc/killpower
SHUTDOWNCMD "/sbin/shutdown -h now"</pre>
<p>Replace apc with the name you have your UPS in /etc/nut/ups.conf and PASSWORD_HERE with the password you set in /etc/nut/upsd.users. Since these files contain sensitive data, we should fix the permissions:</p>
<p><code>$ sudo chown root:nut /etc/nut/*<br />
$ sudo chmod 640 /etc/nut/*</code></p>
<p>Finally, edit /etc/default/nut so that upsd and upsmon will start at system boot:</p>
<pre># /etc/default/nut
START_UPSD=yes
START_UPSMON=yes</pre>
<p>The moment of truth:</p>
<p><code>$ sudo /etc/init.d/nut start</code></p>
<p>Check the end of /var/log/daemon.log to make sure everything started up. Also, you can run the following command which should print out some statistics:</p>
<p><code>$ upsc apc</code></p>
<p>Replace apc with whatever you named your UPS. What&#8217;s left? Save your work, unplug the UPS, and make sure your machine shuts down cleanly. This may take a while. By default, upsmon waits until the battery is at a critically low level before initiating a shutdown. What&#8217;s the point of having 20 minutes of battery life if you aren&#8217;t going to use it?</p>
<p>As you can see, this second method is quite a bit more difficult to configure. That said, using upsd and upsmon, as opposed to nut-hal-drivers, is probably the more reliable method of monitoring a UPS. It&#8217;s also the only option available if you need to monitor one UPS from multiple machines.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/monitoring-a-ups-with-nut-on-debian-or-ubuntu-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>init</title>
		<link>http://blog.shadypixel.com/init/</link>
		<comments>http://blog.shadypixel.com/init/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 18:07:42 +0000</pubDate>
		<dc:creator>btmorex</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.shadypixel.com/?p=3</guid>
		<description><![CDATA[srandom(time(0));
]]></description>
			<content:encoded><![CDATA[<p><code>srandom(time(0));</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shadypixel.com/init/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
