Sunday, September 18, 2011

Verify TRIM support on Linux

Wasted my time today puzzling why the trim support of my ssd does not work, or I thought it wasn't but was working alright. When you google "linux trim verify" the link below and most people link to the site below. Apparently the tests is not fully correct. Most of the time it works for others, but not me. Maybe it has to do that I formatted my ext4 w/ -E stripe-width=128
Anyway this is a better test I found, but I can't seem to see the link anymore. Using my bash history for reference.

dd if=/dev/urandom of=tmpfile bs=1M count=10 && sync
hdparm --fibmap tmpfile
hdparm --read-sector [address between begin_LBA and end_LBA of previous command] # expecting random numbers here
rm tmpfile && sync && sleep 120
hdparm --read-sector [address between begin_LBA and end_LBA of previous command] # expecting zeroes
The real key is the sector address is somewhere in between and NOT the start sector, as its possible the trim command will not set things to zeroes if files overlap. As it had happened to me 9 out of 10 tries using the test below I get random numbers still. The test above I get zeroes consistently.

Manual setup of UEFI, GPT and GRUB2

I recently got a Crucial m4.  I then have to transfer my existing HDD on it.  Its easier to do a clean install of Oneiric and it would pretty much do UEFI + GPT + GRUB2 for you.  However if you want to manually transfer everything I did the following steps:


  • Boot on Oneiric live CD or another boot this that will boot in UEFI mode. Its important that boot is on UEFI mode and not BIOS mode
  • Go to a shell and install gdisk as we want to partition the SSD w/ GPT and not MBR. fdisk only supports MBR
    apt-get install gdisk
    
  • Partition a EFI system partition.  This would hold grub2 files later and other boot loaders if needed.  I partitioned mine on sda1 as type EF00 (EFI System) w/ the size of 200mb.  Yes a bit bigger than what is needed however most people recommend 200mb as some boot loaders needs a bigger space.
  • Format the partitions.  The EFI System partition is formatted as vfat, as per EFI spec.
    mkfs.vat /dev/sda1
    mkswap /dev/sda2
    mkfs.ext4 -E stripe-width=128 /dev/sda3
    mkfs.ext4 -E stripe-width=128 /dev/sda4
    
    I put in a stripe width of 128 k as there are some recommendation this is optimal for SSD. However test suggest that your mileage may vary.
  • Mount and create the dirs on EFI system partition
    mkdir /boot/efi
    mount /dev/sda1 /boot/efi
    mkdir -p /boot/efi/efi
  • Install grub efi
    apt-get install grub-efi-amd64
    
  • Setup grub on the EFI system partition
    modprobe dm-mod
    grub-install --boot-directory=/boot/efi/efi --bootloader-id=GRUB2 --no-floppy --recheck
    cp /usr/share/grub/unicode.pf2 /boot/efi/efi/grub/
    cp /boot/grub/grub.cfg /boot/efi/efi/grub/grub.cfg
    
    I copied my old grub.cfg and update the UUID to point to the new SSD
  • Setup the EFI boot entry
    modprobe efivars
    efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"
    
    GRUB2 is the entry that would appear on the EFI bootloader.
The following resource helped me a lot
https://help.ubuntu.com/community/UEFIBooting#Install_GRUB2_in_.28U.29EFI_systems

I am still working out on the graphics output,  This would only give you a text based grub.

Saturday, January 8, 2011

HP 6910p 3G on linux

I got the 3G hs2300 on the 6910p running before, but it was a long time ago. I would need internet access again on the road. I detached the battery and put in the sim card to test. It seems modem can't be detected. Doesn't appear on lsusb, not much clue on dmesg, I verified that its turned on bios, started to look around forums, tried various modprobe, was going to start using usb-modeswitch.


I then decided to reboot to Windows after several years of not going there. HP wireless assistant tells that its disabled as that the gsm sim is accessible and suggest to close or put the battery back. I put the battery back, HP wireless assistant changes status to still disabled but now suggest to fix via Device Manager. No luck, Device Manager can't find drivers, etc. So did not want to spend it running on Windows and maybe putting the battery back is enough to get it running on Linux again.

Reboot to linux, network manager picks it up. Nothing to setup aside from APN, etc. No driver install, etc. Just put the battery back. Hopefully this post saves someone a few hours diagnosing the problem. Just put the battery back and linux should see the hs2300 3G modem.

Tuesday, August 31, 2010

More on Scala

Get Started on Debian/Ubuntu


Install scala, this would install version 2.7.7 though, 2.8.0 has just been out recently

apt-get install scala

Run the scala shell

scala

(optional) Quick upgrade to scala 2.8.0, install scala as per above and just copy the newer jars
Download scala from http://www.scala-lang.org/downloads and extract the tarball

tar xzf scala-2.8.0.final.tgz
cd scala-2.8.0.final/lib
cp scala-compiler.jar scala-library.jar scala-dbc.jar /usr/share/java


Get Started on Eclipse


Get the eclipse scala plugin http://www.scala-ide.org/ this would include the scala jar, compiler, console, etc.
When you have the plugin the following options are available

  • create a new scala project

  • right click on existing java project and add scala nature and you can now start coding both java and scala together

  • run the scala console inside eclipse



Reference and Links


Below are some useful reference

Scala Tutorial - useful w/ Java Background

Scala by Example - a little long, more like a scala cookbook

Programming Scala

First Steps to Scala - a bit old but still useful

Scala Idioms, Step 1, Lists and Maps - a bit old but quick way to learn about lists. Tuples are using old syntax of {x, y} which is now changed to (x, y)

Who is using Scala




Frameworks and OSS Projects


Wednesday, August 18, 2010

Looking at Scala again

I have been look at scala and lift (web framework built on scala), on and off about a year now. I have revisited it again for the past few weeks. Scala as a language seems to be promising. For me it adds something new to the main stream languages today, like pattern matching (not regexp), functional programming, actors library. There are some languages that have these properties but I think scala has got some transitional properties giving some balance. Using scala you get to access java libraries natively, despite its terse syntax it is still a static language, this would mean tool developers will have an easier.

Scala
Lift

I have also been re-using emacs again. Some interesting scala emacs some stuff.

Scala emacs tools

Friday, July 16, 2010

Low tech stuff

I have started on computers when its wasn't hip yet. When I was a kid, I toyed around a PC XT on green monochrome monitor. Then on to doing BASIC, then to over clocking on a Pentium when Asus brought out the first overclock board. Buying a linux book to get a slackware CD as downloading over a 2400bps modem is very slow. Time has passed so fast.

Lately the latest and greatest tech stuff hasn't been appealing for me. I do get touch the nice smart phones at work. Although new tech stuff isn't as appealing as before. Not sure why, maybe just too many tech stuff going around these days.

Back in the 80s there was something cool, which wasn't computers. I am talking about RC. Remote Control cars, me and my son have a few them.



These are low tech stuff, but very interesting for me. Its one of the interesting things to me as kid back then, aside from playing space wars on a PC XT. This appeals for me especially now as my son is able to build and play with me right now.

LXC on Ubuntu 10.04 Lucid Lynx

If you are like me who doesn't have a lot of time anymore, at times trying new stuff is a lot harder. About a year ago I used kvm, which is great and easy enough to get up and running. I have used it since then however Kvm is a bit too much for my needs as its a full paravirt. Container based virtualization like vserver and openvz seems to be more challenging to get running on a laptop.

Fast forward today, it seems LXC Linux Containers (http://lxc.sourceforge.net) has now made some strides. Its now part of the main kernel, most modern distro should have like. Here is a quick guide on how to get lxc up and running on Ubuntu Lucid.

Below is to setup a debian lenny guest, that uses virbr0 and has dhcp. Do the following as root:

- install libvirt as its easier to do networking on it. No need to setup your own bridge, ipchains and nat. libvirt default qemu network should create a virbr0 interface.


apt-get install libvirt-bin


I have installed this prior for kvm. What we want is virbr0 is up and running. You check this by ifconfig. Try to start it manually on /etc/init.d/libvirt-bin

- install lxc

apt-get install lxc debootstrap


- create the capabilities dir and mount it

mkdir /cgroup

add to /etc/fstab
none /cgroup cgroup defaults 0 0

mount /cgroup


- get and edit the lxc-debian script from /usr/share/doc/lxc/examples/lxc-debian.gz (gunzip it somewhere and apply correct permissions)

Edit and add the following lxc parameters on copy_configuration() function before EOF

# networking
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = virbr0
lxc.network.name = eth0
lxc.network.mtu = 1500
EOF

What this does is use the host virbr0 which is already NATed. This would appear as eth0 on the guest container.

You may need to edit increase the tty allowed, I was getting init warning on my syslog respawning. What I did was to edit my guest inittab to reduce the tty.

lxc.tty = 4 to lxc.tty = 6


- create your lxc dir. In my case the name of my container is "altair". Change it as you fit.

mkdir /home/lxc/altair
lxc-debian -p /home/lxc/altair create


This would start downloading debian lenny packages and create the root file system on /home/lxc/altair/rootfs.

- create the container

lxc-create -n altair -f /home/lxc/altair/config


- run the container

lxc-start -n altair

the above runs it on the foreground, once you have setup everything then you can run it as a deamon

lxc-start -n altair -d


Once you are inside the container, things that I did was
- set the hostname
- fix /etc/hosts
- add your favorite repo on /etc/apt/sources.list
- add X forwarding on ssh and install xauth package
- install rsyslog
- maybe edit your hosts /etc/hosts and add the IP address of the container.

Some useful links:

http://lxc.teegra.net/
http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-lucid-containers/
http://nigel.mcnie.name/blog/a-five-minute-guide-to-linux-containers-for-debian
http://en.gentoo-wiki.com/wiki/LXC