Sunday, March 2, 2014

Mac OS X - fix boot problem due to hard disk errors

Returning from a 2 week trip to the Singapore and Myanmar (aka Burma), my Mac Book Pro 13 which had sat at home powered off the whole time, refused to boot.  About 15% throught the progress bar when booting, the Mac would power off.

Looking up keyboard shortcuts, I held down the 'd' key to show diagnostics, which indicated the mac was failing during the automatic fsck (disk drive file system check).

The solution:

  1. Boot to single user, by holding the 's' key once the startup gong sounds.
  2. Try /sbin/fsck -fy which forces a fix answering "yes" to all questions.  Repeat this command until no errors are reported.
  3. In my case, the "catalog" tree structure was broken enough that fsck stopped without fixing the problem.
  4. I ran fsck_hfs directly which has additional options not supported by the generic fsck, shown by man fsck_hfs.  In the following command, I used the raw device (/dev/rdisk0s2, for my laptop, yours maybe different) for my hard drive that the previous fsck had shown in step 2:
       /sbin/fsck_hfs -Rc /dev/rdisk0s2After this I reran /sbin/fsck -fy to verify the disk had been reconstructed.
  5. Restart the computer by exiting out of single user mode:  exit

Saturday, February 1, 2014

Linux: Samba starts before eth0 is up and will not serve... ack.

My main SMB server, call it sammy, was upgraded to Linux Mint 13 system, but it was not serving.

I noticed that after I started the system (sammy), but before I had logged in, I could not ssh into sammy.  After logging in to sammy on the console, I was able to ssh into it.  It was a surprise to not find it from other SMB clients.

After much debugging, the main clue came when I was on the SMB server, sammy.  Connecting via localhost loopback IP address, I see the SMB service fine when I ran
  smbclient -L localhost -N
but when I tried to connect via the ether IP address, nothing showed up 
  smbclient -L sammy -N   I

The long and short of it was samba was starting before the ethernet interface was getting assigned, so the smb server was unaware of that interface.  Restarting samba solved the problem via
   service smbd restart
   service nmbd restart

Saturday, January 25, 2014

Transfer files off your Android phone: use Droid NAS as an SMB server with a Mac or Linux

If you are getting a getting rid of an Android phone  or device, it's best to make a full backup before you factory reset it.   While, there are many ways to transfer files off of your Android device, I wanted to get everything by viewing my Android files from another "client" computer (which is where I'll copy the Android data).  The steps are:
  1. Export the Android files via the SMB/ CIFS protocol (which is how Windows shares files across computers)
  2. Mount the exported Android  "shares" (the root folders/directories) on a client computer, which can be either Mac or Linux, so you can see the Android files.  (It has been reported that windows will not work as Droid NAS exports via a non standard port; I have not verified if there is a workaround.)  Note: to use Linux you need to be able to run programs as root via sudo.
  3. Copy the files on the client from the Android device to your client computer, using rsync.
(1) Export or expose your Android data to another computer.
There are many Android programs that run as an SMB server.  The one I used is Droid NAS.   After starting the server in Droid NAS, it shows the IP of the Android device and a port, for example 7777, which is the value I will use in the following examples.  There are three profiles "Home", "Work", and "Cafe".  I chose "Home".  I also went to Settings (the gear icon on the bottom left) and specified the wi-fi network on which to export, and I added a user and password, which I'll assume are "uuu" and "pppp" in the examples.  To get these new settings applied, I stopped the server and restarted it.

(2) To see the Android files do either of the following:
On a Mac, in the finder, you should see the Android device in the Shared Section.
Since we added a user and password, you'll have to connect as user uuu with your password pppp.  The finder should show several "shares" that you can "connect" or "mount" on your Mac.

On my phone, I had four shares: Camera, Downloads, Photos and SD Card.  You may have more or fewer shares.

On a linux machine: Verify your linux kernel supports cifs.  You should see a line with cifs when you run
  % grep cifs /proc/filesystems
If you don't see anything, try using smbfs instead of cifs.  If you still don't see anything, you need a newer kernel.  Stop now.

(Optionally, though I never got this to work) verify you can see the Droid NAS as an SMB server:
 % smbclient -L Android-IP-address -p port -U uuu

Mount a share on the linux client.  First make a directory on the Linux cilent where the Android files will be mounted, say /mnt/Android/Camera.
  % sudo mkdir -p /mnt/Android/Camera

 Mount the Android share via the following command.
  % sudo mount -o ro,port=7777 -t cifs -o username=uuu,password=ppp //Android-IP-address/Camera /mnt/Android/Camera

(3)  Copy the files to your client computer.
On the mac:
  (a)  drag the Android shares where you want to copy them.  If this does not work, perhaps because you have too many files and the finder seems to time out getting all the files to copy
  (b) Open a terminal on your Mac and type
   % df
  See where the Android shares are mounted (look in the last column), e.g. /Volumes/Camera
  Copy each share them with rsync via
  % rsync -axv /Volumes/Camera /folder/holding/the/backup

On the linux machine, run rsync
  % rsync -axv /mnt/Android/Camera /folder/holding/the/backup