Wednesday, March 19, 2014

MAC OSX not booting? Make a backup from single user mode first

Even when you keep daily backups your MAC might freeze at a time when the last important file has not been backed up. You should not reinstall the OS before making sure you have a backup. How to proceed? The easiest way (for the geek ?) would be:
  1. Restart in single mode (turn off, turn on and press "Command+S").
  2. When the prompt appears connect the external USB drive.
  3. Look for available disk drives. Most likely it will be the last one listed. In my case I had the internal drive, a USB stick and an external USB hard drive:
    # ls -l /dev/disk*
    ...
    /dev/disk2s2
    
  4. Now let us find the file system type. In my case it is a MAC Hierarchical File System (HFS)
    # fstyp /dev/disk2s2
    hfs
    
  5. To mount the drive we need write permissions. That is why we run the first command below. Needless to say you need to be careful from now on ...
    # mount -uw /
    # mkdir /extdrive
    # mount -t hfs /dev/disk2s2 /extdrive
    
  6. Backup what you need. For examplehere are some directories I backed up today:
    # cp -pr /Users/nestor/Downloads /extdrive/
    # cp -pr /Users/nestor/Documents /extdrive/
    # cp -pr /Users/nestor/Pictures /extdrive/
    # cp -pr /Users/nestor/Movies /extdrive/
    # cp -pr /Users/nestor/Desktop /extdrive/
    # cp -pr /Users/nestor/Library/Mail /extdrive/
    
  7. Unmount and shutdown (or restart):
    # umount /extdrive/
    # shutdown -h now
    

Bootable OSX USB Drive

If you do not have an OSX bootable USB drive you will need to make one from a healthy MAC:
  1. From the App Store search and download OS X. When you get to the below screen do not interact with it, that way the installer remains in the Applications directory. Just move on to the next step.
  2. Format a USB drive from "Disk Utility" using option "MAC OSX Extended (Journaled)" which will format the drive using HFS. Do not bother changing the name as it will be changed anyway as part of the below step.
  3. Run the below from Terminal (assuming the USB was formatted using the default 'untitled' name. Note that the command below corresponds to Mavericks. You probably will have to deal with a different version like El Capitan (/Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia) :
    $ sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
    Erasing Disk: 0%... 10%... 20%... 30%...100%...
    Copying installer files to disk...
    Copy complete.
    Making disk bootable...
    Copying boot files...
    Copy complete.
    Done.
    

Reinstall OS X

  1. Turn off the target MAC, insert the Bootable OSX USB Drive, turn on keeping the Option key pressed to be able to select from where to boot. BTW click here for more OSX startup options.
  2. From the options choose Disk Utility and select the "Macintouch HD". Click on Verify and if needed click on Repair Disk after. This is a crucial step. Errors like "this disk is lock" will be avoided later on. If the disk is damaged there is no need to keep trying as a replacement most likely will be needed.
  3. WARNING: This step erase the whole disk so I assume you have a backup or this is a blank disk. Just click on Erase and select as format "MAC OS Extended (Case-sensitive, journaled)". You might want to pick the "MAC OS Extended (Case-sensitive, journaled, Encrypted)" option. Conform you want to "Erase"
  4. NOw that the disk is formatted go to the menu and close the Disk Utility. Click on Install OSX, select the disk and continue with the installation. After some minutes your new OSX will be ready.

Applying all migration scripts sql or not from tagged releases : an svn cat tag versions example

Let us say your project goes from version 0.2.2 to 2.67. You have correctly tagged your project version after version and now you want to collect all migration scripts from one version to another. This is really achievable in a bash one liner. Below is one example with subversion: The one liner first gets a list from a classical tags directory. It then sorts based on the "period" as separator all tokens using alphabetical order for the first part (name of the package which we assume major version won't go over 9) and numerical order for the last two parts. It filters the results (hopefully less than a million versions ;-) between versions (If you need to exclude the from and to versions just use head/tail with "-n +2"). Finally for each version we concatenate the content of the migration to be performed.

Here is how the scripts invocation looks for a sql migration script:
$ ./svn-cat-tag-versions.sh \
http://subversion.sample.com/path/to/sample-core/tags \
src/main/resources/db/migration.sql sample-core-2.56.1 \
sample-core-2.58
/*****sample-core-2.56.1/*****/
ALTER TABLE contact DROP COLUMN email;
ALTER TABLE contact DROP COLUMN email_notification;
ALTER TABLE contact ADD COLUMN email_notification BIT(1) NOT NULL AFTER VERSION;

/*****sample-core-2.57/*****/
ALTER TABLE contact DROP COLUMN notification;

/*****sample-core-2.58/*****/
Note there was nothing to do as part of 2.58 release and yet the script presents the record making sure it is explicit that there is nothing to do for it.

Tuesday, March 18, 2014

On Lean thinking: Continuous delivery without a tool?

Necessity is the mother of invention. So if you are waiting for a tool to get into the wagon of continuous delivery, wait no more.

Culture should be cultivated to deliver often. And it should come before any tool. Once you are in the habit of finalizing what you started before starting to work on something new you will find yourself begging for a tool to speed you up.

This is because what looks natural to us to do every week in an hour becomes tedious when we need to spend that hour every day. The waste is simply visible now.

The tools then come alone, just from the need you will find or invent them.

Thursday, March 06, 2014

#Ubuntu Terminal Paste SHIFT+CTRL+V not working - just update and upgrade ?

This issue has happened to me in at least two versions of Ubuntu 10.10 and 12.10 as far as I recall. Paste is impossible from terminal is not allowed unless you use the contextual menu. The menu Edit/Paste would be grayed out and shortcuts won't work no matter what combination you choose via "Terminal Menu|Edit|Keyboard Shortcuts|Click|Type Keys". What to do? Simply put if after running the below two commands you still have the issue you better open a bug:
$ sudo apt-get update
$ sudo apt-get upgrade
However it stopped recently from working in a desktop and I found out the /sbin was not included in the PATH. Weird as it was defined in /etc/environment. I ended up adding /sbin to PATH in ~/.bashrc and after restarting a new terminal session I was able to paste again. There most be something wrong with environment variables and the files in charge to set them all. For now I can move at least ...

Followers