Search This Blog

Surviving OSX crash on Linux

The aim of this post is to provide some ideas for recovering work from a crashed Mac machine, at least when the hard disk has not been damaged.

Objectives:

mount the Time Machine backup

mount the original disk as R/W with permissions

mount the disk as Copy on Write

clone the original disk as VDI and mount it

run OSX from Virtual Box

In the following I will note in upper case the mount points and the other parameters needed to the commands. These solutions will be relative to Linux, because, in my case, I was not having another Mac machine at disposal.

# The first option is the access to the Time Machine backup. This is possible through a Python based FUSE filesystem that is available at this link. As from the website documentation we need the path to the mounted Time Machine drive as TIMEMACHINEPATH and the full name of the Mac as HOSTNAME, due to the fact that multiple backups can be present on that Time Machine disk.

# The second option is to mount the original disk as HFS+ partition in Read/Write mode on Linux. This is automatic in recent Linux versions. There is anyway an issue of permissions. In particular all the system files of the OSX partition are visible, but the user's files are locked. Instead of accessing the files as root we use the bindfs virtual filesystem. Bindfs allows to mount any existing folder of Linux setting the rights of all the files to a given user.

sudo bindfs -u $(id -u) -g $(id -g) EXISTINGMOUNT NEWMOUNT

# In the case you don't like to mount the original disk in Read/Write mode it is still possible to get a read/write access using a Copy on Write approach. The resulting mount point will be read/write but all the changed files will be stored on a separate location. This is possible thanks to the use of unionfs, in particular the unionfs-fuse package. The following command merges SOURCEMOUNT and STORAGELOCATION accessing the former read only and the latter as copy on write storage:

The copy-on-write approach can be applied in general, also in the case of the mounting of the Time Machine backup.

# We probably do not want to keep the original hard drive connected all the time, and instead we would like to clone the disk. This could be done with dd at command line or with other tools creating a raw image. Instead we prefer to make a VirtualBox VDI, that is a virtual disk file for a Virtual Machine. The advantage is that the VDI of a read only disk is smaller than the physical disk, and, it is the necessary step for running if from VirtualBox. Assuming VirtualBox is installed we will use the VBoxManage tool as follows:

The DISKSIZEBYTES can be obtained by querying the disk size in bytes to fdisk, referring to the disk device, like /dev/sda or /dev/sdb.

sudo fdisk -l /dev/sda

# Now that the VDI has been created we need to mount it. If the VDI disk is a fixed size it can be directly mounted because the original content is placed on the disk at a given offset. We can use a loop mount:

sudo mount MYVDI NEWMOUNT -o ro,loop,offset=OFFSET

Where OFFSET is obtained from VBoxManage:

VBoxManage internalcommands dumphdinfo MYVDI

In general the VDI is not of fixed size, so we need to use another approach. In the past there was a FUSE filesystem provided with VirtualBox but currently the support is broken. There is also a general library called libguestfs that is super flexible and powerful. For this discussion I suggest to use a feature provided by the qemu emulator. This is obtained by the kernel module nbd (Network Block Device):

The DEVPATH is "/dev/nbd#" where # is the number of the device (0-15). DEVPATHPART is "/dev/nbd#p#" where the first # is the nbd device number, and the second is the number of partition in the disk (typically 1 or 2). All the considerations about HFS+ mounting and copy on write apply also to the mount of the VDI.

All the mounts can be destroyed with umount, while the qemu-nbd can be deleted with the -d flag:

sudo qemu-nbd -d DEVPATH

# The last possibility is to run OSX inside VirtualBox. This is a bit more difficult than installing OSX on a new disk, as can be found online. At the date of writing I am not able to boot to the graphical mode of a Maverick 10.9. What is anyway possible is to boot in single user mode. This can be done without any hacking, just using the latest version of VirtualBox.

What is needed is to create a VirtualBox machine pointing to the VDI file, to enable the EFI bios, and to provide enough memory to the machine. Then at the boot press ESC to enter the EFI boot manager. Then select the EFI Internal Shell from the Boot Manager. This will allow to specify boot options to the OSX boot manager:

fs4:
\System\Library\CoreServices\boot.efi -v -s

The first command moves from current drive to one of the hard disk partition, and this will depend on the layout of the disk. The second command boots the single user mode thanks to the -s option. From the single user mode the disk can be mounted in write mode and many useful commands can be issued...

Comments

Popular posts from this blog

The typical robotic stack is based on the Robotic Operating System (ROS) whose version is linked to a specific Ubuntu LTS distribution, e.g. Indigo-14.04 and Kinetic-16.04 to mention the most recent ones. When working with recent laptops it is possibly that even with a kernel update (like Linux 4.4) it is not possible to have a good working machine.

This post aims at providing some basic indications for using the Docker container system for creating a ROS setup with a different Linux distribution together with GPU support, e.g. running ROS Indigo inside Ubuntu 16.04. Docker is used in the industry for isolation and easy deployment, and in this case it solves the compatibility problem with minimal performance penalty.

We are using this approach internally at PERCRO laboratory of SSSA for working with research robots developed in RAMCIP and ReMeDi, and also with the Baxter robot from Rethink Robotics. The post provides a basic recap also on Docker for the minimal elements useful for pu…

CMake has greatly simplified the process of building libraries and applications across different platforms, and it is adopted by several large projects. Libraries can be easily found through find_package but the result of the lookup has to be manually added to the target through different commands. This post discusses how include the external libraries in an easier way:

The subtitle of this post could be C++11 is cool, but let's start from the beginning.

The starting point is the long standing argument on reporting error states of functions by means of exceptions or by multivalued functions. Recent languages such as Go by Google and Swift by Apple prefer to manage error states in the second form, while C++ and Java are biased toward exceptions (See [6] for a discussion).

Multivalued functions are based on the concept of sum-types, also called algebrical types in other languages such as Haskell, or tagged unions. A sum-type is defined by a list of types, and a sum-type variable contains a typed value from such a list. A sum-type is similar to unions, except that the current type of the union is managed automatically; also a sum-type can be considered complementary to C++11 tuples. In particular we can say:multi-type, single-value: sum-type/variant multi-type, multi-value: tuplesingle-type, multi-value: vector or array
…