cmc/cleberg.net
My personal web garden & blog.
clone: git clone https://gitbay.org/cmc/cleberg.net.git
main: content/blog/2022-03-08-plex-migration.org · raw
1#+date: [2022-03-08 Tue 00:00:00]
2#+title: Migrating Plex to New Hardware with Nvidia GPU
3#+description: Moving Plex to new hardware and setting up Nvidia GPU transcoding.
4#+slug: plex-migration
5#+filetags: :self-hosting:
6
7* Migration Phases
8
9I recently decided to migrate my server from an old OptiPlex desktop machine to
10a custom-built tower with better hardware in every category. In order to do
11this, I would need to properly migrate a full Plex installation.
12
13The second part of this migration is that the new server uses an Nvidia GPU
14(graphics processing unit) and does not have any integrated graphics, which
15requires extra work for installation, but provides much better hardware
16transcoding options for Plex.
17
18Therefore, I have broken this migration down into three phases:
19
201. Configure the New Server
212. Migrate Plex Data & Devices
223. Configure GPU Transcoding
23
24* Phase 1: Configure the New Server
25
26** Choosing an Operating System (OS)
27
28In order to migrate Plex to my new server, I first needed to choose an
29appropriate OS and install it on the machine. Given that I have encountered
30numerous issues installing other Linux distributions properly with Nvidia
31graphics, I chose [[https://ubuntu.com/download/server][Ubuntu Server]].
32
33The first step is to create a bootable USB (universal serial bus) with Ubuntu
34Server. This is easy with [[https://www.balena.io/etcher/][Etcher]], an app that runs on many different platforms.
35Just download the Ubuntu Server =.iso= image, launch Etcher, and install the
36=.iso= on the USB.
37
38Once the USB is created, insert it into my server, reboot, and click =Esc= (or
39any of the =F1-12= keys) until the BIOS (Basic Input/Output System) menu
40appears. Finally, launch the USB boot drive.
41
42** Booting with Nvidia
43
44In order to install Ubuntu Server with an Nvidia Graphics card (and no
45integrated graphics on this device for some reason), you'll have to configure
46the boot menu to allow different graphics drivers to be loaded.
47
48When booting from the USB, the machine will launch the initial installation
49menu. From this menu, type =e= to view the default command options that come
50with the device - it's a good idea to take a photo of this screen, so you can
51enter these commands on the next screen (along with adding support for Nvidia).
52
53Finally, type =Ctrl + C= to enter the command line. From this command line,
54enter the commands found on the =e= screen. Remember to add =nomodeset= to the
55=linux ...= line so that your Nvidia device will display the installation
56screens properly!
57
58Here's an example of the commands I pulled from the =e= screen and entered on
59the command line.
60
61#+begin_src sh
62setparams 'Install Ubuntu Server'
63setgfxpayload=keep
64linux /casper/vmlinuz quiet nomodeset ---
65initrd /casper/initrd
66boot
67#+end_src
68
69Once the machine is rebooted, enter the =e= screen again and add =nomodeset= to
70the =linux ...= line again and press =Ctrl + X= to save the boot options.
71
72The machine is now fully installed and can properly display on an external
73display using the Nvidia GPU.
74
75Always remember to update and upgrade on a new installation:
76
77#+begin_src sh
78sudo apt update; sudo apt upgrade -y; sudo apt autoremove -y
79#+end_src
80
81* Phase 2: Migrate Plex Data & Devices
82
83This phase uses the great Plex article on migrations ([[https://support.plex.tv/articles/201370363-move-an-install-to-another-system/][Move an Installation to
84Another System]]) and adds a bit more information to help with commands and
85context.
86
87** Terminology
88
89- *Source:* The original server that is being replaced.
90- *Destination:* The new server.
91- *Client:* Any application that can be used to modify settings for both
92 source/destination.
93
94** Step 01: [Client] Update Settings
95
96Open up a Plex app and /disable/ the =Account= > =Library= > =Empty trash
97automatically after every scan= preference for the source server.
98
99** Step 02: [Destination] Install Plex
100
101Open up the [[https://www.plex.tv/media-server-downloads/][Plex Media Server download page]] and copy the link for the
102appropriate platform.
103
104Execute the following commands on the destination server to install Plex:
105
106#+begin_src sh
107wget <url>
108sudo dpkg -i <filename>
109sudo systemctl stop plexmediaserver.service
110#+end_src
111
112** Step 03: [Source] Stop Plex & Migrate Data
113
114First, stop the Plex service so that no data is created or modified during the
115migration.
116
117#+begin_src sh
118sudo systemctl stop plexmediaserver.service
119#+end_src
120
121Next, copy the data to the new server. To find where the Plex data directory is
122located, Plex has another excellent article available: [[https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/][Where is the Plex Media
123Server data directory located?]].
124
125There are many ways to copy the data to the new server and will largely depend
126on the size of the folder being copied. Personally, my data folder was ~23GB and
127I opted to simply use the =scp= command to copy the files over SSH (Secure Shell
128Protocol).
129
130This process was throttled by the old server's slow hard disk and ports and took
131approximately 90 minutes to complete. In comparison, moving the data from the
132new server's =home/user/= directory to the =/var/.../Plex Media Server=
133directory took 2-3 minutes.
134
135#+begin_src sh
136scp -r "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server" your_user@xxx.xxx.xxx.xxx:"'/path/to/destination/'"
137#+end_src
138
139** Step 04: [Destination] Update File Permissions
140
141In case you move the data directory to a common area on the new server, it will
142have to be moved to the proper location before Plex can function properly:
143
144#+begin_src sh
145mv "Plex Media Server" /var/lib/plexmediaserver/Library/Application Support/
146#+end_src
147
148To ensure permissions were retained properly, the server will need to show that
149all files and folders in the data directory are owned by =plex:plex= (or
150whichever user is running the Plex application).
151
152#+begin_src sh
153sudo chown -R plex:plex "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
154#+end_src
155
156Finally, start the service and check the status.
157
158#+begin_src sh
159sudo systemctl start plexmediaserver.service
160sudo systemctl status plexmediaserver.service
161#+end_src
162
163** Step 05: [Client] Update Libraries & Metadata
164
165The first step - now that the new server is up and running - is to sign out of
166the client and sign back in. Once this is done, update any library locations, if
167necessary. This was unnecessary in my case since I simply moved my storage
168drives from the source server to the destination server.
169
170Next, perform the following actions in the client:
171
1721. On the left sidebar, click =More= > Three-Dot Menu > =Scan Library Files=
1732. /Enable/ the =Account= > =Library= > =Empty trash automatically after every
174 scan= preference for the source server.
1753. On the left sidebar, click =More= > Three-Dot Menu > =Manage Server= > =Empty
176 Trash=
1774. On the left sidebar, click =More= > Three-Dot Menu > =Manage Server= > =Clean
178 Bundles=
1795. On the left sidebar, click =More= > Three-Dot Menu > =Manage Server= >
180 =Optimize Database=
181
182Finally, double-check the Remote Access settings to make sure no changes have
183caused issues with accessing the server from outside the network.
184
185In my case, I use a single port forwarding rule in my router and needed to
186update the Local LAN (local area network) IP (internet protocol) Address to the
187new server IP address.
188
189* Phase 3: Configure GPU Transcoding
190
191The final piece to the migration is enabling hardware transcoding so that Plex
192can fully utilize the new Nvidia GPU available in the server. The first step is
193to install Nvidia graphics drivers. This process may take a few minutes, but the
194commands are pretty simple:
195
196#+begin_src sh
197sudo add-apt-repository ppa:graphics-drivers/ppa
198sudo apt update
199sudo apt-get install ubuntu-drivers-common
200sudo ubuntu-drivers autoinstall
201#+end_src
202
203Finally, reboot so that the changes are loaded:
204
205#+begin_src sh
206sudo reboot now
207#+end_src
208
209To ensure that the Nvidia graphics drivers are working properly, run the
210following command to view the available GPUs, statistics, and processes:
211
212#+begin_src sh
213sudo nvidia-smi
214#+end_src
215
216Finally, enable hardware transcoding settings in the Plex application to finish
217the process.