Java 2 Ada - Tag ssd2011-02-20T17:29:17+00:00Stephane Carrezurn:md5:d12e23c53b2436d6becce3d51ddbdf38AWAInstalling an SSD device on Ubuntuurn:md5:03c69a41049dec04a3a05027848529892011-02-20T17:29:17+00:002011-02-20T17:29:17+00:00Stephane Carrezlvmperformancessd
<div class="post-text"><p>This article explains the steps for the installation of an SSD device on an existing Ubuntu desktop PC.</p><h2>Disk Performances</h2><p>First of all, let's have a look at the disk read performance with the <code>hdparm</code> utility. The desktop PC has three disks, <code>/dev/sda</code> being the new SSD device (an <a href="http://www.ocztechnology.com/ocz-vertex-2-sata-ii-3-5-ssd.html">OCZ Vertex 2 SATA II 3.5" SSD</a>).</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo -i hdparm -t /dev/sda /dev/sdb /dev/sdc</b>
</div>
<p>The three disks have the following performance:</p><pre><code>sda: OCZ-VERTEX2 3.5 229.47 MB/sec
sdb: WDC WD3000GLFS-01F8U0 122.29 MB/sec
sdc: ST3200822A 59.23 MB/sec
</code></pre><p>The SSD device appears to be 2 times faster than a 10000 rpm disk.</p><h2>Plan for the move</h2><p>The first step is to plan for the move and define what files should be located on the SSD device.</p><h4>Identify files used frequently</h4><p>To benefit of the high read performance, files used frequently could be moved to the SSD device. To identify them, you can use the <code>find</code> command and the <code>-amin</code> option. This option will not work if the file system is mounted with <code>noatime</code>. The <code>-amin</code> option indicates a number of minutes. To find the files that were accessed during the last 24 hours, you may use the following command:</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo find /home -amin -1440</b>
</div>
<p>In most cases, files accessed frequently are the system files (in <code>/bin</code>,<code> /etc</code>, <code>/lib</code>, ..., <code>/usr/bin</code>, <code>/usr/lib</code>, <code>/usr/share</code>, ...) and users' files located in <code>/home</code>.</p><h4>Identify Files that change frequently</h4><p>Some people argue that files modified frequently should not be located on an SSD device (write endurance and write performance).</p><p>On a Linux system, the system files that are changed on regular basis are in general grouped together in the <code>/var</code> directory. Some configuration files are modified by system daemons while they are running. The list of system directories that changes can be limited to:</p><pre><code>/etc (cups/printers.conf.0, mtab, lvm/cache, resolv.conf, ...)
/var (log/*, cache/*, tmp/*, lib/*...)
/boot (grub/grubenv modified after booting)
</code></pre><h4>Temporary Files</h4><p>On Linux temporary files are stored in one of the following directories. Several KDE applications are saving temporary files in the <code>.kde/tmp-</code><i><code>host</code></i> directory for each user. These temporary files could be moved to a ram file system.</p><pre><code>/tmp
/var/tmp
/home/$user/.kde/tmp-$host
</code></pre><h4>Move plan</h4><p>The final plan was to create one partition for the root file system and three LVM partitions for <code>/usr</code>, <code>/var</code> and <code>/home</code> directories.</p><h2>Partition the drive</h2><p>The drive must be partitioned with <code>fdisk</code>. I created one bootable partition and a second partition with what remains.</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo fdisk -l /dev/sda</b>
<br></br>
Disk /dev/sda: 120.0 GB, 120034123776 bytes<br></br>
255 heads, 63 sectors/track, 14593 cylinders<br></br>
Units = cylinders of 16065 * 512 = 8225280 bytes<br></br>
Sector size (logical/physical): 512 bytes / 512 bytes<br></br>
I/O size (minimum/optimal): 512 bytes / 512 bytes<br></br>
Disk identifier: 0x00070355<br></br>
<br></br>
Device Boot Start End Blocks Id System<br></br>
/dev/sda1 * 1 1295 10402056 83 Linux<br></br>
/dev/sda2 1296 14593 106816185 83 Linux
</div>
<p>To ease future management of partitions, it is useful to use <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29">LVM</a> and create a volume group.</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo vgcreate vg01 /dev/sda2</b><br></br>
Volume group "vg01" successfully created
</div>
<p>The partitions are then created by using <code>lvcreate</code>. More space can be allocated on them by using the <code>lvextend</code> utility.</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo lvcreate -L 10G -n sys vg01</b><br></br>
Logical volume "sys" created <br></br>
$ <b>sudo lvcreate -L 10G -n var vg01</b><br></br>
Logical volume "var" created <br></br>
$ <b>sudo lvcreate -L 4G -n swap vg01</b><br></br>
Logical volume "swap" created <br></br>
$ <b>sudo lvcreate -L 60G -n home vg01</b><br></br>
Logical volume "home" created
</div>
<p>The LVM partitions are available through the <a href="http://en.wikipedia.org/wiki/Device_mapper">device mapper</a> and they can be accessed by their name:</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>ls -l /dev/vg01/</b><br></br>
total 0<br></br>
lrwxrwxrwx 1 root root 19 2011-02-20 14:03 home -> ../mapper/vg01-home<br></br>
lrwxrwxrwx 1 root root 19 2011-02-20 14:03 swap -> ../mapper/vg01-swap<br></br>
lrwxrwxrwx 1 root root 18 2011-02-20 14:03 sys -> ../mapper/vg01-sys<br></br>
lrwxrwxrwx 1 root root 18 2011-02-20 14:03 var -> ../mapper/vg01-var
</div>
<h2>Format the partition</h2><p>Format the file system with <a href="http://en.wikipedia.org/wiki/Ext4">ext4</a> as it integrates various improvements which are useful for the SSD storage (Extents, Delayed allocation). Other file systems will work very well too.</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo mkfs -t ext4 /dev/vg01/sys</b>
</div>
<h2>Move the files</h2><p>To move files from one system to another place, it is safer to use the <code>tar</code> command instead of a simple <code>cp</code>. Indeed, the <code>tar</code> command is able to copy special files without problems while not all <code>cp</code> commands support the copy of special files.</p><div style='float: none; background-color: #E8F0FF; border: 1px solid #aaa; width: 90%; margin-bottom: 10px;'>
$ <b>sudo mount /dev/vg01/sys /target</b><br></br>
$ <b>sudo -i</b><br></br>
# <b>cd /usr</b><br></br>
# <b>tar --one-file-system -cf - . | (cd /target; tar xf -)</b>
</div>
<p>If the file system to move is located on another LVM partition, it is easier and safer to use the <code>pvmove</code> utility to move physical extents from one physical volume to another one.</p><h2>Change the mount point</h2><p>Edit the <code>/etc/fstab</code> file and change the old mount point to the new one. The <code>noatime</code> mount option tells the kernel to avoid updating the file access time when it is read.</p><pre><code>/dev/vg01/sys /usr ext4 noatime 0 2
/dev/vg02/home /home ext4 noatime 0 2
/dev/vg01/var /var ext4 noatime 0 2
</code></pre><h2>Tune the IO Scheduler</h2><p>For the SSD drive, it is best to disable the Linux IO scheduler. For this, we will activate the <code>noop</code> IO scheduler. Other disks will use the default IO scheduler or another one. Add the following lines in <code>/etc/rc.local</code> file:</p><pre><code>test -f /sys/block/sda/queue/scheduler &&
echo noop > /sys/block/sda/queue/scheduler
</code></pre><h2>References</h2><p><a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29">LVM</a></p><p><a href="http://en.wikipedia.org/wiki/Ext4">ext4</a></p><p><a href="http://www.ocztechnologyforum.com/forum/showthread.php?54379-Linux-Tips-tweaks-and-alignment">http://www.ocztechnologyforum.com/forum/showthread.php?54379-Linux-Tips-tweaks-and-alignment</a></p><p><a href="http://www.storagesearch.com/ssdmyths-endurance.html">http://www.storagesearch.com/ssdmyths-endurance.html</a></p></div>