Shared media folder
The media folder of the Proxmox host under /media, shared by Jellyfin, downloaders and co. – bind mount in LXCs, virtiofs in VMs, group media (GID 2000) in every guest. Attach it when creating the guest: var_media=<Directory Mapping>
Add to a guest
In the guest as root – container and VM alike:
update --add-modules media-shareRuns a normal update and installs the module on the way.
From the Proxmox node, without logging in:
pct exec <ID> -- update --add-modules media-share # container
ssh root@<IP> update --add-modules media-shareChoose when creating a guest
Without a dialog, on the Proxmox node:
IAC_NONINTERACTIVE=1 var_modules=auto-update,media-share \
bash -c "$(curl -fsSL https://haypack.dev/<app>/ct.sh)"var_modules replaces the app's preselection – keep auto-update in the list if you want it. Interactive: choose “advanced” in the dialog, or tick the module in the generator on the app page.
Remove
update --remove-modules media-shareRemoves the module's packages, services, firewall rules and configuration again. Data stays.
Details
One media folder on the Proxmox host, mounted under /media in every guest that needs it:
downloaders write into it, Jellyfin and co. read from it. Containers get it as a bind mount,
VMs over virtiofs – no network share and no NFS inside the guests. Because everything is one
file system, moving a finished download into the library is a rename or a hardlink, not a copy.
Every guest gets the group media with GID 2000. Containers map this GID 1:1 to the host,
virtiofs passes IDs unchanged – so whatever any guest writes belongs to the group media on the
host and in every other guest. Apps that use the folder put their user into the group.
Once on the Proxmox host
iac does not manage the storage of the host – this part is yours:
zfs create data-pool/media # or any directory, e.g. a mounted NAS share later
chown 100000:2000 /data-pool/media # 100000 = root of the containers, 2000 = media
chmod 2775 /data-pool/media # setgid: new files and folders get the group
echo 'root:2000:1' >> /etc/subgid # lets containers map GID 2000 1:1
Root of a container may not change anything that belongs to root of the host (UID 0) – the
owner 100000 lets the guests create their folders. Folders you create on the host yourself
(movies, tv, …) need the same: chown -R 100000:2000 /data-pool/media and
find /data-pool/media -type d -exec chmod 2775 {} +.
Then Datacenter → Resource Mappings → Directory Mappings → Add: ID media, path
/data-pool/media on this node (Proxmox VE 8.4 or later).
New guests
var_media=media bash -c "$(curl -fsSL https://iac.heyer.systems/<app>/ct.sh)"
var_media is the ID of the Directory Mapping. For a container ct.sh adds mp0 (the path of
the mapping on this node) and the lxc.idmap for GID 2000, for a VM vm.sh adds virtiofs0.
Both select this module. The interactive dialog asks for it under “advanced”.
Existing guests
Attach the folder on the host, restart the guest, then inside it: update -am media-share.
VM:
qm set <id> --virtiofs0 mediaContainer:
pct set <id> --mp0 /data-pool/media,mp=/media, then append to/etc/pve/lxc/<id>.conf:lxc.idmap: u 0 100000 65536 lxc.idmap: g 0 100000 2000 lxc.idmap: g 2000 2000 1 lxc.idmap: g 2001 102001 63535
Files already in /media of the guest are hidden by the mount – move them to the host first.
The update after attaching also creates the folders of the app (e.g. /media/downloads/usenet)
in the shared folder.
A VM with a mapping that is not called media: media_share_tag=<ID> in
/etc/iac/settings.env, then update.
Use it
Keep everything under /media, the downloads too – e.g. /media/downloads, /media/movies,
/media/tv. Apps that write there need UMask=0002, so the group may change their files.
Limits
- Proxmox backups do not contain the folder – neither bind mounts nor virtiofs.
- A VM with virtiofs cannot be live-migrated and has no snapshots with RAM.
- Containers and VMs on other nodes need the same mapping there, with the same data (e.g. a NAS share mounted on every node).
Check it
findmnt /media
getent group media # media:x:2000:<users>
nobody:nogroup on everything in /media of a container: the host folder does not belong to
100000:2000 – fix it on the host as above, then update in the guest.
When the module is removed, a VM unmounts the folder; the group and all files stay. In a
container the bind mount stays until you remove mp0 on the host.
Ein Medienordner auf dem Proxmox-Host, eingehängt unter /media in jedem Gast, der ihn braucht:
Downloader schreiben hinein, Jellyfin und Co. lesen daraus. Container bekommen ihn als
Bind-Mount, VMs über virtiofs – keine Netzwerkfreigabe und kein NFS in den Gästen. Weil
alles ein Dateisystem ist, ist das Verschieben eines fertigen Downloads in die Bibliothek ein
Umbenennen oder ein Hardlink, keine Kopie.
Jeder Gast bekommt die Gruppe media mit GID 2000. Container bilden diese GID 1:1 auf den Host
ab, virtiofs reicht IDs unverändert durch – was ein Gast schreibt, gehört also auf dem Host und in
jedem anderen Gast der Gruppe media. Apps, die den Ordner nutzen, nehmen ihren Benutzer in die
Gruppe auf.
Einmal auf dem Proxmox-Host
iac verwaltet den Speicher des Hosts nicht – dieser Teil liegt beim Admin:
zfs create data-pool/media # oder ein beliebiges Verzeichnis, später etwa eine eingehängte NAS-Freigabe
chown 100000:2000 /data-pool/media # 100000 = root der Container, 2000 = media
chmod 2775 /data-pool/media # setgid: neue Dateien und Ordner bekommen die Gruppe
echo 'root:2000:1' >> /etc/subgid # erlaubt Containern, GID 2000 1:1 abzubilden
root eines Containers darf nichts ändern, was root des Hosts (UID 0) gehört – der Besitzer 100000
lässt die Gäste ihre Ordner anlegen. Ordner, die man selbst auf dem Host anlegt (movies, tv,
…), brauchen dasselbe: chown -R 100000:2000 /data-pool/media und
find /data-pool/media -type d -exec chmod 2775 {} +.
Danach Datacenter → Resource Mappings → Directory Mappings → Add: ID media, Pfad
/data-pool/media auf diesem Knoten (Proxmox VE 8.4 oder neuer).
Neue Gäste
var_media=media bash -c "$(curl -fsSL https://iac.heyer.systems/<app>/ct.sh)"
var_media ist die ID des Directory Mappings. Für einen Container ergänzt ct.sh mp0 (den Pfad
des Mappings auf diesem Knoten) und die lxc.idmap für GID 2000, für eine VM ergänzt vm.sh
virtiofs0. Beide wählen dieses Modul. Der interaktive Dialog fragt unter „advanced“ danach.
Bestehende Gäste
Den Ordner auf dem Host anhängen, den Gast neu starten, dann darin: update -am media-share.
VM:
qm set <id> --virtiofs0 mediaContainer:
pct set <id> --mp0 /data-pool/media,mp=/media, dann an/etc/pve/lxc/<id>.confanhängen:lxc.idmap: u 0 100000 65536 lxc.idmap: g 0 100000 2000 lxc.idmap: g 2000 2000 1 lxc.idmap: g 2001 102001 63535
Dateien, die schon in /media des Gasts liegen, verdeckt der Mount – vorher auf den Host
verschieben. Das update nach dem Anhängen legt auch die Ordner der App (etwa
/media/downloads/usenet) im gemeinsamen Ordner an.
Eine VM mit einem Mapping, das nicht media heißt: media_share_tag=<ID> in
/etc/iac/settings.env, danach update.
Benutzen
Alles unter /media ablegen, auch die Downloads – etwa /media/downloads, /media/movies,
/media/tv. Apps, die dorthin schreiben, brauchen UMask=0002, damit die Gruppe ihre Dateien
ändern darf.
Grenzen
- Proxmox-Backups enthalten den Ordner nicht – weder Bind-Mounts noch virtiofs.
- Eine VM mit virtiofs lässt sich nicht live migrieren und hat keine Snapshots mit RAM.
- Container und VMs auf anderen Knoten brauchen dort dasselbe Mapping mit denselben Daten (etwa eine NAS-Freigabe, die auf jedem Knoten eingehängt ist).
Prüfen
findmnt /media
getent group media # media:x:2000:<benutzer>
nobody:nogroup auf allem in /media eines Containers: Der Ordner auf dem Host gehört nicht
100000:2000 – auf dem Host wie oben korrigieren, danach update im Gast.
Wird das Modul entfernt, hängt eine VM den Ordner aus; die Gruppe und alle Dateien bleiben. In
einem Container bleibt der Bind-Mount, bis mp0 auf dem Host entfernt wird.