Time Machine via NFS on Mavericks

Here is my way of using nfs as time machine backup.
Avoid NFSv4 on Mavericks, it’s terribly unstable. NFSv3 is as fast as Netatalk in my environment.

1. Configure NFS server. The exports should at least have these options below.


2. Mounting NFS share from Mac by automount.

Create a file containing mount options. Make sure to use vers=3,resvport and locallocks, at least.

Format: “name of the mount directory you want to see in Finder” “nfs options” “nfs device directory”
e.g. vi /etc/auto_nfs
Backup -fstype=nfs,vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,

Edit /etc/auto_master, write mount point and filename of the text file created above.

Format: “mount point” “name of the text file you created above”
e.g. vi /etc/auto_master
/Users/Shared/NFS auto_nfs
Invoking automount.

sudo automount -vc

3. Create a disk image for time machine. Change the size to your liking, it won’t take actual space in the disk. Command below create sparsebundle image under current directory. Any volname, and sparsebundle filename is acceptable.

hdiutil create -size 500g -type SPARSEBUNDLE -nospotlight -volname "TimeMachine" -fs "Case-sensitive Journaled HFS+" -verbose ~/timemachine.sparsebundle

4. Move the disk image to NFS directory you mounted, and remove the local sparsebundle disk image

rsync -avE timemachine.sparsebundle /Users/Shared/NFS/Backup/TimeMachine/
rm -rf timemachine.sparsebundle

5. Setting NFS share as time machine destination
Mount the remote sparsebundle image.
hdiutil attach -verbose /Users/Shared/NFS/Backup/TimeMachine/timemachine.sparsebundle
Set the image as destination of time machine backup.
sudo tmutil setdestination /Volumes/TimeMachine

6. Set sparsebundle image to be attached automatically. Probably, this step is unnecessary.
Open System Preference, Select Accounts, Select your Account, Click on Login components tab, and drag the sparsebudle image on NFS and drop it to the list.

7. Start the first backup from the GUI. I recommend using TimeMachineEditor to schedule backup if you think it’s just plain stupid to take hourly backups of home-use
laptop like me.

Disable another annoying feature of Time Machine by the command below.
sudo tmutil disablelocal

8. How to use TimeMachine in Recovery Mode
I am not sure what happens when NFS share is mounted on the MacintoshHD volume.(OS intallation partition),
so in here, I mount it on the recovery partition.

Creating mnt directory in recovery hd for mounting
i. defaults write com.apple.DiskUtility DUDebugMenuEnabled 1
ii. select show every partition in debug tab in disk utility, and mount it.
iii. mkdir /Volumes/Recovery¥ HD/System/mnt
iv. unmount the disk
v. defaults write com.apple.DiskUtility DUDebugMenuEnabled 0<

Boot into recovery mode, and mount the NFS. You might want to write a simple bash script containing these commands and place it on recovery disk for convenience.
mount -t nfs -o vers=3,rw,soft,intr,rsize=32768,wsize=32768,noatime,timeo=1200,retrans=10,
proto=tcp,resvport,locallocks,noacl /Volumes/Image¥ Volume/System/mnt

Mount the sparsebundle image.
hdiutil attach -verbose /Volumes/Image¥ Volume/System/mnt/TimeMachine/timemachine.sparsebundle

That’s all!
You should see your disk in TimeMachine GUI.
Don’t close the lid during recovery, otherwise it pauses.
Please leave a comment if you have any better option.


NFS Setup Note

NFS Setup on Arch Linux

NFS server on Arch Linux
1. Get nfs-utils from repo

2. Edit domain section of /etc/idmapd.conf.

3. Edit /etc/exports and decide your pseudo-root directory (Can be anywhere)
Change the permission of the directories to your preference with chmod.
Explanations are available in man exports

4. mount the directory you want to share via nfs
mount –bind /mnt/hdd /srv/nfs4
in /etc/fstab
/mnt/hdd /srv/nfs4 none bind 0 0

5. Apply /etc/exports configuration.You must run the command below everytime you make changes to a exports file
exportfs -rav

6. Open ports for nfs, if you use iptables
specify mount port in /etc/conf.d/nfs-server.conf
MOUNTD_OPTS=”–port 4444″

Client Settings
From MacOS
Read man mount_nfs, man nfs.conf, man mount
To specify mount port use mountport=4444.

# It seems nfsv4 does not work well on Mavericks, even though MacOS is supposed to be Unix.
SMB will probably perform better.

# Updates
NFSv3 with certain options works very well.
Read the Time Machine via NFS article.

SSH Login Script

Bash(expect) script to login remote machines via ssh.
Append -L:”local port”:”Remote host”:Remote port” to do port fowarding.
Associate sh files with /bin/mintty.exe if you are using cygwin.

To one host

log=/cygdrive/c/Users/Public/logs/"$name"_`date +%d_%h_%Y_%H%M%S`

expect -c "
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null-l $user $host
expect password:
send $pass\n
" | tee -a "$log"_raw.txt
perl $noansi "$log"_raw.txt > "$log".txt

Send commands to more than one host(telnet)

hosts="host host1 host2"

for host in $hosts; do
expect -c "
spawn telnet \"$host\"
expect login:
send \"$user\n\"
expect Password:
send \"$pass\n\"
expect $
send \"ping\n\"
expect $
send \"exit\n\"

Perl script to remove all control characters from recorded files by tee.
Taken from http://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output

use encoding 'shiftjis', STDIN=>'shiftjis', STDOUT=>'shiftjis';
while () {
s/ \e[ #%()*+\-.\/]. |
\r | # Remove extra carriage returns also
(?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd
(?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL)
(?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST
\e.|[\x80-\x9f] //xg;
1 while s/[^\b][\b]//g; # remove all non-backspace followed by backspace

Cygwin Installation Notes

1. Get Cygwin and apt-cyg
Required packages for apt-cyg


Recommended extra packages

inetutils (telnet,ftp client)
util-linux (for script command)
openssh (for ssh server)
tftp (tftp client)
tcp-wrappers (for xinetd)
xinetd (for ftp,telnet,tftp server)
luit (for character encoding)

Install apt-cyg. If the command below fails just save http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
and place it under /usr/bin and make it executable.

svn –force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/
chmod +x /bin/apt-cyg

2. Configuration for Japanese Windows.
vi .inputrc

set kanji- sjis
set convert-meta off
set meta- on
set output-meta on

3. Configure Windows environment variables to use cygwin commands in Windows Powershell.
Right-click Computer, properties, Advanced system setting, environment variable
edit PATH and append the below. With Powershell, you don’t have to worry about character encodings.

4. Tuning to my preference.

vi /etc/bash.bashrc
PS1='[\u@\h \W]\$ '
alias explorer=/cygdrive/c/Windows/explorer.exe

To clear banner on ssh, ftp, telnet login, do…
echo '' > /etc/motd
echo '' > /etc/defaults/etc/motd

To make blue coloured text visible on black background, do…
echo 'Blue=127,127,255' >> ~/.minttyrc
echo 'BoldBlue=191,191,255' >> ~/.minttyrc

Cygwin vim does not set vimrc by default, so place vimrc under home directory and edit to your liking.
cp /usr/share/vim/vim74/vimrc_example.vim ~/.vimrc

To install ssh on Cygwin, do below.
cygrunsrv.exe -S sshd

To activate ftp, tftp, telnet server, do below.
vi /etc/xinetd.d/ftpd
vi /etc/xinetd.d/tfppd
vi /etc/xinetd.d/telnet
disable = no
user = username

Cygwin does not accept from outside by default, so edit below and comment all to accept from all.
vi /etc/hosts.deny
cygrunsrv -S xinetd

5. Whenever you have errors like “child info fork abort”, stop all cygwin related service and start ash.exe under bin directory, annd run /bin/rebaseall -v

6. In order to uninstall cygwin, stop and remove all cygwin services, and open regedit and search for keyword cyg and remove them. There are something like Cygnus Solution ~, and Cygwin totalling to four.

Arch Linux Installation Command Notes

Recently I installed Arch Linux on virtualbox, however, as of 1/1/2014 cfdisk was not working right
and I could not boot the OS by both grub and syslinux. Here is what I did.

1.Partitioning. (Just one logical partition is enough for me. No boot partition, no swap partition…)
cgdisk /dev/sda
#first sector = 2048(default)
#type = 8300(linux)

2. Boot Flagging
parted /dev/sda set 1 boot on

3. Formatting
mkfs.ext4 /dev/sda1

4. Installing packages and etc (follow the begginers guide of arch wiki)
vi /etc/pacman.d/mirrorlist
# bring up mirror site of your favourite location.
mount /dev/sda1 /mnt
pacstrap -i /mnt
genfstab -p -U /mnt >> /mnt/etc/fstab
arch-chroot /mnt
vi /etc/locale.gen
# uncomment en_GB.UTF8
echo LANG=en_GB.UTF8 > /etc/locale.conf
ln -s /usr/share/zoninfo/Japan /etc/localtime
hwclock -w -u
echo “your_hostname” >> /etc/hostname
useradd “username” -m -s /bin/bash
passwd “username”

5. Configuring grub
pacman -S grub
vi /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
grub-install —force /dev/sda

6. Reboot
umount /mnt

GUI setup on Virtualbox(xfce4 & slim)
pacman -S xorg-server xorg-server-utils xorg-xinit mesa
cp /etc/skel/.xinitrc ~/.xinitrc
pacman -S ttf-dejavu
pacman -S xfce4
pacman -S slim
vi /etc/slim.conf and specify default user and enable auto login
localectl set-x11-keymap layout jp106 to set jp106 keymap

Resource usage
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.8G 1.7G 5.8G 23% /
dev 248M 0 248M 0% /dev
run 250M 300K 250M 1% /run
tmpfs 250M 192K 250M 1% /dev/shm
tmpfs 250M 0 250M 0% /sys/fs/cgroup
tmpfs 250M 12K 250M 1% /tmp

free -h

total used free shared buffers cached
Mem: 499M 476M 22M 2.8M 15M 379M
-/+ buffers/cache: 81M 417M
Swap: 0B 0B 0B

455 user 9 -11 98860 6000 4256 S 6.7 1.2 1:34.90 pulseaudio
385 user 20 0 9536 1524 960 S 0.6 0.3 0:12.77 VBoxClient
96 root 20 0 0 0 0 S 0.1 0.0 0:01.71 kworker/0:2
136 root 20 0 11252 1656 1256 S 0.1 0.3 0:01.24 VBoxService
338 root 20 0 39696 4164 3376 S 0.1 0.8 0:00.19 upowerd
1 root 20 0 4704 2636 1980 S 0.0 0.5 0:00.77 systemd

About my blog

I started this blog to leave notes about IT stuff like configuring Linux
applications, network equipments and etc because I can’t memorise everything
I do and I don’t like googling everytime.
Hopefully I will remember stuff better by writing everything on this blog.