Monday, 19 September 2011

SSD In Linux

In an effort to make my Dual Core 1.6 Centrino laptop perform abit better I thought I would splash out on a SSD. I picked this up for £75 http://www.ocztechnology.com/ocz-vertex-2-sata-ii-2-5-ssd.html By the way my laptop is only SATA 1.

A quick google of SSD Linux shows alot of different ideas and I thought I would record the ones I used.

BTW a quick benchmark of my previous SATA 1 Toshiba 60GB 5400 2.5 drive with hdparm -t showed about 30MB/S.

Here's the steps I used.

1. Disk alignment
I used this guide http://www.ocztechnologyforum.com/forum/showthread.php?77769-A-Simple-How-To-on-Partitioning-and-Alignment-on-GNU-Linux-using-fdisk which basically says, make sure each partition starts on a sector that is divisible by 512.

I quickly knocked up a OpenSUSE live usb stick (dd_rescue openSUSE-11.4-KDE-LiveCD-x86_64.iso /dev/sdX)

I then fired up fdisk with sudo fdisk -H 32 -S 32 /dev/sda and created a 3 partition layout. fdisk offered to start the partition on a sector divisible by 512 so very little work was needed here.

NB On a fresh install of OpenSUSE 11.4 and no optimisations hdparm -t was giving 117.45 MB/sec - already almost 4 times quicker!

2. Change Disk Scheduler
Given that disks have been on various patters before SSD's, operating systems have therefore been optimised for them by default. http://www.gnutoolbox.com/linux-io-elevator/ This describe them all. You can see which one your are currently using by doing

cat /sys/block/sda/queue/scheduler

based on http://tombuntu.com/index.php/2008/09/04/four-tweaks-for-using-linux-with-solid-state-drives/ I am going to use deadline scheduler and set the /sys/block/sda/queue/iosched/fifo_batch to 1

So in /etc/rc.d/boot.local I added:-

echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch

This is easily enabled in any >= 2.6.33 kenel via fstab. Here's my entry for /
/dev/disk/by-id/ata-OCZ-VERTEX2_OCZ-F1B8655OI4BKW33W-part2 / ext4 noatime,acl,user_xattr,discard 1 1
Add the noatime option to fstab (see above example)

Disable IPv6 in opensuse

/etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1

Wednesday, 10 August 2011

Writing files as root in vim

I do this at least once a day; open a file in vim, make changes, then get reminded that I didn't do it using sudo.

simple one-liner fixes this.

:w !sudo tee %

Thanks to http://www.cyberciti.biz/faq/vim-vi-text-editor-save-file-without-root-permission/ for that one.

Monday, 13 December 2010

using a remote machine as a proxy with SSH

This is such a useful feature of SSH that I wish I had know about before now.

When working remotely from an insecure location, or when only the remote location is trusted by another host, e.g for a firewall login or viewing intranet pages you only have access to from a certain machine; you can use a remote machine as a SOCKS proxy straight out of the box.

e.g. on the localmachine, run:

ssh -fND 1234 username@yourremotemachine

This will create a SOCKS proxy on localhost port 1234
-f flag tells the shell to fork and run in the background
-N Leaves no login shell
-D 1234 sets up a SOCKS proxy via port 1234 on the localhost

On the local machine you can then set the browser to use the SOCKS 5 proxy on localhost port 1234

Tuesday, 2 November 2010

diff files across servers

Here's another really handy one liner for diff-ing files across servers using process substitution. This seems to work in zsh and bash.

diff /a/file/ <(ssh anotherserver 'cat /a/file/')

Tuesday, 19 October 2010

Finding the most recently modified files with find

I recently needed to check that no files had been modified since I last made an archive of a certain directory. Here's a good one for geting a list of files by last modified date, newest at the top.

find . -type f -printf "%TY-%Tm-%Td %TT %pn\n" | sort -r | less

Tuesday, 24 August 2010

ctrl-a and ctrl-b not working in tmux on RHEL 5.5

Rather than moving to the beginning of a line and the end of a line, ctrl-a and ctrl-b were just print ^A and ^B to the screen. Not sure why, I don't really have time to investigate, but this seems to fix the issue when run within the tmux session.

set -o emacs