<?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>Whatever happened to Benjamin Ragheb? &#187; shell</title>
	<atom:link href="http://www.benzado.com/blog/tags/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.benzado.com/blog</link>
	<description>A professional&#039;s personal blog.</description>
	<lastBuildDate>Mon, 11 Apr 2011 18:06:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Creating a RAM disk on Mac OS X</title>
		<link>http://www.benzado.com/blog/post/7/creating-a-ram-disk-on-mac-os-x</link>
		<comments>http://www.benzado.com/blog/post/7/creating-a-ram-disk-on-mac-os-x#comments</comments>
		<pubDate>Fri, 12 Sep 2008 19:44:29 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Nerdery]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.benzado.com/blog/?p=7</guid>
		<description><![CDATA[Here is a pair of shell functions to create and destroy a RAM disk on Mac OS X. # Creates a RAM disk device, formats it as HFS+, then mounts it. # parameters: size in megabytes create_ram_disk&#40;&#41; &#123; local RAMDISK_SIZE_MB=$1 local RAMDISK_SECTORS=$&#40;&#40;2048 * $RAMDISK_SIZE_MB&#41;&#41; RAMDISK_DEVICE=`hdiutil attach -nomount ram://$RAMDISK_SECTORS` RAMDISK_PATH=`mktemp -d /tmp/ramdisk.XXXXXX` newfs_hfs $RAMDISK_DEVICE # format as [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a pair of shell functions to create and destroy a <a href="http://en.wikipedia.org/wiki/RAM_disk">RAM disk</a> on Mac OS X.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Creates a RAM disk device, formats it as HFS+, then mounts it.</span>
<span style="color: #666666; font-style: italic;"># parameters: size in megabytes</span>
create_ram_disk<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">RAMDISK_SIZE_MB</span>=<span style="color: #007800;">$1</span>
	<span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">RAMDISK_SECTORS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2048</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #007800;">$RAMDISK_SIZE_MB</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #007800;">RAMDISK_DEVICE</span>=<span style="color: #000000; font-weight: bold;">`</span>hdiutil attach <span style="color: #660033;">-nomount</span> ram:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$RAMDISK_SECTORS</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">RAMDISK_PATH</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">mktemp</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>ramdisk.XXXXXX<span style="color: #000000; font-weight: bold;">`</span>
	newfs_hfs <span style="color: #007800;">$RAMDISK_DEVICE</span> <span style="color: #666666; font-style: italic;"># format as HFS+</span>
	<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> hfs <span style="color: #007800;">$RAMDISK_DEVICE</span> <span style="color: #007800;">$RAMDISK_PATH</span>
	<span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-h</span> <span style="color: #007800;">$RAMDISK_PATH</span> <span style="color: #666666; font-style: italic;"># report on disk usage</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Destroys the RAM disk created by create_ram_disk</span>
<span style="color: #666666; font-style: italic;"># parameters: none</span>
destroy_ram_disk<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Destroying <span style="color: #007800;">$RAMDISK_DEVICE</span>&quot;</span>
	<span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-h</span> <span style="color: #007800;">$RAMDISK_PATH</span> <span style="color: #666666; font-style: italic;"># report on disk usage</span>
	<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$RAMDISK_DEVICE</span>
	hdiutil detach <span style="color: #007800;">$RAMDISK_DEVICE</span>
	<span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #007800;">$RAMDISK_PATH</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>What are they good for?  I use these in any script that needs to write a lot of files that will be thrown away before the script is over.  For example, I keep the contents of my websites in a subversion repository.  When I want to update the site, I run a script which executes:</p>
<ol>
<li><strong>create_ram_disk 100</strong> to create a 100MB RAM disk</li>
<li><strong>svn export</strong> to write the web files to <strong>$RAMDISK_PATH</strong></li>
<li><strong>rsync</strong> to copy changed files from the RAM disk to the web host</li>
<li><strong>destroy_ram_disk</strong> to clean up</li>
</ol>
<p>I also do this in release build scripts, telling the xcodebuild command to use a temporary RAM disk for intermediate and product files.  Sure, Mac OS X has an excellent disk cache, but why hassle it when you know that all of those files will be deleted soon anyway?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benzado.com/blog/post/7/creating-a-ram-disk-on-mac-os-x/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.benzado.com @ 2012-02-04 20:05:32 by W3 Total Cache -->
