<?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>I apologize that this blog is using the default Wordpress template.</description>
	<lastBuildDate>Thu, 06 May 2010 16:33:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.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() { local RAMDISK_SIZE_MB=$1 local RAMDISK_SECTORS=$((2048 * $RAMDISK_SIZE_MB)) 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>
<pre># Creates a RAM disk device, formats it as HFS+, then mounts it.
# parameters: size in megabytes
create_ram_disk() {
	local RAMDISK_SIZE_MB=$1
	local RAMDISK_SECTORS=$((2048 * $RAMDISK_SIZE_MB))
	RAMDISK_DEVICE=`hdiutil attach -nomount ram://$RAMDISK_SECTORS`
	RAMDISK_PATH=`mktemp -d /tmp/ramdisk.XXXXXX`
	newfs_hfs $RAMDISK_DEVICE # format as HFS+
	mount -t hfs $RAMDISK_DEVICE $RAMDISK_PATH
	df -h $RAMDISK_PATH # report on disk usage
}

# Destroys the RAM disk created by create_ram_disk
# parameters: none
destroy_ram_disk() {
	echo "Destroying $RAMDISK_DEVICE"
	df -h $RAMDISK_PATH # report on disk usage
	umount -f $RAMDISK_DEVICE
	hdiutil detach $RAMDISK_DEVICE
	rmdir $RAMDISK_PATH
}</pre>
<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>
