Last active
June 21, 2018 01:47
-
-
Save stewartadam/373ef4249d2c3001cae088d2d535b375 to your computer and use it in GitHub Desktop.
Installing Plex in a systemd-nspawn container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER_NAME="plex" | |
CONTAINER_ROOT="/var/lib/machines/$CONTAINER_NAME" | |
BRIDGE_INTERFACE=br0 | |
mkdir "$CONTAINER_ROOT" | |
sudo dnf --releasever=25 --installroot="$CONTAINER_ROOT" install systemd passwd dnf fedora-release NetworkManager | |
systemd-nspawn -D "$CONTAINER_ROOT" --network-bridge="$BRIDGE_INTERFACE" | |
# Install Plex RPM here, then 'exit' or press Ctrl+] 3x to kill container | |
mkdir -p /etc/systemd/nspawn | |
cat << EOF > "/etc/systemd/nspawn/${CONTAINER_NAME}.nspawn" | |
[Network] | |
VirtualEthernet=no | |
Bridge=$BRIDGE_INTERFACE | |
[Files] | |
BindReadOnly=/your/plex/media | |
TemporaryFileSystem=/tmp | |
EOF | |
systemctl enable machines.target | |
systemctl enable "systemd-nspawn@${CONTAINER_NAME}" | |
systemctl start "systemd-nspawn@${CONTAINER_NAME}" | |
# If you ever want to open a shell to the container | |
machinectl login "$CONTAINER_NAME" | |
# If you want a read-write bind, to avoid 'permission denied' errors you'll want to chown any R/W mapped folders (on the host) | |
# to be based on the container's UID offset. The commands below demonstrate how to determine the UID offset for the plex user | |
# for a given container container. | |
CONTAINER_PLEX_UID=$(systemd-run -q -t id plex | grep -Eo 'uid=([0-9]+)' | cut -d'=' -f2) | |
let HOST_PLEX_ID=$CONTAINER_BASE_UID+$CONTAINER_PLEX_UID | |
chown -R $HOST_PLEX_ID /your/rw/mapped/folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment