I kept forgetting to plug in my external USB drive to my MacBook for backups, so started rooting (no pun intended!) around for an automated solution to make backups over the network. Everything pointed to buying a home NAS – and while these aren’t too expensive, the bigger problem was finding the space for it (never mind the electricity & ethernet sockets to plug it in). So I started looking for a way to repurpose one of my existing network-connected devices.
I realised I had a prime candidate with the Lenovo ultra-small-form-factor PC (which I’d been using to play old games from my sofa), which you can see in the messy photo above, as it sits out of sight under my TV and is connected via ethernet to the home router. I installed Fedora Linux so that it could still be used for computing/gaming (and kept Windows 10 with dual-boot) and bought two cheap 1TB USB hard drives from Amazon and plugged them in (you can see the first one in the background, the second one is just out of shot). A couple of hours later, it was a home NAS ready to use for Mac Time Machine backups!
Here’s a quick(ish) guide to replicate what I did on Fedora (this should work with little variations on most distros):
Check your hostname
You’ll need this later (especially if you have lots of machines on your network), so run
hostname at the shell to check what it is. If you’re happy with it, all good. If you want to change it, you can do this:
sudo hostnamectl set-hostname your-new-name
Setting up the two USB drives for RAID mirroring
Look for the device address for the USB drives you plugged in. An easy place to see this is in the Disks utility that comes as standard in Fedora (look in the Utilities app folder). In my case, as the machine’s internal hard drive is an NVMe SSD, the external USB drives showed up as
The following command will create a single BTRFS filesystem using both disks, with both data (
-d) & metadata (
-m) mirrored (
raid1) on the other disk – this will help ensure your backup still works even if one drive completely fails. The ‘force’ (
-f) flag will overwrite the existing filesystems on the disks – this is necessary since most USB drives come pre-formatted, but double-check you’re referencing the right drives before doing this!
sudo mkfs.btrfs -f -m raid1 -d raid1 /dev/sda /dev/sdb
You can now mount the disk (first making a folder to mount it to) and create the Time Machine folder ready for the next step:
sudo mkdir /mnt/usbraid sudo mount /dev/sda /mnt/usbraid sudo mkdir /mnt/usbraid/TimeMachine
You’ll notice I’ve only referenced one of the drives: you can mount the RAID filesystem by referencing either of the devices it uses (it doesn’t matter which one). To verify that it’s using both drives, list BTRFS filesystems on your machine by running the following command (it’ll also show you the UUIDs and corresponding devices):
sudo btrfs filesystem show
Next, you’ll want to ensure the drives automatically mount at startup and, since they’re USB disks, you’ll want to refer to the filesystem using its UUID instead of the device addresses (in case those change). This is easiest done via the Disks utility again: click on the USB drive that shows as mounted, click the gear icon and open the mount options. You’ll want to do the following:
- Tick ‘mount at system startup’
- Open the ‘Identify As’ drop-down and choose the UUID (usually the final option)
The following steps will install Samba, enable the service (but not start it – we’ll need to configure it first), let it through the firewall, and give Samba permissions to read & write files across your filesystem.
sudo dnf install samba sudo systemctl enable smb sudo firewall-cmd --add-service=samba --permanent sudo setsebool -P samba_export_all_rw 1 sudo setsebool -P samba_export_all_ro 1
Below is a complete Samba config file (
/etc/samba/smb.conf) for Time Machine which you can use. Don’t forget to edit the path based on what you chose in the previous step, and the last line depending on the size of your disks. Don’t use the Time Machine share to store any other files, as they won’t be included in the max size calculation – if you want a network drive for general family use, set up another Samba share (just copy the TimeMachine block and edit appropriately, removing the last two lines that are specific to Time Machine functionality).
[global] map to guest = Bad User fruit:aapl = yes log file = /var/log/samba/%m log level = 1 max log size = 5000 min protocol = SMB2 vfs objects = acl_xattr catia fruit streams_xattr fruit:nfs_aces = no inherit permissions = yes fruit:model = MacSamba fruit:posix_rename = yes fruit:veto_appledouble = no fruit:wipe_intentionally_left_blank_rfork = yes fruit:delete_empty_adfiles = yes fruit:metadata = stream [TimeMachine] path = /mnt/usbraid/TimeMachine guest ok = yes writeable = yes browseable = yes read only = no inherit acls = yes fruit:time machine = yes fruit:time machine max size = 512G
Latest macOS versions (Big Sur & Monterey at the time of writing) may not allow Time Machine backups to proceed while logged into your home server as guest, despite the above Samba configuration allowing guest users on your network to write to the Time Machine share. You can resolve this by creating a local user on your home server that matches your Unix username on your Mac (you can check this by going into the terminal as your Mac user and seeing what shows up before the
sudo useradd username
You should then change the ownership of the Time Machine folder to this user (see below using
chown). You will also need to set a password for that user on the server in Samba (see below using
smbpasswd) which you’ll then use to login from your Mac:
sudo chown -R username /mnt/usbraid/TimeMachine
sudo smbpasswd -a username
This is the more secure option too in case you have unknowns on your home wi-fi, and you can then remove guest access from the Samba config.
Once in place you can start the Samba service:
sudo systemctl start smb
At this point you should be able to see your machine under its host name in Finder. You can then go into System Preferences on your Mac, then Time Machine and use ‘Select Disk’ to select your new Time Machine network drive as a target, at which point you’ll be prompted to login using the username/password combo you set up earlier.
If you’ve made mistakes or need to edit the configuration, don’t forget to restart Samba (
sudo systemctl restart smb) so the changes take effect before attempting to connect again.
And that’s it! Your Mac will now begin backing up. I would recommend enabling ‘Power Nap’ while plugged into the Power Adapter; this can be found under the Battery settings in System Preferences. This will ensure Time Machine backups happen in the background whenever your machine is plugged in (even if the lid is closed).
Quirks to watch out for
Some machines have the annoying habit of flipping drives off the bus. If this affects your machine, you may notice that a drive will disappear from e.g. /dev/sda and re-appear with another address e.g. /dev/sdc. Depending on the combo, your system may no longer recognise that both drives are part of the same RAID array: you can verify this by listing the BTRFS filesystems (
sudo btrfs filesystem show) and seeing if it reports a drive missing. Time Machine backups will work fine with one drive but you’ll of course lose the benefit of RAID mirroring, so you’ll want to correct the situation if it happens.
This can be done in 5 quick steps:
- Stop the Samba server (check in your Mac’s System Preferences first to see if a Time Machine backup is running; you can either wait til it finishes, or stop it)
- Unmount the USB RAID array
- Mount it again (use the UUID)
- Start the Samba server
- Begin the BTRFS ‘scrub’ process to correct any gaps in mirrored data between the disks
sudo systemctl stop smb sudo umount /mnt/usbraid sudo mount UUID=your-uuid-here /mnt/usbraid sudo systemctl start smb sudo btrfs scrub start /mnt/usbraid
You may wish to list the BTRFS filesystems (
sudo btrfs filesystem show) to double-check both drives show up. If you get a true drive failure in future, look up the BTRFS ‘replace’ function – you’ll be surprised how easy it is to replace a disk while keeping your filesystem running like nothing’s happened!
I used cheap spinning disks but came to regret it a bit (you don’t notice slow backups as they happen in the background, but you definitely notice when retrieving files from Time Machine later), so would recommend SSDs if your budget can stretch.
I hope this was useful! If there’s anything I’ve missed, and especially if you have a quicker/easier way of doing this, please let me know in the comments!