In this tutorial I will explain how to install a music streaming server (madsonic) On Raspberry Pi with ArchLinux ARM.
To see a tutorial on how to install Arch Linux on a Raspberry Pi you can look at this post.
The main features of madsonic are the following:
- Intuitive web interface
- Supports transcoding to various formats (Ex. FLAC> mp3)
- It has clients for Android and iOS
Limit RAM for GPU and swap area creation (SWAP)
The Madsonic server runs on Java, so on a Raspberry Pi with 256 MB of RAM, it uses approximately 50% of the RAM. In this case, I recommend creating a swap space to prevent the Raspberry Pi from running out of memory.
1. We create a file that will be used as a swap file area and assign it a space of 512 MB
# fallocate -l 512M / swapfile
2. We assign read and write permissions to the file.
# chmod 600 / swapfile
3. We format as swap
# mkswap / swapfile
3. We activate swap
# swapon / swapfile
4. We add the following line to the /etc/fstab file to mount the swap automatically.
/ swapfile none swap defaults 0 0
5. We modify the file /etc/sysctl.d/99-sysctl.conf so that writes to swap are only performed when little RAM is available. We add the following line
vm.swappiness = 10
6. Using the command Free -h We check the amount of RAM we have.
7. We modify the file /boot/config. txt depending on the Raspberry Pi model we have, to limit the amount of RAM allocated to the graphics.
We will allocate 64MB of RAM for graphics.
- For Raspberry Pi model A (with 256 MB of RAM) we modify the line gpu_mem_256 = 128 by gpu_mem_256 = 64
- For Raspberry Pi model B (with 512 MB of RAM) we modify the line gpu_mem_512 = 316 by gpu_mem_512 = 64
Overclocking (Optional)
We will edit the /boot/config.txt file and uncomment some of the overclocking options located at the end of the file.
##Modest arm_freq=800 core_freq=300 sdram_freq=400 over_voltage=0 ##Medium #arm_freq=900 #core_freq=333 #sdram_freq=450 #over_voltage=2 ##High #arm_freq=950 #core_freq=450 #sdram_freq=450 #over_voltage=6 ##Turbo #arm_freq=1000 #core_freq=500 #sdram_freq=500 #over_voltage=6
I used the Modest option (speed of 800), with that speed my Raspberry Pi works well.
Madsonic Installation
Madsonic is located in the Arch Linux User Repository (AUR), therefore we need the base-devel package to be able to compile programs from the AUR.
We install the necessary packages:
# pacman -S wget curl base-devel yajl java-runtime libcups
We created a directory for the compilation and downloaded Madsonic from the AUR.
$ mkdir build $ cd build $ wget https://aur.archlinux.org/packages/ma/madsonic/madsonic.tar.gz
We extract the files and edit the file PKGBuild to add support for ARM processors. We look for the line arch = ('i686' 'x86_64') and we add
'armv6h'.
$ tar zxf madsonic.tar.gz $ cd madsonic $ nano PKGBUILD ... arch = ('i686' 'x86_64' 'armv6h')
We used the makepkg command to download and compile the madsonic code. This may take a while. Please be patient.
$ makepkg -g >> PKGBUILD $ makepkg
The makepkg command will generate a file with the .xz extension, which we can install using pacman.
# pacman -U madsonic-5.0.3860-1-armv6h.pkg.tar.xz
Installing Java Oracle for ARM
After installing Madsonic, I noticed that OpenJDK uses almost 100% of the processor, resulting in poor performance on the Raspberry Pi.
The solution to this problem is to use Oracle Java for ARM architecture. For more information on this topic, you can review the Oracle article where they present the Oracle Java vs. OpenJDK benchmark at this link.
We download Java Oracle for ARM architecture
wget --no-cookies \ --no-check-certificate --header "Cookie: gpw_e24 = http% 3A% 2F% 2Fwww.oracle.com% 2F; \ oraclelicense = accept-securebackup-cookie" \ "http: / /download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-arm-vfp-hflt.tar.gz "
We extracted the file to the path /opt/java-oracle/
# mkdir / opt / java-oracle # tar -zxf jdk-7u55-linux-arm-vfp-hflt.tar.gz -C / opt / java-oracle
We create the Java Home environment variable and back up the OpenJDK Java executables.
# JHome = / opt / java-oracle / jdk1.7.0_55 # test -L / usr / bin / java && mv /usr/bin/java[,.backup}
We created symbolic links for java and javac.
# ln -sf /opt/java-oracle/jdk1.7.0_55/bin/java / usr / bin / java # ln -sf /opt/java-oracle/jdk1.7.0_55/bin/javac / usr / bin / javac
Now we can test the Java installation with the command java -version
[eroland @ alarmpi ~] $ java -version java version "1.7.0_55" Java (TM) SE Runtime Environment (build 1.7.0_55-b13) Java HotSpot (TM) Client VM (build 24.55-b03, mixed mode)
We edited the madsonic configuration file to use Java Oracle and not Java OpenJDK.
# nano /var/madsonic/madsonic.sh
And we modified the JAVA_HOME line to look like this:
JAVA_HOME = / opt / java-oracle / jdk1.7.0_55 / jre: / usr / lib / jvm / java-7-openjdk
Madsonic configuration
The Madsonic configuration is done in the file /var/madsonic/madsonic.sh , the first thing we do is back it up.
cp /var/madsonic/madsonic.sh[,.backup}
In this file you can modify the port that madsonic will use (by default it uses port 4040), the path of the folder where the songs will be stored, etc.
We will add an external hard drive connected via USB where we will put the songs to be played.
If the hard drive is formatted as NTFS , you need to install the ntfs-3g package in order to mount the drive.
# Pacman -S NTFS -3G
We create the folder where the hard drive will be mounted and we give it the necessary permissions
# mkdir / mnt / Data # chmod 775 / mnt / Data
We obtain the mounting point of our Hard Drive
$ ls -l / dev / disk / by-label / total 0 lrwxrwxrwx 1 root root 10 Dec 31 1969 Data -> ../../sda2 lrwxrwxrwx 1 root root 10 Dec 31 1969 PS3 -> ../../ sda1
In my case I am interested in the disk labeled Data located at /dev/sda2
However, using the label to mount the disc is not highly recommended, as if the label changes, the disc cannot be mounted.
We obtain the unique identifier ( UUID ) of our hard drive.
ls -l / dev / disk / by-uuid /
We will have a result similar to this:
[eroland @ alarmpi ~] $ ls -l / dev / disk / by-uuid / total 0 lrwxrwxrwx 1 root root 10 Dec 31 1969 19F4-1917 -> ../../sda1 lrwxrwxrwx 1 root root 15 Dec 31 1969 2300 -4E18 -> ../../mmcblk0p1 lrwxrwxrwx 1 root root 10 Dec 31 1969 58F6AA78F6AA55D2 -> ../../sda2 lrwxrwxrwx 1 root root 15 Dec 31 1969 b471cde8-2a15-44e7-acce-e9a2a54511 - /../mmcblk6p0
We note down the UUID of our hard drive (in this case 58F6AA78F6AA55D2 )
We add the following line to the end of the /etc/fstab file
UUID = 58F6AA78F6AA55D2 / mnt / Data ntfs-3g default 0 0
We reboot our Raspberry Pi and the hard drive will automatically mount.
Finally we start the madsonic service:
# systemctl start madsonic.service
If we want the service to start automatically every time the system loads.
# systemctl enable madsonic.service
And voila, we have our music streaming server.
Once the madsonic service is started , we can access our Raspberry Pi's IP address and port 4040 from our preferred browser. In my case, it's 192.168.17.1:4040 , and we log in using the username=admin and password=admin.
Within the web interface we can add new users and change the default password.
Well, this is my first contribution, I hope you like it.
Sources:
http://d.stavrovski.net/blog/post/set-up-home-media-streaming-server-with-madsonic-archlinux-and-cubieboard2
http://www.techjawab.com/2013/06/how-to-setup-mount-auto-mount-usb-hard.html