Skip to content

Commit 04aa3cf

Browse files
author
Patrick M
committed
feat: smb for lxc
1 parent b3ea325 commit 04aa3cf

3 files changed

Lines changed: 153 additions & 1 deletion

File tree

239 KB
Loading

src/data/blog/2024/using-curl-with-sni copy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: post
33
title: "Using curl with SNI"
44
pubDatetime: 2024-05-01
5-
featured: true
5+
featured: false
66
tags: ["Linux", "Bash"]
77
description:
88
"This is a short little reminder for myself, when using curl to make requests

src/data/blog/2026/smb-for-lxc.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
layout: post
3+
title: Passing SMB to LXC on Proxmox
4+
featured: true
5+
draft: false
6+
pubDatetime: 2026-02-26T12:00:00
7+
slug: hello-world-again
8+
tags: [ "LXC", "systemd", "Proxmox" ]
9+
description: "Passing an SMB share from the proxmox host to LXC"
10+
---
11+
12+
![A small creature prodding a bigger creature to work](../../../assets/images/2026/smb-for-lxc/header.jpeg)
13+
14+
I've started thinking differently about mounting my SMB shares in my LXC containers. The main benefit has always been portability. Shifting an LXC between hosts was as easy as migrating them because the mount was maintained in the host. There are some serious drawbacks to this approach though, mainly security. Having to run the LXC as root. Also, remounting if there is a connectivity issue with the SMB share. You can't use systemd automount without opening permissions up even further, which again, security. This finally got to me, so I swapped everything to host mounts. Here's how I did it.
15+
16+
## Automounting
17+
18+
The big piece here is the mount and automount unit file for systemd. I keep these in `/root/` in a folder called `systemd-mount` so lets start there.
19+
20+
```bash
21+
cd /root
22+
mkdir systemd-mount
23+
chmod 700 systemd-mount
24+
cd systemd-mount
25+
```
26+
27+
### Folder Structure
28+
29+
Next I want to create a folder to keep each share separate. I like to use the naming convention of `[NAS host]-[share name]-[share user]`. For this example I'm going to create `filehost-documents-proxmox`.
30+
31+
```bash
32+
mkdir filehost-documents-proxmox
33+
chmod 700 filehost-documents-proxmox
34+
cd filehost-documents-proxmox
35+
```
36+
37+
Now we can create our unit files, starting with the mount unit. The naming convention for mount unit files is specific and must follow the folder path. So a mount unit that creates a mount at `/mnt/filehost/documents/` would need to be named `mnt-filehost-documents.mount`. Same for automount. I will also create a credentials file.
38+
39+
> [!IMPORTANT]
40+
> Mount units require file names that align with the folder mount path.
41+
> `/mnt/path/folder` becomes `mnt-path-folder.mount`
42+
43+
```bash
44+
touch mnt-filehost-documents.mount
45+
touch mnt-filehost-documents.automount
46+
touch documents-proxmox-credentials
47+
chmod 700 *
48+
```
49+
50+
### Mount Unit
51+
52+
```ini
53+
# mnt-filehost-documents.mount
54+
[Unit]
55+
Description=samba mount for //filehost.internal/documents for the proxmox user
56+
Requires=systemd-networkd.service
57+
After=network-online.target
58+
Wants=network-online.target
59+
60+
[Mount]
61+
What=//filehost.internal/documents
62+
Where=/mnt/filehost/documents
63+
Options=vers=3.0,credentials=/root/systemd-mount/filehost-documents-proxmox/documents-proxmox-credentials,iocharset=utf8,rw,x-systemd.automount,uid=101000,gid=101000
64+
Type=cifs
65+
TimeoutSec=30
66+
67+
[Install]
68+
WantedBy=multi-user.target
69+
```
70+
71+
### Automount Unit
72+
73+
```ini
74+
# mnt-filehost-documents.automount
75+
[Unit]
76+
Description=Automount for mnt-filehost-documents
77+
78+
[Automount]
79+
Where=/mnt/filehost/documents
80+
TimeoutIdleSec=0
81+
82+
[Install]
83+
WantedBy=multi-user.target
84+
```
85+
86+
### Credentials
87+
88+
```bash
89+
# documents-proxmox-credentials
90+
username=documents-proxmox
91+
password=your_share_password
92+
```
93+
94+
## Linking into `systemd`
95+
96+
Now that the units are created we have to link them into `/etc/systemd/system`. We can use `systemd link` to make the links. Remember, the link requires the absolute path and will fail with a relative one.
97+
98+
```bash
99+
systemctl link /root/systemd-mount/filehost-documents-paperless/mnt-filehost-documents.mount
100+
systemctl link /root/systemd-mount/filehost-documents-paperless/mnt-filehost-documents.automount
101+
```
102+
103+
> [!NOTE]
104+
> Link requires the absolute file path
105+
106+
Once linked you can verify with `ls -la /etc/systemd/system/mnt*`. If you see the symlinks, now reload systemd and enable the automount service.
107+
108+
```bash
109+
systemctl daemon-reload
110+
systemctl enable --now mnt-filehost-documents.automount
111+
systemctl status mnt-filehost-documents.automount
112+
systemctl status mnt-filehost-documents.mount
113+
```
114+
115+
> [!IMPORTANT]
116+
> You should only enable the automount. The automount unit triggers the mount unit.
117+
118+
Also verify the share is mounted by seeing if you can view files in the share.
119+
120+
```bash
121+
ls -la /mnt/filehost/documents
122+
```
123+
124+
## Adding the Share in LXC
125+
126+
Now we can add the share to our LXC container. In Proxmox, these are called mount points. Navigate to the LXC file and add the mount point to the configuration.
127+
128+
```bash
129+
cd /etc/pve/lxc
130+
ls -la
131+
```
132+
133+
```diff
134+
hostname: paperless
135+
arch: amd64
136+
cores: 4
137+
memory: 2048
138+
tags: debian13;samba;
139+
140+
---
141+
142+
unprivileged: 1
143+
features: nesting=1
144+
145+
+ mp0: /mnt/filehost/documents,mp=/mnt/documents,replicate=0
146+
```
147+
148+
The first path is for where on the host you want to map. The second is where that path will appear in the LXC. `replicate=0` tells proxmox not to back up the share. Now you should be able to start your LXC and navigate to the mount point from within.
149+
150+
```bash
151+
ls /mnt/documents
152+
```

0 commit comments

Comments
 (0)