Saturday 17 December 2011

Resize images on the command line

I've recently been buying allot of digital downloads and it seems a waste that the album art encoded into the track is often 1500x1500 and taking up valuable disk space.

A quick blast with Graphics Magick solves all

gm mogrify -scale 25% Artwork.jpg

Saturday 10 December 2011

Rsync happiness

I recently got around to setting up a backup of my data. I decided rather than using something like Drop Box (which i'm sure is great) I'd keep things simple and set up a new EBS volume on my EC2 box and rsync my data there.

Here was the initial command I used to get the first sync in place manually.

rsync -arvzh --progress -e 'ssh -i path to pub key' /dir/to/backup user@host:/backup/dir/here

A quick review of the flags

-a archive mode (preserve timestamps)
-r recurse into directories
-v verbose
-z compress data during transfer
-h output in human readable format
--progress show a nice progress meter (won't want this in script)

-e specify remote shell and put any further args in quotes

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.