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.