<?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>chys&#039;s random notes &#187; fs</title>
	<atom:link href="http://en.chys.info/tag/fs/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.chys.info</link>
	<description>Study more problems; Talk less of isms.</description>
	<lastBuildDate>Tue, 27 Dec 2011 11:56:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>install vs. cp; and mmap</title>
		<link>http://en.chys.info/2009/05/install-vs-cp-and-mmap/</link>
		<comments>http://en.chys.info/2009/05/install-vs-cp-and-mmap/#comments</comments>
		<pubDate>Fri, 08 May 2009 21:19:19 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fs]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=500</guid>
		<description><![CDATA[If we hand write a Makefile, we should always stick to install instead of using cp for the installation commands. Not only is it more convenient, but it does things right (cp does things wrong). For example, if we attempt to update /bin/bash, which is currently running, with “cp ... /bin/bash”, we get a &#8220;text [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If we hand write a <code>Makefile</code>, we should always stick to <a href="http://linux.die.net/man/1/install">install</a> instead of using <a href="http://linux.die.net/man/1/cp">cp</a> for the installation commands. Not only is it more convenient, but it does things right (cp does things <em>wrong</em>).</p>
<p>For example, if we attempt to update <code>/bin/bash</code>, which is currently running, with “<code>cp ... /bin/bash</code>”, we get a &#8220;text busy&#8221; error. If we attempt to update <code>/lib/libc.so.6</code> with “<code>cp ... /lib/libc.so.6</code>”, then we either get &#8220;text busy&#8221; (in ancient versions of Linux) or breaks each and every running program within a fraction of a second (in recent versions of Linux). <code>install</code> does the thing right in both situations.</p>
<p>The reason why <code>cp</code> fails is that it simply attempts to open the destination file in write-only mode and write the new contents. This causes problem because Linux (and all contemporary <a href="http://en.wikipedia.org/wiki/Unix-like">Unices</a> as well as Microsoft Windows) uses <a href="http://en.wikipedia.org/wiki/Memory-mapped_file">memory mapping</a> (mmap) to load executables and dynamic libraries.</p>
<p>The contents of an executable or dynamic library are mmap&#8217;d into the linear address space of relevant processes. Therefore, any change in the underlying file affects the mmap&#8217;d memory regions and can potentially break programs. (<code>MAP_PRIVATE</code> guarantees changes by processes to those memory regions are handled by <a href="http://en.wikipedia.org/wiki/Copy-on-write">COW</a> without affecting the underlying file. On the contrary, <a href="http://en.wikipedia.org/wiki/POSIX">POSIX</a> leaves to implementations whether COW should be used if the underlying file is modified. In fact, for purpose of efficiency, in Linux, such modifications are <em>visible</em> to processes even though <code>MAP_PRIVATE</code> may have be used.)</p>
<p>There is an option <code>MAP_DENWRITE</code> which disallows any modification to the underlying file, designed to avoid situations described above. Executables and dynamic libraries are all mmap&#8217;d with this option. Unfortunately, it turned out <code>MAP_DENYWRITE</code> became a source of <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">DoS attacks</a>, forcing Linux to ignore this option in recent versions.</p>
<p>Executables are mmap&#8217;d by the kernel (in the <code>execve</code> <a href="http://en.wikipedia.org/wiki/System_call">syscall</a>). For kernel codes, <code>MAP_DENYWRITE</code> still works, and therefore we get &#8220;text busy&#8221; errors if we attempt to modify the executable.</p>
<p>On the other hand, dynamic libraries are mmap&#8217;d by userspace codes (for example, by loaders like <code>/lib/ld-linux.so</code>). These codes still pass <code>MAP_DENYWRITE</code> to the kernel, but newer kernels silently ignores this option. The bad consequence is that you can break the whole system if you think you&#8217;re only upgrading the <a href="http://en.wikipedia.org/wiki/C_standard_library">C runtime library</a>.</p>
<p>Then, how does <code>install</code> solve this problem? Very simple &#8211; <a href="http://en.wikipedia.org/wiki/Unlink_(Unix)">unlinking</a> the file before writing the new one. Then the old file (no longer present in directory entries but still in disk until the last program referring to it exits) and the new file have different <a href="http://en.wikipedia.org/wiki/Inode">inodes</a>. Programs started before the upgrading (continuing using the old file) and those after the upgrading (using the new version) will both be happy.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/05/install-vs-cp-and-mmap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ext4 data loss</title>
		<link>http://en.chys.info/2009/03/ext4-data-loss/</link>
		<comments>http://en.chys.info/2009/03/ext4-data-loss/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 04:49:09 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ext4]]></category>
		<category><![CDATA[fs]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.chys.info/?p=384</guid>
		<description><![CDATA[I, too, have experienced data losses in ext4 partitions. There was some problem with my X that hangs the system about once a week (I was upgrading my X system and drivers too aggressively) so sometimes I had to hard reboot my computer (even magic SysRq does not respond in such cases). I lost most [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2008/12/migrating-to-ext4/' rel='bookmark' title='Migrating to EXT4'>Migrating to EXT4</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I, too, have experienced data losses in ext4 partitions.</p>
<p>There was some problem with my X that hangs the system about once a week (I was upgrading my X system and drivers too aggressively) so sometimes I had to hard reboot my computer (even <a href="http://en.wikipedia.org/wiki/Magic_SysRq_key">magic SysRq</a> does not respond in such cases). I lost most or all of my KDE settings after the reboots, and for one time also all my Thunderbird settings. This never happened until I <a href="http://blog.chys.info/2008/12/migrating-to-ext4/">migrated to ext4</a>..</p>
<p>So I converted all my ext4&#8242;s back to ext3 and downgraded the kernel to 2.6.27 which is considered by Gentoo as stable. Loss of KDE settings is no big deal, but I really don&#8217;t want to have a kernel bug erase my codes, or homework that is due tomorrow, or diary I&#8217;ve kept for eight years.</p>
<p>Anyway, the performance of ext4 is really good..</p>
<p>References &#8211; Other recent reports of ext4 data losses:<br />
[1] <a href="https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/45">https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/45</a><br />
[2] <a href="http://www.h-online.com/open/Ext4-data-loss-explanations-and-workarounds--/news/112892">http://www.h-online.com/open/Ext4-data-loss-explanations-and-workarounds&#8211;/news/112892</a><br />
[3] <a href="http://www.h-online.com/open/Possible-data-loss-in-Ext4--/news/112821">http://www.h-online.com/open/Possible-data-loss-in-Ext4&#8211;/news/112821</a><br />
[4] <a href="http://cookinglinux.cn/ext4-lose-data.html">http://cookinglinux.cn/ext4-lose-data.html</a> (Chinese)</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2008/12/migrating-to-ext4/' rel='bookmark' title='Migrating to EXT4'>Migrating to EXT4</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/03/ext4-data-loss/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Migrating to EXT4</title>
		<link>http://en.chys.info/2008/12/migrating-to-ext4/</link>
		<comments>http://en.chys.info/2008/12/migrating-to-ext4/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 01:23:00 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ext4]]></category>
		<category><![CDATA[fs]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.chys.info/2008/12/migrating-to-ext4/</guid>
		<description><![CDATA[Ext4, the successor to ext3 which was formerly known as ext4dev, is marked stable in Linux kernel 2.6.28, meaning the Linux kernel team now recommends using ext4 in production. To convert a file system from ext3 to ext4, use tune2fs -O extents /dev/DEV and remount the file system as ext4. (Two e2fsck runs are recommended [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/ext4-data-loss/' rel='bookmark' title='Ext4 data loss'>Ext4 data loss</a></li>
<li><a href='http://en.chys.info/2010/02/extract-deb-files/' rel='bookmark' title='Extract Deb files from command line'>Extract Deb files from command line</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Ext4">Ext4</a>, the successor to ext3 which was formerly known as ext4dev, is marked stable in Linux kernel 2.6.28, meaning the Linux kernel team now recommends using ext4 in production.</p>
<p>To convert a file system from ext3 to ext4, use<br />
<blockquote>tune2fs -O extents /dev/DEV</p></blockquote>
<p>and remount the file system as ext4. (Two <code>e2fsck</code> runs are recommended before and after <code>tune2fs</code>.) Some documentations also include the <code>-E test_fs</code> option. This is not necessary now since ext4 is no longer experimental.</p>
<p>Finally do not forget to modify <code>/etc/fstab</code>.</p>
<p>An ext4 file system created this way is not a “true” ext4 &#8211; the extents feature, the main advantage of ext4 comapred to ext3, is not automatically applied to old files. New files created afterwards are in the extents format.</p>
<p>Unlike the 100% backward compatibility of ext3 with ext2, an ext4 file system can no longer be mounted as if it were an ext3, unless the extents feature is disabled. (If you want to disable extents, why not simply use ext3?)
<div class="blogger-post-footer">
<hr />
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://creativecommons.org/images/public/somerights20.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</div>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/ext4-data-loss/' rel='bookmark' title='Ext4 data loss'>Ext4 data loss</a></li>
<li><a href='http://en.chys.info/2010/02/extract-deb-files/' rel='bookmark' title='Extract Deb files from command line'>Extract Deb files from command line</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2008/12/migrating-to-ext4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shrink an LVM partition</title>
		<link>http://en.chys.info/2008/10/shrink-an-lvm-partition/</link>
		<comments>http://en.chys.info/2008/10/shrink-an-lvm-partition/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 21:37:00 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fs]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[LVM]]></category>

		<guid isPermaLink="false">http://blog.chys.info/2008/10/shrink-an-lvm-partition/</guid>
		<description><![CDATA[Gentoo’s Documentation says it is easier to increase the size of an LVM partition than to shrink it, so they recommend starting with smaller partitions and then increase them as needed. Of course they are not saying shrinking is impossible, but only less easy. The most important thing is the FS must be reduced BEFORE [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gentoo.org/doc/en/lvm2.xml">Gentoo’s Documentation</a> says it is easier to increase the size of an <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29">LVM</a> partition than to shrink it, so they recommend starting with smaller partitions and then increase them as needed.</p>
<p>Of course they are not saying shrinking is impossible, but only less easy. The most important thing is the FS must be reduced BEFORE the volume, or the FS will get damaged.</p>
<p>Example: Shrink partiton <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">/dev/vg/home</span> with ext3 filesystem from 30G to 12G:<br />
<span style="font-family: &quot;Courier New&quot;,Courier,monospace;">e2fsck /dev/vg/home</span> (resize2fs requires a check before resizing)<span style="font-family: &quot;Courier New&quot;,Courier,monospace;"><br />
resize2fs /dev/vg/home 10G</span> (resize FS to 10G)<span style="font-family: &quot;Courier New&quot;,Courier,monospace;"><br />
lvreduce -L12G /dev/vg/home</span> (reduce partition)<br />
<span style="font-family: &quot;Courier New&quot;,Courier,monospace;">resize2fs /dev/vg/home</span> (extend FS to the whole partition)</p>
<p>Someone (I’m not sure who..) recommended doing two resizes like this claiming it is safer.
<div class="blogger-post-footer">
<hr />
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://creativecommons.org/images/public/somerights20.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</div>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2008/10/shrink-an-lvm-partition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

