<?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>Erning.write() &#187; gentoo</title>
	<atom:link href="http://erning.net/tags/gentoo/feed" rel="self" type="application/rss+xml" />
	<link>http://erning.net</link>
	<description>Reloading</description>
	<lastBuildDate>Fri, 18 Jun 2010 18:05:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>USB硬盘的固定设备名和自动休眠</title>
		<link>http://erning.net/archives/static-device-name-and-auto-spin-down-for-usb-harddisk</link>
		<comments>http://erning.net/archives/static-device-name-and-auto-spin-down-for-usb-harddisk#comments</comments>
		<pubDate>Sat, 23 Jan 2010 18:07:26 +0000</pubDate>
		<dc:creator>erning</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gentoo]]></category>

		<guid isPermaLink="false">http://erning.net/?p=186</guid>
		<description><![CDATA[AirPort Extreme可以外接USB硬盘提供文件服务，但是和它的路由功能一样，都不够满足我的需求。而作为穿墙路由器的华硕小机器有4个USB口，我还用它兼作文件服务器使用，提供Samba和NFS。 但是Gentoo在这里遇到两个小问题。 第一个问题，USB硬盘是可以热拔插，这样由于载入顺序的问题，每个硬盘设备名称可能会变化。例如这个机器自带一个读卡器，在没有外挂USB硬盘时启动后候设备名为/dev/sdb。之后插入USB硬盘，USB硬盘的设备名为/dev/sdc。但是如果挂着USB硬盘启动，这两个设备的设备名就正好反过来了。我希望是固定的设备名。 第二个问题，USB硬盘长时间不访问的时候不会自动停下来，这样既不省电也不利延长硬盘的寿命。我希望在不用的时候它可以休眠。 设备名的问题可以用udev的rules解决。我加了一个udev配置文件/etc/udev/rules.d/99-external-storages.rules。 [plain gutter="false"] KERNEL==&#8221;sd*&#8221;, SUBSYSTEMS==&#8221;usb&#8221;, ATTRS{idVendor}==&#8221;0bda&#8221;, ATTRS{idProduct}==&#8221;0158&#8243;, ATTRS{serial}==&#8221;20071114173400000&#8243;, SYMLINK+=&#8221;cardreader%n&#8221; KERNEL==&#8221;sd*&#8221;, SUBSYSTEMS==&#8221;usb&#8221;, ATTRS{idVendor}==&#8221;1bcf&#8221;, ATTRS{idProduct}==&#8221;0c31&#8243;, ATTRS{serial}==&#8221;20090717090A&#8221;, SYMLINK+=&#8221;storage/neso%n&#8221; [/plain] 这样给内置的读卡器添加了一个设备名的符号链接/dev/cardreader；给我的NESO 1T硬盘添加了设备名符号链接/dev/storage/neso。用固定名称访问设备的问题就解决了。 第二个问题稍微复杂些，一直没找到方便的方法。laptop-mode-tools也没能满足我的要求。一番搜索后找到sdparm可以用来控制USB硬盘，还有一段perl脚本用来调度sdparm。这样就可以满足我的需求了。脚本的原始出外我给忘了，这里我稍微修改了一点，增加对设备名符号链接的支持。 [perl] #!/usr/bin/perl -w use File::Basename; use Cwd &#8216;abs_path&#8217;; $statfile = &#8220;/proc/diskstats&#8221;; die &#8220;$0: Cannot read $statfile\n&#8221; unless -r $statfile; $&#124; = 1; ($disk, $interval) = (@ARGV); if (-l $disk) { $original_disk [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.apple.com/airportextreme/">AirPort Extreme</a>可以外接USB硬盘提供文件服务，但是和它的路由功能一样，都不够满足我的需求。而作为<a href="/archives/my-linux-gateway">穿墙路由器</a>的华硕小机器有4个USB口，我还用它兼作文件服务器使用，提供Samba和NFS。</p>
<p>但是Gentoo在这里遇到两个小问题。</p>
<p>第一个问题，USB硬盘是可以热拔插，这样由于载入顺序的问题，每个硬盘设备名称可能会变化。例如这个机器自带一个读卡器，在没有外挂USB硬盘时启动后候设备名为/dev/sdb。之后插入USB硬盘，USB硬盘的设备名为/dev/sdc。但是如果挂着USB硬盘启动，这两个设备的设备名就正好反过来了。我希望是固定的设备名。</p>
<p>第二个问题，USB硬盘长时间不访问的时候不会自动停下来，这样既不省电也不利延长硬盘的寿命。我希望在不用的时候它可以休眠。</p>
<p>设备名的问题可以用udev的rules解决。我加了一个udev配置文件/etc/udev/rules.d/99-external-storages.rules。<br />
[plain gutter="false"]<br />
KERNEL==&#8221;sd*&#8221;, SUBSYSTEMS==&#8221;usb&#8221;, ATTRS{idVendor}==&#8221;0bda&#8221;, ATTRS{idProduct}==&#8221;0158&#8243;, ATTRS{serial}==&#8221;20071114173400000&#8243;, SYMLINK+=&#8221;cardreader%n&#8221;<br />
KERNEL==&#8221;sd*&#8221;, SUBSYSTEMS==&#8221;usb&#8221;, ATTRS{idVendor}==&#8221;1bcf&#8221;, ATTRS{idProduct}==&#8221;0c31&#8243;, ATTRS{serial}==&#8221;20090717090A&#8221;, SYMLINK+=&#8221;storage/neso%n&#8221;<br />
[/plain]<br />
这样给内置的读卡器添加了一个设备名的符号链接/dev/cardreader；给我的NESO 1T硬盘添加了设备名符号链接/dev/storage/neso。用固定名称访问设备的问题就解决了。</p>
<p>第二个问题稍微复杂些，一直没找到方便的方法。<a href="http://samwel.tk/laptop_mode/">laptop-mode-tools</a>也没能满足我的要求。一番搜索后找到<a href="http://sg.danny.cz/sg/sdparm.html">sdparm</a>可以用来控制USB硬盘，还有一段perl脚本用来调度sdparm。这样就可以满足我的需求了。脚本的原始出外我给忘了，这里我稍微修改了一点，增加对设备名符号链接的支持。<br />
[perl]<br />
#!/usr/bin/perl -w<br />
use File::Basename;<br />
use Cwd &#8216;abs_path&#8217;;</p>
<p>$statfile = &#8220;/proc/diskstats&#8221;;<br />
die &#8220;$0: Cannot read $statfile\n&#8221; unless -r $statfile;</p>
<p>$| = 1;<br />
($disk, $interval) = (@ARGV);</p>
<p>if (-l $disk) {<br />
    $original_disk = $disk;<br />
    while (-l $disk) {<br />
        $disk = readlink $disk;<br />
    }<br />
    $disk = dirname($original_disk) . &#8220;/&#8221; . $disk;<br />
    $disk = abs_path($disk);<br />
}</p>
<p>$disk =~ s,/dev/,,;<br />
print &#8220;$0: disk: $disk, interval: $interval\n&#8221;;</p>
<p>$halted_data = $last_seen = &#8221;;<br />
while (1) {<br />
  open(STATUS, $statfile);<br />
  ($_) = grep(/^\s+\d+\s+\d+\s+$disk\s/o, <STATUS>);<br />
  close STATUS;</p>
<p>  if ($last_seen eq $_ &#038;&#038; $halted_data ne $_) {<br />
    print &#8220;Spinning down: $disk\n&#8221;;<br />
    system &#8220;sync&#8221;;<br />
    system &#8220;sdparm&#8221;, &#8220;&#8211;command=stop&#8221;, &#8220;/dev/$disk&#8221;;<br />
    $halted_data = $_;<br />
  }<br />
  $last_seen = $_;<br />
  sleep $interval;<br />
}<br />
[/perl]</p>
<p>最后在启动脚本里加上<br />
[plain gutter="false"]<br />
ebegin &#8221;    &#8211; Spindown USB HD&#8221;<br />
nohup /usr/local/sbin/spindown-usbhd /dev/storage/neso 1200 >> /var/log/spindown-usbhd.log 2>&#038;1 &#038;<br />
eend $?<br />
[/plain]<br />
好了，20分钟这块硬盘没有读写之后自动休眠。</p>
]]></content:encoded>
			<wfw:commentRss>http://erning.net/archives/static-device-name-and-auto-spin-down-for-usb-harddisk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Linux Gateway</title>
		<link>http://erning.net/archives/my-linux-gateway</link>
		<comments>http://erning.net/archives/my-linux-gateway#comments</comments>
		<pubDate>Tue, 05 Jan 2010 08:56:23 +0000</pubDate>
		<dc:creator>erning</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[gfw]]></category>

		<guid isPermaLink="false">http://erning.net/?p=110</guid>
		<description><![CDATA[使用透明网关，将web流量通过squid走，cache之后可以提高家里机器访问web的速度。 通过squid配置，将被墙的站点设置成通过SSH隧道走。但squid本身不能forward给socks5代理，因此中间加了个privoxy中转。被墙的站点也可以在squid缓存，节省流量。 如果所有的web访问都通过SSH隧道，访问国内的站点慢了。不仅会反向被墙还浪费海外主机的流量。 没有海外主机的时候，SSH隧道可以用TOR替代。 https不可以做透明代理，这时候需要将浏览器的proxy设置到网关的squid。 图上没标出，网关上还安装有bind，提供域名解析服务，用来对付DNS解析被篡改的问题。 现在这个硬件用的是Asus EeeBox b202，安静省电。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/zendragon/4192451789/" title="My Linux Gateway by Zhang Erning, on Flickr"><img src="http://farm3.static.flickr.com/2737/4192451789_ec84d67d3f.jpg" width="352" height="500" alt="My Linux Gateway" /></a></p>
<p>使用透明网关，将web流量通过squid走，cache之后可以提高家里机器访问web的速度。</p>
<p>通过squid配置，将被墙的站点设置成通过SSH隧道走。但squid本身不能forward给socks5代理，因此中间加了个privoxy中转。被墙的站点也可以在squid缓存，节省流量。</p>
<p>如果所有的web访问都通过SSH隧道，访问国内的站点慢了。不仅会反向被墙还浪费海外主机的流量。</p>
<p>没有海外主机的时候，SSH隧道可以用TOR替代。</p>
<p>https不可以做透明代理，这时候需要将浏览器的proxy设置到网关的squid。</p>
<p>图上没标出，网关上还安装有bind，提供域名解析服务，用来对付DNS解析被篡改的问题。</p>
<p>现在这个硬件用的是<a href="http://www.asus.com.cn/product.aspx?P_ID=QUObl5lSRQQ3lSqJ">Asus EeeBox b202</a>，安静省电。</p>
]]></content:encoded>
			<wfw:commentRss>http://erning.net/archives/my-linux-gateway/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Gentoo Linux Dailup Internet by CDMA Phone</title>
		<link>http://erning.net/archives/gentoo-linux-dailup-internet-by-cdma-phone</link>
		<comments>http://erning.net/archives/gentoo-linux-dailup-internet-by-cdma-phone#comments</comments>
		<pubDate>Fri, 18 Nov 2005 11:49:41 +0000</pubDate>
		<dc:creator>erning</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[cdma]]></category>
		<category><![CDATA[gentoo]]></category>

		<guid isPermaLink="false">http://www.erning.net/archives/2005/11/18/gentoo-linux-dailup-internet-by-cdma-phone/</guid>
		<description><![CDATA[My CDMA phone connects to the laptop via a USB cable. So I have to configurate the kernel with USB Modem support. Device Drivers --> USB support --> [M] Support for Host-side USB [M] USB Modem (CDC ACM) support Check if the device is well reconized after install and modprobe the module(cdc_acm). # dmesg &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>My CDMA phone connects to the laptop via a USB cable.  So I have to configurate the kernel with USB Modem support.</p>
<pre class="brush: plain">
Device Drivers -->
    USB support -->
        [M] Support for Host-side USB
        [M] USB Modem (CDC ACM) support
</pre>
<p>Check if the device is well reconized after install and modprobe the module(cdc_acm).</p>
<pre class="brush: plain">
# dmesg | grep acm
usbcore: registered new driver cdc_acm
drivers/usb/class/cdc-acm.c: v0.23:USB Abstract Control Model driver for USB modems and ISDN adapters
</pre>
<p>Great, the device has been recognized. Then create the ttyACM0 node in <em>/dev</em> is it does exist.<br />
<code><br />
mknod /dev/ttyACM0 c 166 0<br />
</code></p>
<p>Edit the configuration file <em>/etc/conf.d/net.ppp0</em> (or .ppp1, .ppp2). Here&#8217;s mine</p>
<pre class="brush: plain">
# Config file for /etc/init.d/net.ppp0

PEER="cdma"                     # Define peer (aka ISP)
DEBUG="yes"                     # Turn on debugging
PERSIST="no"                    # Redial after being dropped
ONDEMAND="no"                   # Only bring the interface up on demand?
MODEMPORT="/dev/ttyACM0"        # TTY device modem is connected to
LINESPEED="230400"              # Speed pppd should try to connect at
INITSTRING=""                   # Extra init string for the modem
DEFROUTE="yes"                  # Must pppd set the default route?
HARDFLOWCTL="yes"               # Use hardware flow control?
ESCAPECHARS="yes"               # Use escape caracters ?
PPPOPTIONS=""                   # Extra options for pppd
USERNAME="card"                 # The PAP/CHAP username
PASSWORD="card"                 # Your password/secret.  Ugly I know, but i
                                # will work on something more secure later
                                # on.  700 permission on /etc/init.d/net.ppp0
                                # should be enouth for now.
NUMBER="#777"                   # The telephone number of your ISP
                                # leave blank for leased-line operation.
REMIP=""                        # The ip of the remote box if it should be set
NETMASK=""                      # Netmask
IPADDR=""                       # Our IP if we have a static one
MRU="768"                       # Sets the MRU
MTU="768"                       # Sets the MTU
RETRYTIMEOUT="60"               # Retry timeout for when ONDEMAND="yes" or
                                # PERSIST="yes"
IDLETIMEOUT="600"               # Idle timeout for when ONDEMAND="yes"
PEERDNS="yes"                   # Should pppd set the peer dns?

AUTOCFGFILES="no"               # By default this scripts will generate
                                # /etc/ppp/chat-isp, /etc/ppp/chap-secrets,
                                # /etc/ppp/pap-secrets and /etc/ppp/peers/isp
                                # automatically.  Set to "no" if you experience
                                # problems, or need specialized scripts.  You
                                # will have to create these files by hand then.

AUTOCHATSCRIPT="no"             # By default this script iwll generate
                                # /etc/ppp/chat-${PEER} automatically. Set to "no"
                                # if you experience problems, or need specialized
                                # scripts. You will have to create these files by
                                # hand then.

# Directory where the templates is stored
TEMPLATEDIR=/etc/ppp
</pre>
<p>Then have to manual edit two additional files <em>/etc/ppp/chat-cdma</em> and <em>/etc/ppp/peers/cdma</em>.</p>
<pre class="brush: plain">
# /etc/ppp/chat-cdma:
'ABORT' 'BUSY'
'ABORT' 'ERROR'
'ABORT' 'NO ANSWER'
'ABORT' 'NO CARRIER'
'ABORT' 'NO DIALTONE'
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
'' 'ATZ'
'OK' 'ATDT#777'
'CONNECT' ''
'TIMEOUT' '5'
'~--' ''
</pre>
<pre class="brush: plain">
# /etc/ppp/peers/cdma:
connect "/usr/sbin/chat -v -f /etc/ppp/chat-cdma"
defaultroute
usepeerdns
/dev/ttyACM0
230400
local
novj
</pre>
<p>Now everything is OK.  To dialup the Internet simply type<br />
<code><br />
/etc/init.d/net.ppp0 start<br />
</code></p>
<p>The CDMA ISP is <a href="http://www.chinaunicom.com.cn">China Unicom</a>.</p>
<p>If the above configurations does not fit for your situation <a href="http://www.google.com/search?hl=en&#038;lr=&#038;newwindow=1&#038;q=linux+usb+modem+cdma+dialup&#038;btnG=Search">try to search more information here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://erning.net/archives/gentoo-linux-dailup-internet-by-cdma-phone/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My gentoo config files for Dell Inspiron 8600</title>
		<link>http://erning.net/archives/my-gentoo-config-file-for-dell-inspiron-8600</link>
		<comments>http://erning.net/archives/my-gentoo-config-file-for-dell-inspiron-8600#comments</comments>
		<pubDate>Tue, 28 Jun 2005 14:01:08 +0000</pubDate>
		<dc:creator>erning</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[gentoo]]></category>

		<guid isPermaLink="false">http://www.erning.net/?p=54</guid>
		<description><![CDATA[/etc/make.conf # These settings were set by the catalyst build script that automatically built this stage # Please consult /etc/make.conf.example for a more detailed example CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -mcpu=i686 -fomit-frame-pointer -pipe" CXXFLAGS="${CFLAGS}" MAKEOPTS="-j2" #ACCEPT_KEYWORDS="~x86" USE="X gtk gtk2 gnome qt kde mozilla cjk unicode nptl nptlonly java dvd -xmms -gcj -fortran -userlocales -font-server" PORTDIR_OVERLAY="/usr/local/portage" #FETCHCOMMAND="/home/erning/bin/proz -k=5 --no-getch [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>/etc/make.conf</em></strong></p>
<pre class="brush: bash">
# These settings were set by the catalyst build script that automatically built this stage
# Please consult /etc/make.conf.example for a more detailed example

CHOST="i686-pc-linux-gnu"
CFLAGS="-O3 -mcpu=i686 -fomit-frame-pointer -pipe"
CXXFLAGS="${CFLAGS}"

MAKEOPTS="-j2"

#ACCEPT_KEYWORDS="~x86"
USE="X gtk gtk2 gnome qt kde mozilla cjk unicode nptl nptlonly java dvd -xmms -gcj -fortran -userlocales -font-server"

PORTDIR_OVERLAY="/usr/local/portage"

#FETCHCOMMAND="/home/erning/bin/proz -k=5 --no-getch \${URI} -P \${DISTDIR}"
#RESUMECOMMAND="/home/erning/bin/proz -k=5 --no-getch \${URI} -P \${DISTDIR}"

#SYNC="rsync://192.168.1.30/gentoo-portage"
GENTOO_MIRRORS="http://mirror.averse.net/pub/gentoo/ http://mymirror.asiaosc.org/gentoo/ ftp://ftp.linuxforum.net/gentoo"
</pre>
<p><strong><em>/etc/portage/package.keywords</em></strong></p>
<pre class="brush: bash">
#sys-kernel/gentoo-sources ~x86
media-video/ati-drivers ~x86

net-im/skype ~x86
sys-apps/dbus ~x86

app-emulation/vmware-workstation ~x86

media-fonts/acroread-asianfonts ~x86
app-text/acroread ~x86

dev-util/lincvs ~x86
dev-util/kdevelop ~x86

x11-libs/wxGTK ~x86

kde-base/konqueror ~x86
kde-base/libkonq ~x86
kde-base/kcontrol ~x86
kde-base/kcminit ~x86
kde-base/kdebase-data ~x86
kde-base/kdelibs ~x86
kde-base/konsole ~x86
kde-base/arts ~x86
kde-base/kdebase-kioslaves ~x86
kde-base/kdialog ~x86
kde-base/khelpcenter ~x86
kde-base/kdesu ~x86

app-dicts/stardict-oxford-en-zh-gb ~x86
app-dicts/stardict-cdict-en-zh-gb ~x86
app-dicts/stardict-cedict-zh-en-gb ~x86
app-dicts/stardict-xdict-en-zh-gb ~x86
app-dicts/stardict-xdict-zh-en-gb ~x86

dev-python/wxpython ~x86
</pre>
<p><strong><em>/etc/portage/package.use</em></strong></p>
<pre class="brush: bash">
media-fonts/acroread-asianfonts linguas_zh_CN linguas_zh_TW languas_ko languas_ja
media-video/mplayer X aalib alsa arts avi bidi cdparanoia dga directfb divx4linux dts dv dvb dvd dvdread edl encode esd fbcon ggi gif gtk i8x0 ipv6 joystick jpeg libcaca lirc live lzo mad matroska matrox mmx mmxext mpeg mythtv nas nls oggvorbis opengl oss png real rtc sdl sse sse2 svga tga theora truetype v4l v4l2 xanim xinerama xv xvid xvmc -xmms
media-libs/win32codecs quicktime real

dev-util/kdevelop php sql subversion

www-client/mozilla mozdevelop mozxmlterm
www-client/mozilla-firefox mozdevelop mozxmlterm
</pre>
]]></content:encoded>
			<wfw:commentRss>http://erning.net/archives/my-gentoo-config-file-for-dell-inspiron-8600/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
