# My Homelab Journey with Raspberry Pi: Immich for Photo Backup - Part 3

Hello again!

After setting up my Raspberry Pi with various services and getting everything to run smoothly, another need popped into my mind—creating a reliable photo backup solution at home.

Sure, we all rely on cloud services to store our photos and files, but let’s be honest—those costs climb as your storage needs grow. I’m not quite ready to ditch the cloud entirely (yet 😄), but having an additional local backup sounded like a smart move.

For this experiment, I repurposed an old external HDD that I wasn’t using anymore, thanks to a shiny new SSD. Then, I discovered **Immich**, a self-hosted photo and video management solution. Spoiler alert: it’s pretty awesome! You can check it out here: [Immich](https://immich.app/).

Let me walk you through how I set everything up, from prepping the hardware to deploying Immich.

## Preparing the External HDD

To start, I connected my external HDD to the Raspberry Pi via the blue USB port. Typically, these drives won’t mount automatically, so let’s confirm its status. I ran the command:

```bash
df -h
```

As expected, the drive wasn’t listed. So, I checked all block devices with:

```bash
lsblk
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1734283822746/8d38c1ff-fff4-41e0-9209-eb82089be980.png align="center")

Here’s where the HDD showed up as `/dev/sda`. Now, before proceeding, I decided to format the drive. (Quick tip: **Make sure you’ve backed up any important data on the disk first!**)

### Formatting the Drive

Using `fdisk`, I created a new partition table and formatted the drive:

1. Opened the disk utility:
    
    ```bash
     fdisk /dev/sda
    ```
    
2. Used the following commands within `fdisk`:
    
    * `o` to create a new DOS (MBR) disk label.
        
    * `n` for a new partition, choosing `p` for primary, and leaving the other options as default.
        
    * `w` to write the changes.
        
3. Formatted the new partition to the `ext4` filesystem:
    
    ```bash
    sudo mkfs -t ext4 /dev/sda1
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1734283891394/6ce72f16-35a0-4837-8782-c8712ae85b0e.png align="center")
    

### Mounting the Drive on the Raspberry Pi

With the external HDD formatted and ready, the next step was mounting it to the Raspberry Pi.

#### Step 1: Create a Mount Point

First, I created a folder where the drive would be mounted:

```bash
sudo mkdir -p /mnt/home-data
```

Then, I assigned the folder permissions to my user:

```bash
sudo chown -R ayub:ayub /mnt/home-data
```

(*Ps: Replace* `ayub` with your actual username.)

#### Step 2: Automatically Mount the Drive

To ensure the drive mounts automatically every time the Raspberry Pi boots up, I gathered the necessary details using:

```bash
sudo blkid /dev/sda1
```

This command returned something like this:

```bash
/dev/sda1: UUID="xxxxx-xxxx-xxxx-xxxx" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b12bb460-01"
```

I noted the `UUID` and `TYPE` values because we’d need them for the next step.

#### Step 3: Modify the `fstab` File

The `fstab` file controls how drives are mounted in Linux. I edited it with the following command:

```bash
sudo nano /etc/fstab
```

At the bottom of the file, I added this line:

```bash
UUID=xxxxx-xxxx-xxxx-xxxx /mnt/home-data ext4 defaults,auto,users,rw,nofail,noatime 0 0
```

(*Replace* `xxxxx-xxxx-xxxx-xxxx` with your UUID and `ext4` with your filesystem type.)

After saving the file (CTRL + X, then Y, and ENTER), I unmounted the drive to apply the changes:

```bash
sudo umount /dev/sda1
```

Finally, I re-mounted it with:

```bash
sudo mount -a
```

The drive was now ready to use, automatically mounting on every boot.

---

## Installing Immich

![](https://immich.app/img/logomark-light.svg align="center")

With the hard drive set up, I moved on to installing Immich using Portainer. Immich is a fantastic self-hosted photo and video management solution with a sleek interface and powerful features.

Here’s how I set it up:

#### Step 1: Deploy Immich via Portainer

1. Opened Portainer and navigated to "**Stacks**" in the sidebar.
    
2. Clicked on "**Add Stack**" and gave it the name **immich**.
    
3. Selected "**Web Editor**" as the build method.
    
4. Copied the content of the `docker-compose.yml` file from the official [Immich GitHub repository](https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml) and pasted it into the editor.
    
5. Updated the environment variables:
    
    * Switched `.env` references to `stack.env`.
        
    * Pasted the contents of `example.env` from the same GitHub repository into the **Environment Variables** editor.
        
    
    ![](https://immich.app/assets/images/dot-env-9d5e65f0228d512fff2efd9841a18d3c.png align="center")
    

#### Step 2: Configure Environment Variables

![](https://immich.app/assets/images/env-1-4e444bbed7269766444b939211014f7c.png align="center")

![](https://immich.app/assets/images/env-2-ee71f97989cf9c0d4b8f93ec182c6820.png align="center")

In **Simple Mode**, I made the following changes:

* Set a secure `DB_PASSWORD`.
    
* Updated `DB_DATA_LOCATION` and `UPLOAD_LOCATION` ***(in our case is /mnt/home-data)*** paths to point to folders on the external HDD.
    

#### Step 3: Deploy the Stack

Finally, I clicked on "**Deploy the Stack**."

(*Note: If you encounter an error like* `can't set healthcheck.start_interval as feature requires Docker Engine v25 or later`, you can fix it by commenting out the `start_interval: 30s` line in the `docker-compose.yml` file.)

## Creating a Proxy Host for Immich

Once Immich was up and running, it was time to make it accessible through a neat, custom domain name. For this, I used Nginx Proxy Manager.

#### Step 1: Connect Immich to the Nginx Proxy in Portainer

Since Immich was running inside Docker via Portainer, I needed to link it to my Nginx Proxy container. Here’s how I did it:

1. In Portainer, I made sure Immich was part of the same Docker network as the Nginx Proxy Manager. To do this:
    
    * I opened Portainer and went to the **Immich** container settings.
        
    * Under the **Networks** section, I added the **Nginx Proxy** network (the same network Nginx Proxy Manager was using).
        
2. Next, I created a **Proxy Host** in Nginx Proxy Manager, assigning a clean, easy-to-remember domain name (e.g., `photos.domaine.com`).
    
3. I pointed the domain to Immich’s internal container IP and port, and added SSL for extra security.
    

Now, Immich was accessible through the domain!

---

## Immich in Action

After everything was set up, I visited the domain URL and was welcomed by the Immich interface. I created my user account and started exploring. One of the coolest features is the mobile app, which allows you to automatically back up your photos. Simply download the Immich app on your phone, enter the URL of your Immich server, and your photos will be backed up automatically, keeping everything synced across your devices. The app works seamlessly and makes it so much easier to manage your photo library on the go!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1734284618609/76e78259-3e04-4e6a-8abb-38474334b7de.png align="center")

This project was a great way to enhance my home lab with a local photo backup solution. While I’m not ditching the cloud just yet, having a backup I control feels pretty awesome.

Stay tuned for more updates as my homelab journey continues!
