Friday, July 26, 2013

SamSung SSD 840 firmware upgrade on Mac without Bootcamp or Internal Superdrive

Situation

I replaced my internal superdrive with a Samsung 840 SSD in a HD caddy.  Then I put the superdrive in an external USB exclosure so I could simply attach the device for the very few times I need to read a DVD or CD-Rom.

Aside from the 1TB HD, I now also have a SSD that is used a boot disk and contains Mountain Lion and a bunch of applications.  Data is stored on the slower hard disk.

Problem

My Mid-2010 iMac does not allow to boot from the external superdrive.  When you try, you are quickly presented with the message that it could not find a bootable device, press a key to retry...
Because Samsung provides its SSD firmware update for Mac by a bootable ISO you have to burn to DVD, I was stuck.

I did not want to install Windows with Bootcamp, just for updating my SSD firmware.  And even if I would have wanted, it probably wouldn't work since I can't boot a DVD from my external superdrive.

Some more info about the Samsung SSD firmware

It appears that the DXT08B0Q_Mac.iso file from the Samsung download site contains just a single file: BTDSK.IMG, which is just an image file containing FreeDOS and an SSR directory with the actual firmware (SSR/FW/DXT08B0Q/DXT08B0Q.enc) and an update utility (DSRD1_0.EXE).

Simply putting the image file on a USB stick didn't work.  It was not found by the EFI boot manager of my iMac.

Workaround

So I needed to find a way to be able to boot FreeDOS and run the DSRD1_0.EXE to do the update.

That was where rEFIt came into the picture, which is an EFI boot manager that is more advanced that the standard EFI environment that comes with a Mac (which appears to be an EFI 1.x environment).

And I needed a FreeDOS image I could boot from rEFIt.

I didn't want the struggle attaching external devices, so I added 2 partitions to my internal HDD:

  • A HFS+ partition for rEFIt that can boot SYSLINUX
  • A FAT partition for SYSLINUX (needed to boot FreeDOS)

Procedure

Download the required tools and firmware:

Create the extra partitions with Apple's Disk utility:
  • first create a 1G partition with an Apple extended journaled file system for rEFIt, so call it rEFIt for clarity
  • then create a 1G partition with a FAT file system for SYSLINUX and a FreeDOS image, just make sure that this partition is within the first 3 partitions (so make sure it is a primary partition), or you won't be able to boot from it.  Name it SYSLINUX
Setup rEFIt:
  • Open the rEFIt-0.14.dmg image that you downloaded from the rEFIt site
  • Copy the "efi" directory to newly created rEFIt partition
  • Open a command shell and go to /Volumes/rEFIt/efi/refit/ to run the enable.sh script
    • cd /Volumes/rEFIt/efi/refit/
    • sudo ./enable.sh
Get a bootable FreeDOS image from the UNetbootin site and install it:
  • Run the app, provide the superuser password
  • Choose "FreeDOS" as the distribution (version 1.0 at this time)
  • Type: USB drive
  • Drive: /dev/disk0s4 (or whatever the device you have you SYSLINUX partition on, check with diskutil list)
  • It will download FreeDOS and install it on the partition
Next, prepare the firmware:
  • Open de iso file, you will find a BTDSK.IMG file
  • Open de BTDSK.IMG file, and copy the SSR directory to the SYSLINUX partition, so that you can access the firmware once you have booted in FreeDOS.
Reboot, and press the Option key while hearing the "BOING" sound at startup to boot FreeDOS:
  • Choose to boot SYSLINUX (rEFIt)
  • Choose the default kernel
  • Choose 5 to boot FreeDOS Live
  • Once you get the A:\> prompt, change to C:
    • C:
    • cd SSR
    • run DSRD1_0.EXE
  • Follow the install utility
  • In my case, I had to power cycle the SATA SSD, but I couldn't since it was internally, so the version check failed and it said it was unsuccessful.
After a reboot, the firmware version will be refreshed with the newest firmware version.


Friday, September 21, 2012

Release only specific sanlock resource

On august 29 2012, libvirt 0.10.0 has been released which includes the sanlock bugfix when hot-dettaching virtual disks:

http://libvirt.org/news.html

Wednesday, September 19, 2012

Test puppet code from shell

Sometimes it comes in handy to quickly test some puppet code or conditions from the command line.  The following command greps for ID in a file, and unless found it echoes a string (or does something more useful):

# ralsh exec "/bin/echo ID not found" unless="/bin/grep -q ID /etc/default/mpt-statusd"

If the "unless" command returns "1", the "exec" command is executed.
The inverted situation is covered by "onlyif".  If the "onlyif" command returns "0", the "exec" command will be executed.

Wednesday, August 22, 2012

limits.conf or limits.d

Sometimes you're hitting the limits of the operating system but you're not sure if your changes in limits.conf are picked up, or you are not sure what parameter may be hitting a limit...

Then you find plenty of information in /proc/$pid/limits!

# cat /proc/$(pidof java)/limits
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            10485760             unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             1024                 unlimited            processes 
Max open files            32768                32768                files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       15904                15904                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        

/etc/security/limits.d/90-nproc.conf limits nproc to 1024 to prevent fork bombs for all users.  You may need to override it for specific users or groups for high-capacity servers.

Tuesday, August 21, 2012

System V init template

Sometimes you just need a quick and simple custom System V init script template to be able to start/stop daemons during boot/reboot.

This init template uses the RHEL/CentOS symantics/functions and works on RHEL/CentOS 6.x

#!/bin/sh
#
# myApp Starts/stop the myApp daemon
#
# chkconfig:   345 55 25
# description: myApp description

### BEGIN INIT INFO
# Provides: myApp
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 345
# Default-Stop: 016
# Short-Description: Starts/stop the myApp daemon
# Description:      myApp description
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec=/path/to/myapp
prog="myapp"
OPTS=""
config=/etc/sysconfig/$prog

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    daemon $exec $OPTS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
}

stop() {
    echo -n $"Stopping $prog: "
    if [ -n "`pidofproc $exec`" ] ; then
        killproc $exec
    else
        failure $"Stopping $prog"
    fi
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

Tuesday, August 14, 2012

Sanlock patch accepted

My sanlock patch has been accepted by the libvirt maintainers today.  It will be included in libvirt 0.10.0.  It fixes the problem where all sanlock resources are released when hot-dettaching a disk from a qemu/kvm domain, leaving the other (disk) resources unlocked/unprotected.

Meanwhile, this is a situation that can be recovered from through the sanlock client by re-registering the assigned disks, or by avoiding the problem altogether by applying the patch.

Monday, August 06, 2012

Open vSwitch bandwidth throttling

Bandwidth throttling is pretty easy with Open vSwitch for outgoing (ingress) traffic.  Configure the ingress policy on the port interface for the specific virtual machine.  To limit outgoing bandwidth to 100Mbit/s:

# ovs-vsctl set Interface vnet0 ingress_policing_rate=100000
# ovs-vsctl set Interface vnet0 ingress_policing_burst=10000

The config can be tested with iperf by running the client on the VM, like:
 # iperf -d -i 10 -c <destserver> -t 60  
 [ 3] 0.0-10.0 sec 124 MBytes 104 Mbits/sec  
 [ 3] 10.0-20.0 sec 118 MBytes 99.1 Mbits/sec  
 [ 3] 20.0-30.0 sec 116 MBytes 97.1 Mbits/sec  
 [ 3] 30.0-40.0 sec 117 MBytes 98.1 Mbits/sec  
 [ 3] 40.0-50.0 sec 116 MBytes 97.7 Mbits/sec  
 [ 3] 50.0-60.0 sec 118 MBytes 99.2 Mbits/sec  
 [ 3] 0.0-60.2 sec 710 MBytes 98.9 Mbits/sec  

To reset the bandwidth to full speed:

# ovs-vsctl set Interface vnet0 ingress_policing_rate=0