Oops

A few days ago, I finally decided to upgrade the installed Linux on my dedicated box hosted at OVH. As with every task you tend to postpone until it is too late, it failed miserably, Murphy’s law I am looking at you right now !

During the install process, the machine hanged (I am not sure whether the machine is faulty or not, it seems to shut down under heavy load). Fortunately for me, OVH is kind enough to send a tech resets the machine, and if it does not ping when booted, the tech reboots the machine in rescue mode.

Rescue mode

The rescue mode is a lightweight Linux booted on the machine so you can run fsckand other commands to rescue your filesystem (you can even scp files to backup before a reinstall for example.

My problem was simple, I needed to allow dpkg to finish its job in order for me to get a working machine. Then I think of the good old powerful chroot command and I remembered how powerful Unixes are !

Mounting filesystems

As you should know, chroot is a command allowing to change the root of a file system, litterally jailing it into a directory (popular things of today like pico containers like Docker are improved versions of chroot).

The partition layout of my machine is the following :

  • sda1 contains the root filesystem
  • sda2 contains home directories

I issued the following commands to “jail” the rescue mode into my machine :

$ mount /dev/sda1 /mnt
$ mount /dev/sda2 /mnt/home
    
$ mount -o bind /proc /mnt/proc
$ mount -o bind /dev /mnt/dev
$ mount -o bind /dev/pts /mnt/dev/pts
$ mount -o bind /sys /mnt/sys 
$ chroot /mnt/

From then, I was on my machine, with my files and so on, so I have been able to run dpkg to finish the install :

$ dpkg --configure --a

Finally, dpkg sent me back to a working prompt and I have been able to reboot the machine (do not forget to change boot disk in OVH manager to hd or netboot to prevent rebooting in rescue mode).

Command line nerd

As a command line geek, I always have at least one open and tend to use it for everything on my machine.

HomeBrew is a very convenient tool to install command line tools to your Mac without cluttering up your environment. You can use it like your Linux friends are using apt-get or yum and it feels really nice.

One thing that your friend can do and you cannot, is installing Google Chrome only using command line, this is where HomeBrew Cask comes to the rescue.

Installation guide

Cask will be up and running in a very few steps :

$ brew tap phinze/cask
$ brew install brew-cask
$ brew cask install dropbox #for example

Usage hint

This tool is really nice because it allows you to script your machine setup. No more headaches forgetting the installation of when you want to use it.

Don’t hesitate to add a small script in your .dotfiles to seed your software on new machines, and if your preferred software is missing, it is really easy to add new casks.

Manage your services

If you’re using HomeBrew to manage your software installation on your Mac, there is a thing that is not that easy to do : launchd or launchctl service management. Often you need to manually tell launchd to load the plist of your newly installed service. It leads to a lot of things launched at boot on your machine, and they are not easy to manage.

LaunchRocket provides a simple PreferencePane allowing you to start/stop services when you only need to with a clean and simple GUI.

LaunchRocket in action

You can easily install it via brew cask (more to come on brew cask soon) or download the zip distribution

Install from VirtualBox ?

If you are like me, you have got plenty of hard drives hanging around and never got an optical drive or an usb stick. One thing that could reveal itself to be hard is installing a new Operating System on any machine without any of the two I mentionned earlier.

In this short tips and tricks post, I will show you how you can use VirtualBox raw disks feature (I guess here for compatibility with VMWare) to install a new Operating System from your old one (yes, without the 10 minutes part were you can do nothing else with your computer).

Prerequisites

What you will need in order for this to work :

  • a Linux setup with root access (sudoing will be fine)
  • a second hard drive where you want to put your brand new Operating System
  • ISO file of the OS you want to install

Install

First of all, install VirtualBox on your system (yum, apt-get, whatever your package system is). Then you will need to find out what is the identifier of the drive you want to use as a new (sudo fdisk -l can tell you everything you need to know about your disks).

In my example lets say I want to install on a 300GB hard drive, I got this fdisk output

cgatay@cgatay2:~$ sudo fdisk -l
[sudo] password for cgatay:

Disk /dev/sda: 251.1 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders, total 490350672 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000efa30

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   489302015   244649984   83  Linux
/dev/sda2       489304062   490348543      522241    5  Extended
/dev/sda5       489304064   490348543      522240   82  Linux swap / Solaris

Disk /dev/sdb: 400.1 GB, 400088457216 bytes
255 heads, 63 sectors/track, 48641 cylinders, total 781422768 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003f041

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          63   390627047   195313492+   7  HPFS/NTFS/exFAT
/dev/sdb2       390627048   781422767   195397860    c  W95 FAT32 (LBA)

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00048185

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048      499711      248832   83  Linux
/dev/sdc2          499712  1952790527   976145408   83  Linux
/dev/sdc3      1952792574  1953523711      365569    5  Extended
/dev/sdc5      1952792576  1953523711      365568   82  Linux swap / Solaris

Disk /dev/sdd: 300.1 GB, 300090728448 bytes
255 heads, 63 sectors/track, 36483 cylinders, total 586114704 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb074

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1   *        2048   574060543   287029248   83  Linux
/dev/sdd2       574062590   586113023     6025217    5  Extended
/dev/sdd5       574062592   586113023     6025216   82  Linux swap / Solaris

The interesting line is the one stating Disk /dev/sdd: 300.1 GB. From now on I will use /dev/sdd as the target of my install.

For the rest of the commands to work you need to run everything as root (by sudoing), I think there is more “cleaner” way of doing this by correctly setting suid flags but I did not took the time to look after this.

You need to create the hard disk file that will point to your physical install, then launch VirtualBox as root (there is a lot of chances that your regular user can’t do everything he wants on a device):

sudo VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk /dev/sdd; #replace /dev/sdd with your device
sudo VirtualBox;

From there, this is a simple VirtualBox machine setup, you just need to select the created disk.vmdk file for the hard disk of your Virtual Machine, mount the ISO and proceed with the install. At the end of the install, you can shut down the VirtualMachine, reboot your computer and use the boot selection menu of your bios (or change the boot order) to boot directly on your newly installed system.

If you are on a Linux system, you can issue a update-grub that will detect all your operating systems and will create the boot menu (you can still boot your old one this way).

Disclaimer

This method has been tested multiple times for installing Windows as well as Linuxes without any hurt. However, it might kill kitten or trigger a nuclear war if used incorrectly, in such cases, I decline responsibility.

Thoughts

As a side note, I think a Linux host is not required, you can achieve the same with a Windows operating system, the command line surely just need some improvements to point to the physical disk.

Another Java Rest framework

If you’re a somewhat experienced Java developer I guess you’ve encountered a lot of framework when it comes to write web services.

Restx.io is a new kid on the block leveraging high velocity with a focus on testability through a set of unique and great features :

  • each rest endpoint generates its documentation from its tests (real killer feature here : we hate writing docs but we live writing tests!)
  • a built in monitoring engine
  • everything that can be done at compile time is done at that time (annotations / dependency injection)
  • it is written in good old plain Java (IDE support : I’m looking at you Play Framework!)
  • auto compile (we don’t like waiting!)

I’ve tested it on a few small projects, I can’t wait to try it on a real project !