Configure your Linux based NAS as a TimeCapsule

The reason for the setup own TimeCapsule

Of cause, you can buy AirPort Time Capsule and setup it up for a few minutes if you are ready to spend around $400 and get a low-configurable device.

But, if you already have a Linux-based server in your home you can easily add Time Capsule functionality to it.

1. How it works

Actually, you need two services to emulate TimeCapsule for your Apple devices:

  • Samba server which provides shared folders in your network.
  • Avahi server which populate  TimeCapsule service information with Bomjour protocol in your network.
2. Install Samba and avahi servers

Get root permission with sudio:

host:$  sudo -s
Password:
host:#

Update your system:

host:# apt-get update
host:# apt-get upgrade

Install samba & avahi-daemon

You need samba version higher than 4.

 

host:# apt-get install avahi-daemon samba -y
3. Update hostname of your server

Hostname must be aligned between system, avahi-daemon, and Samba. Otherwise, your apple devices will find a several shares with different names in your network.

For an expample:

  1. Drive
  2. DRIVE
  3. my server

To avoid this situation you should configure your hostname accordingly to your preference to populate the share  for your apple devices.

host:# hostnamectl set-hostname YourHostName
Update file /etc/hosts It should look like this example:
127.0.0.1	localhost
::1		localhost ip6-localhost ip6-loopback
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters

127.0.1.1	YourHostName

Reboot your system and check your configuration when it started.

host:# hostnamectl
4. Configure avahi-daemon

You need to add config file to TimeCapcule service:

host:# cd /etc/avahi/services
host:# touch timemachine.service 
host:# vi timemachine.service 

Add following configuration and update it with your hostname:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">HOSTNAME</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
 <service>
   <type>_device-info._tcp</type>
   <port>0</port>
   <txt-record>model=TimeCapsule8,119</txt-record>
 </service>
 <service>
   <type>_adisk._tcp</type>
   <txt-record>sys=waMa=0,adVF=0x100</txt-record>
   <txt-record>dk0=adVN=TimeMachine,adVF=0x82</txt-record>
 </service>
</service-group>

Please pay your attention to row #4! 

“HOSTNAME” must correspond to configured in chapter #3!

Also, please pay your attention to row #17! 

“TimeMachine” name must correspond to your Samba share name!

Configure your system to launch avahi-daemon at system boot and launch it: 

host:# systemctl enable avahi-daemon
host:# systemctl start avahi-daemon

Your apple devices will find your TimeCapsule, but it be unaccessible till Samba would be configured and started.

5. Configure Samba server

You need to update Samba config file with necessary options and Share for TimeCapcule.

The standard Samba file is too big with a lot of commented parameters. There is a shortened config file with necessary options only for better visibility and understanding.

host:# vi /etc/samba/smb.conf

Change your config due to following example. 

[global]
        wins support = true
        server string = %h server (Samba, Ubuntu)
        netbios name = HOSTNAME
        obey pam restrictions = yes
        writeable = yes
        workgroup = HOME
        security = user
        pam password change = yes
        log file = /var/log/samba_log.%m
        logging = file
        passwd program = /usr/bin/passwd %u
        server role = standalone server
        encrypt passwords = yes
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        max log size = 1000
        map to guest = bad user
        os level = 20
        unix password sync = yes
        usershare allow guests = yes
        
[TimeMachine Home]
        path = /BACKUP/%U
        writable = yes
        durable handles = yes
        kernel oplocks = no
        kernel share modes = no
        posix locking = no
        vfs objects = catia fruit streams_xattr
        ea support = yes
        browseable = yes
        read only = No
        inherit acls = yes
        fruit:time machine = yes
        fruit:aapl = yes
        spotlight = yes
        create mask = 0600
        directory mask = 0700
        comment = Time Machine

Please pay your attention to row #4! 

“HOSTNAME” must correspond to configured in chapter #3!

Please pay your attention to row #22! 

Share name must must correspond to name in row #17 of avahi-daemon config file (chapter 4).

Samba is configured, but the directory to store is not created still.

So you have to create directory accordingly to line #23 in smb.conf.

host:# mkdir -p /BACKUP/

According to row #23 a new directory samba will add for each user (%U  means username) in shared directory.

Each user will have access to own directory only!

/BACKUP/mac/username (for an example).

6. Create a user for each Apple device

Of cause, you can use one samba-user for all apple devices, but it’s not a good approach due to security. 

Also, please be aware that each apple device thinks that all available space on your shared directory can be used for their own backups. 

It’s very difficult to limit space for each device if all of them use the same samba-user.

Create a group for all backup users (almost linux distributives have pre-created “backup” group and you can use it):

host:# groupadd backup
host:# groupadd: group 'backup' already exists

Add users with following commands and set passwords for them (repeat this block for each user):

host:# useradd -m -G backup user1
host:#  smbpasswd -a user1
New SMB password:
Retype new SMB password:
Added user user1.
host:#

Configure your system to launch samba at system boot and launch it:

host:# systemctl enable smbd
host:# systemctl start smbd

Configure your mac-device to use your new Time Capcule and enjoy it!

Here you can find how to limit your disk usage for backups.

Please feel free to ask any questions or leave your comments!

2 thoughts on “Configure your Linux based NAS as a TimeCapsule

  1. Hi Admin,

    great article. I would really like to implement your solution (in some way I did this long time ago
    emulating a time machine backup system) in a debian environment.

    So can you also give a short description, how to recover an iOS device using the TimeCapsule backups.

    Warm wishes from Heidelberg
    Tilo

Leave a Reply

Your email address will not be published. Required fields are marked *