官术网_书友最值得收藏!

Running Logitech Media Server on the Pi

Our current solution is all well and good if you only want to use the system around the home and garden. However, to make the system truly portable, we need to move the media collection, Logitech Media Server, and wireless network to the Pi.

Creating a backup image of an SD card

Since we will now be making a few changes to the software running on the Pi, it may be worthwhile that you take an image of the SD card so that later, it is easy to restore the Pi to its working state.

Fortunately, this is a very simple thing to do, and since it is essentially just the reverse of writing the OS image to the card, it can be done with the dd utility:

sudo dd if=/dev/sdb of=working.img

This will create an image of the SD card at /dev/sdb and save it to the working.img file. This can later be rewritten to the SD card in the same way as a fresh OS image.

One thing worth noting about this method is that it will take an image of the entire SD card, including any free space. Hence, the size of the image is equal (or marginally smaller in the majority of cases) to the capacity of the SD card. This means that to restore the image, you need an SD card of at least the capacity of the card the image was taken from. For this reason, it is good to try and use an SD card that is just big enough for what you need, in order to both restore the image onto a larger range of SD cards and to reduce the amount of storage required to keep the images.

Automounting a USB storage device

Since its likely that your media collection may not entirely fit on a single SD card (as well as Raspbian), we will opt to store this on an external USB device, this could either be a USB memory stick or an external hard drive. The process of doing this is the same for all storage devices.

First, we need to know the path to the storage device and the filesystem it uses. Both can be obtained using the following command:

sudo blkid

This will give output similar to the following. Here, you can see the two partitions on the SD card (mmcblk0p1 and mmcblk0p2) as well as a USB memory stick (/dev/sda1). Ensuring that you assign a label to the partition while formatting it will help to make identification easier:

/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="787C-2FD4" TYPE="vfat"
/dev/mmcblk0p2: UUID="3d81d9e2-7d1b-4015-8c2c-29ec0875f762" TYPE="ext4"
/dev/sda1: SEC_TYPE="msdos" LABEL="DANNIXON" UUID="321A-15D0" TYPE="vfat"

Note the path to the device at the very start of the line and the partition type given by TYPE. We will need both of these pieces of information when we set up the partition to be mounted at the boot time.

Next, we will create a directory for the partition to be mounted on. This is the path that will be used to access the root of the partition when it is mounted. In this case, we will create a directory under /media. In Linux this is the directory used for mounting removable filesystems; the name of the directory is not critical, but something descriptive is recommended:

sudo mkdir /media/music

Now that the mount point has been created, we will modify the filesystem table (fstab) to automatically mount the drive when the Pi boots; this can be done using the nano text editor. The filesystem table needs to be modified as root:

sudo nano /etc/fstab

To add the partition of our USB device, the following line should be added to the end of the file, replacing /dev/sda1 with the path to your partition and vfat with the partition type (which were discovered earlier):

/dev/sda1 /media/music vfat defaults 0 0

Once finished, press Ctrl + X to save and exit. Reboot the Pi using:

sudo reboot

Once the Pi has booted, check whether the partition has been mounted and is accessible using:

ls /media/music

This should show you the files and directories at the root of the partition on the USB storage device.

Installing Logitech Media Server

Now that we have the music collection stored locally with the Pi, we need to move our Logitech Media Server instance there. Officially, there is no support for LMS on the Pi, however, All Things Pi (http://allthingspi.webspace.virginmedia.com/) has already done the work of porting LMS to run on the Pi.

Firstly, there are a few more libraries that are required by Logitech Media Server that may need to be installed first. This can be done with the following command:

sudo apt-get install libjpeg8 libpng12-0 libgif4 libexif12 libswscale2 libavcodec53

Now, we can download and install the Debian version of Logitech Media Server from the Logitech website:

wget http://downloads.slimdevices.com/LogitechMediaServer_v7.7.2/logitechmediaserver_7.7.2_all.deb
sudo dpkg -i logitechmediaserver_7.7.2_all.deb

As it is, the installation needs some modifications before it can be used on the Pi. Before we start with this, we need to ensure that LMS is not already running; this is done by attempting to stop the service:

sudo service logitechmediaserver stop

Next, we need to download and extract the required files that will be used to modify the LMS installation from All Things Pi:

wget http://allthingspi.webspace.virginmedia.com/files/lms-rpi-raspbian.tar.gz
tar -zxvf lms-rpi-raspbian.tar.gz

Now, we can perform the required modifications using the following commands:

sudo patch /usr/share/perl5/Slim/bootstrap.pm lms-rpi-bootstrap.patch
sudo mv arm-linux-gnueabihf-thread-multi-64int /usr/share/squeezeboxserver/CPAN/arch/5.14/
sudo mv libmediascan.so.0.0.0 libfaad.so.2.0.0 /usr/local/lib
sudo mv /usr/share/squeezeboxserver/Bin/arm-linux/faad /usr/share/squeezeboxserver/Bin/arm-linux/faad.old
sudo mv faad /usr/share/squeezeboxserver/Bin/arm-linux
sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so
sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so.0
sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so
sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so.2
sudo ldconfig
sudo chown -R squeezeboxserver:nogroup /usr/share/squeezeboxserver/

Once we are finished, Logitech Media Server should be ready to use. However, I had to reboot before I was able to navigate to the web interface:

sudo reboot

Once the Pi has booted, navigate to PI_IP:9000 (where PI_IP is the IP address of your Pi) to access the LMS web interface. Here, you can follow the same steps described earlier to set up your media library. Keep in mind that the web interface and media scanning may seem slightly slower than on a standard PC. This is mainly due to the lower system resources of the Pi.

Setting up the Pi as a Wi-Fi access point

Since we want to be able to use the speaker system wherever we go, we need a way to connect to the Pi without relying on the availability of a wireless network. The easiest way to do this is to turn the Pi into a Wi-Fi access point that we can connect to using a smartphone.

First, we will assign a static IP address to the Wi-Fi interface. Start by opening the interfaces file in nano:

sudo nano /etc/network/interfaces

Edit the file so that after the allow-hotplug wlan0 line, it looks like the following code. This code is telling the wlan0 interface to take a static IP address rather than using DHCP as was done previously:

allow-hotplug wlan0

iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0

#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

Next, we will set up the DHCP server, which will provide an IP address to any devices that connect to the Wi-Fi network:

sudo apt-get install isc-dhcp-server
sudo nano /etc/dhcp/dhcpd.conf

This will open nano to edit the DHCP server configuration. First, uncomment the authoritative line. This tells the server that it is the main DHCP server on the network. Next, comment out the following two lines:

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

Next, add the following lines to the end of the file:

subnet 192.168.42.0 netmask 255.255.255.0 {
  range 192.168.42.10 192.168.42.50;
  option broadcast-address 192.168.42.255;
  option routers 192.168.42.1;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name "local";
  option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Then, we need to tell the DHCP server which interfaces to use. This is done by editing the following configuration file:

sudo nano /etc/default/isc-dhcp-server

Add wlan0 to the list of interfaces so that the line looks like this:

INTERFACES="wlan0"

Next, we will install and configure the access point daemon. This involves creating a configuration file for the access point:

sudo apt-get install hostapd
sudo nano /etc/hostapd/hostapd.conf

Add the following lines to the configuration file, replacing NETWORK and PASSWD with the SSID and key you wish to use for the wireless access point:

interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=NETWORK
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=PASSWD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Now, we need to tell the daemon to use this configuration file when it starts. This is done by editing the daemon startup options:

sudo nano /etc/default/hostapd

Replace the DAEMON_CONF line with the following:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Finally, reboot the Pi and you should be able to connect to the Wi-Fi network using the login used in the configuration file. You can then use either a web browser or smartphone application to connect to the Logitech Media Server instance at 192.168.42.1.

If the Wi-Fi network is not showing up in a search, you may need to use an alternative driver. To check whether this is the case, run the following commands:

sudo apt-get install iw
iw list

If you see a message similar to nl80211 not found, then open /etc/hostapd/hostapd.conf and swap the commented out driver lines so that rtl871xdrv is uncommented. Next, we need to download a modified version of hostapd using the following set of commands:

wget http://www.adafruit.com/downloads/adafruit_hostapd.zip
unzip adafruit_hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv hostapd /usr/sbin
sudo chmod 755 /usr/sbin/hostapd

Once the commands have finished executing, reboot the Pi and you should be able to pick up the Wi-Fi network.

主站蜘蛛池模板: 乐陵市| 和平区| 双牌县| 五大连池市| 修文县| 唐海县| 宁安市| 东山县| 黔西县| 定西市| 漳浦县| 井冈山市| 庆城县| 贵定县| 蓝山县| 周宁县| 岳西县| 旌德县| 宣武区| 南城县| 北安市| 论坛| 米脂县| 称多县| 周口市| 连江县| 新野县| 乐陵市| 栾城县| 介休市| 余庆县| 金山区| 巴里| 福鼎市| 定远县| 金昌市| 南澳县| 奈曼旗| 兴义市| 乌拉特前旗| 银川市|