Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Wednesday, March 9, 2011

Optimising Linux for minimal writes - useful for an SSD

Tip 1: Use ext2 instead of ext3/ext4.
ext3 and ext4 are journaled filesystems and so maintain a log of all filesystem changes (which can be used for recovery if need be).  If you're using a laptop chances are sudden power failure isn't really a threat so you'll lose less by not having a journaled filesystem - if you're using a desktop your choice to use a non-journaled filesystem should be an informed one.

Tip 2: Don't update file access times.
Modify your /etc/fstab adding noatime to the options for mounted drives.  This will stop writing to the file system every time a file is accessed.  (This is also used to improve disk I/O performance for critical applications - git does this for example, though they may have switched to relatime).

Tip 3: Mount "non-essential" write-heavy directories as tmpfs.
Update /etc/fstab to mount /tmp, /var/tmp and /var/log as tmps:
#              
tmpfs           /tmp            tmpfs   defaults        0       0
tmpfs           /var/tmp        tmpfs   defaults        0       0
tmpfs           /var/log        tmpfs   defaults        0       0
Unfortunately when /var/log is now mounted it won't have any of the necessary directories so we'll need to create them each time on boot.  Update /etc/rc.local with the following snippet just before the "exit 0" line.
for dir in apparmor apt ConsoleKit cups dist-upgrade fsck gdm installer libvirt news samba speech-dispatcher unattended-upgrades; do
if [ ! -e /var/log/$dir ] ; then
mkdir /var/log/$dir
fi
done
You can get the list of directories you need by running cd /var/log; ls -d */

These tips can be found repeated on the web but I gathered most of my info from here.  That page also lists some further optimisations for the kernel to take full advantage of an SSD's speed.

Tuesday, March 8, 2011

Mounting an encrypted logical volume

I found this useful when trying to do some recovery work on my computer which uses dm-crypt for full disk encryption.  The following was done using the Ubuntu Maverick (10.10) livecd.

Mount the encrypted partition
root@ubuntu:/home/ubuntu# sudo cryptsetup luksOpen /dev/sda4 data
Enter passphrase for /dev/sda4:
root@ubuntu:/home/ubuntu# ls /dev/mapper
control  data

Mount the logical volume
root@ubuntu:/home/ubuntu# aptitude install lvm2
root@ubuntu:/home/ubuntu# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg0" using metadata type lvm2
root@ubuntu:/home/ubuntu# vgchange -ay vg0
  2 logical volume(s) in volume group "vg0" now active
root@ubuntu:/home/ubuntu# mkdir /mnt/tmp
root@ubuntu:/home/ubuntu# sudo mount /dev/vg0/root /mnt/tmp

Monday, February 14, 2011

Linux: Add existing user to existing group

I seem to need to look this up at least once a month....


usermod -a -G ftp tony # add tony to the ftp group

Thursday, February 10, 2011

Install dependencies with dpkg (kinda)

dpkg -i /tmp/package.deb # Try to install package, fail, but generate list of unresolved dependencies
apt-get -f --force-yes --yes install # Resolve generated dependencies
dpkg -i /tmp/package.deb # Install package (with dependencies now met)

Monday, January 24, 2011

Update Ubuntu Release from the command line

sudo apt-get install update-manager-core # may/may not be necessary
sudo do-release-upgrade


If there's no new release found and you think there should be, check /etc/update-manager/release-upgrades and change Prompt=lts to Prompt=normal if necessary

Saturday, October 2, 2010

Mounting an encrypted LUKS LVM volume from a live CD

Get Luks and dm-crypt running on the live disk:
sudo apt-get install lvm2 cryptsetup
sudo modprobe dm-crypt
sudo cryptsetup luksOpen /dev/sda4 crypt1

If you LVM setup then you need to continue with:
sudo vgscan --mknodes
sudo vgchange -ay
Take note of the volume group name. 'vg0' in my case.

Mount the disk:
sudo mkdir /mnt/disk
sudo mount /dev/vg0/root /mnt/disk

Friday, July 30, 2010

Move Lucid min, max, close buttons to the right

gconftool-2 --set /apps/metacity/general/button_layout --type string menu:minimize,maximize,close

Friday, February 26, 2010

Clock Screensaver for Ubuntu

You can use the GLText screensaver to display the time whenever you lock your screen:

In the file /usr/share/applications/screensavers/gltext.desktop change

Exec=gltext -root
to
Exec=gltext -root -front -text '%l:%M:%S %p'

Saturday, May 2, 2009

Changing keymapping in Ubuntu

I recently needed to remap the 2nd enter key on my macbook so that I would actually have an insert key (what were apple thinking?). Here's how I did it:
  • xev | grep keycode (run this and press they key you want to map, this will help you determine its keycode)
  • in a file put "keycode xxx = MyKey" in my case I had "keycode 104 = Insert"
  • xmodmap keymapfile (the key should work straight away after this)
  • to make the change permanent create ~/.xmodmap with all the key mappings you want and then go to System ▸ Preferences ▸ Sessions, click the Add button, fill in the Name and Description fields and put the following into the Command field:
xmodmap ~/.xmodmap

Friday, May 1, 2009

Creating a Truecrypt NTFS volume in both Ubuntu and OSX

I wanted to encrypt my external disk and I wanted it to work under Linux, Windows and OSX (read and write for all). To my mind the two obvious options were dmcrypt and truecrypt. Dmcrypt works nicely for my laptop but as far as I could find it only had one windows client (FreeOTFE) and no OSX client which pretty much left me with Truecrypt. I also needed a filesystem that worked well on all three OSs so NTFS was the best option largely due to ntfs-3g.

I ended up creating the encrypted volume under both Linux and OSX during some troubleshooting so here's how I did it in both OSs. Note: you only need to create the encrypted once in either Linux or OSX

The steps for Linux (Ubuntu 8.10):
  • Install Truecrypt (grab the .deb and install that)
  • truecrypt -t -c /dev/sdc (create the encrypted volume - choose "None" for the file system)
  • truecrypt -t --filesystem=none /dev/sdc (mount the volume)
  • mkfs.ntfs -f -L Cams_1Tb /dev/mapper/truecrypt1 (format the volume as ntfs)
Then you should be able to mount the volume either via the gui or the command line and have it automatically mount without problem

The steps for OS X (Leopard):

  • Install Truecrypt
  • Install ntfs-3g for mac
  • I also installed MacFuse 2.0 at one stage following on from some forums posts but this may not be necessary (Truecrypt 6.1a installs MacFuse 1.6 or 1.7)
  • /Applications/TrueCrypt.app/Contents/MacOS/TrueCrypt -t --filesystem=fat -c /dev/rdisk2 (fat seemed to work better than no file system at all)
  • Mount the Volume in Truecrypt and look at the "Volume Properties" on the newly attached volume. Take note of the "Virtual Device" in my case this was /dev/disk5
  • sudo diskutil eraseVolume NTFS-3G Cams_1Tb /dev/disk5 (convert the FAT volume to NTFS)
From here on end mounting and dismounting the device in Truecrypt should work a charm.