Time Machine Backups Using Proxmox, Ubuntu and an External USB Drive

󰃭 2024-09-01

This guide assumes you already have a Proxmox host, at the time of writing v8.2 was current, which is what I used. It also assumes you have a basic Ubuntu 24.04 VM running on that host. If not, you should set that up first. The VM can be fairly minimal; for example, 8GB of storage and 1GB of RAM should more than suffice.

It also assumes you have a USB Storage device that you want to use for backing up macOS using Time Machine.

Mapping a USB Drive to the Ubuntu VM Using Virtio in Proxmox

Mapping a USB drive via the Proxmox GUI is quick and easy, but the performance may be suboptimal because the driver is emulated. For better performance, it’s recommended to use the virtio driver, which is paravirtualized. Paravirtualization allows the guest VM to interact more directly with the hardware, improving I/O performance compared to emulated devices.

Retrieving Your VM ID in Proxmox

Before proceeding, you need to know the VM ID of your Ubuntu VM in Proxmox. Here’s how to find it:

  1. Log into the Proxmox web interface.
  2. Navigate to the Virtual Machines section on the left sidebar.
  3. Select your VM, and you’ll see its ID next to the VM name in parentheses (e.g., 105).

You will use this VM ID in the upcoming steps.

On the Proxmox Host (as root):

  1. Plug in the USB drive, then open a shell on the Proxmox host and run:

    ls -l /dev/disk/by-id/
    

    You’ll see output similar to this:

    lrwxrwxrwx 1 root root 13 Oct  4 09:02 nvme-nvme.1987-3231343337393-5036303020434f5245-00000001 -> ../../nvme0n1
    lrwxrwxrwx 1 root root 15 Oct  4 09:02 nvme-nvme.1987-3231343337393-5036303020434f5245-00000001-part1 -> ../../nvme0n1p1
    lrwxrwxrwx 1 root root  9 Oct  5 18:15 usb-Seagate_Expansion_Desk_NAAAA32D-0:0 -> ../../sdb
    lrwxrwxrwx 1 root root 10 Oct  5 18:15 usb-Seagate_Expansion_Desk_NAAAA32D-0:0-part1 -> ../../sdb1
    

    Identify your USB drive. In this example, the relevant entry is the last one.

  2. Assign the USB drive to your VM using virtio2 for optimal performance. Since virtio is paravirtualized, it enables more direct communication between the virtual machine and the hardware, reducing overhead and improving performance. If your VM ID is 105, you would run:

    qm set 105 -virtio2 /dev/disk/by-id/usb-Seagate_Expansion_Desk_NAAAA32D-0:0-part1
    

    Note: If you already have other virtio disks attached, you may need to adjust the virtio number (virtio3, virtio4, etc.) accordingly.

  3. Verify that the disk has been added to your VM by checking the configuration file:

    cat /etc/pve/qemu-server/105.conf
    

    Alternatively, you can check the Proxmox UI under the VM’s hardware section.

On the Ubuntu VM (as root):

  1. List the block devices on the VM:

    lsblk
    

    The output should look something like this:

    sda                         8:0    0   10G  0 disk
    ├─sda1                      8:1    0    1M  0 part
    ├─sda2                      8:2    0  1.8G  0 part /boot
    └─sda3                      8:3    0  8.2G  0 part
      └─ubuntu--vg-ubuntu--lv 252:0    0  8.2G  0 lvm  /
    sr0                        11:0    1  2.6G  0 rom
    vda                       253:0    0  5.5T  0 disk
    

    Here, the newly added drive is shown as vda.

  2. Mount the drive:

    # Create a mount point if it doesn't already exist
    mkdir -p /media/timemachine
    mount /dev/vda /media/timemachine
    

Installing and Configuring Netatalk

  1. Install Netatalk:

    apt install netatalk
    
  2. Edit the configuration file:

    vim /etc/netatalk/afp.conf
    
  3. Update the configuration by uncommenting and editing the relevant section:

    ;
    ; Netatalk 3.x configuration file
    ;
    
    [Global]
    ; Global server settings
    
    ; [Homes]
    ; basedir regex = /xxxx
    
    ; [My AFP Volume]
    ; path = /path/to/volume
    
    [Your Time Machine Volume]
    path = /media/timemachine  # Set this to your mount point
    time machine = yes
    
  4. Change the ownership of the mount point to your user:

    chown <your-username>:<your-group> /media/timemachine
    
  5. Restart Netatalk to apply the changes:

    systemctl restart netatalk
    

That should complete the setup for Time Machine backups. On your Mac you can now connect to the share using Finder and go and set up Time Machine from System Preferences.