HIFIBERRY DAC+ on Arch Linux


hifiberry_magni
Raspberry Pi B+ with HiFiBerry DAC+ connected to Schiit Magni amplifier




First of all follow directions here to install arch on your raspberry pi SD card. Click on the tab that says “Installation” and carefully follow all directions. I did my installation from a Linux computer and once it booted did all the ssh commands from the terminal on my mac on the same network.

These are the instructions but I strongly recommend going to the website and following them from there as they sometimes change. First and foremost you need to know which disk is yours. Picking the wrong disk can overwrite your hard disk. You’ve been warned.

Type lsblk (if you are doing this from a linux computer)



  • I just shoved an SD card from my camera into my computer to demonstrate.  You can see that the attached SD card of approximately 2GB in size is /dev/sde

  • So plug your card in and look for the proper size.  Once again if I use /dev/sda I’m going to wipe out the hard drive on the computer that I am doing this on so this is a potentially dangerous operation.  Get it right.

  • /dev/sdb in this example is my attached USB 1TB drive with all my backups.  Also, a potentially dangerous operation.  BE CAREFUL.


Image 1-18-15 at 8.03 PM

Replace sdX in the following instructions with the device name for the SD card as it appears on your computer.
  1. Start fdisk to partition the SD card:
  2. fdisk /dev/sdX
  3. At the fdisk prompt, delete old partitions and create a new one:
    1. Type o. This will clear out any partitions on the drive.
    1. Type p to list partitions. There should be no partitions left.
    1. Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector.
    1. Type t, then c to set the first partition to type W95 FAT32 (LBA).
    1. Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
    1. Write the partition table and exit by typing w.
  1. Create and mount the FAT filesystem:
  2. mkfs.vfat /dev/sdX1
  3. mkdir boot
  4. mount /dev/sdX1 boot
  5. Create and mount the ext4 filesystem:
  6. mkfs.ext4 /dev/sdX2
  7. mkdir root
  8. mount /dev/sdX2 root
  9. Download and extract the root filesystem (as root, not via sudo):
  10. wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
  11. bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root
  12. sync
  13. Move boot files to the first partition:
  14. mv root/boot/* boot
  15. Unmount the two partitions:
  16. umount boot root
  17. Insert the SD card into the Raspberry Pi, connect ethernet, and apply 5V power.
  18. Use the serial console or SSH to the IP address given to the board by your router. The default root password is 'root'.


Now plug your pi into ethernet and find your IP address. I use a program called Fing on my iPad or Android phone. My IP is 10.0.1.191 (this photo is an old screenshot of another Arch Pi I have).

fing

Or you can find your IP address from your routers configuration page. (Note that I did this after my initial installation which used ethernet @ 10.0.1.191, now that I am on WiFi my address is 10.0.1.186)

Screenshot 2014-11-29 12.52.00


now issue this command from a terminal program on the same network. I did this from my MacBookAir

shh 10.0.1.191 -l root

password is root

You’re in.

If for some reason you aren’t in and it barks at you about strict checking of ssh key pairs and refuses the connection try this

ssh-keygen -R 10.0.1.191

Make sure to use your IP address. Once that’s done you can run

shh 10.0.1.191 -l root

and now you’ll be in.


Screenshot 2014-11-28 13.05.31

Now update the installation.

pacman -Syyu

Screenshot 2014-11-28 13.05.42

Updating can take a while so relax and just let it do it’s thing. Reboot then log in again with the ssh command you used before.

Change your root password pronto. Enter the command, then your password of choice twice.

passwd root

Screenshot 2014-11-28 13.15.25

Now before we do anything fancy let’s set up the DAC. That’s the whole point of this, right?

nano /etc/modules-load.d/raspberrypi.conf

add this to the file

snd_soc_bcm2708
bcm2708_dmaengine
snd_soc_hifiberry_dacplus

Screenshot 2014-11-28 13.18.11

Notice how I commented out the first two lines with the # sign? That way if you ever remove the DAC and go back to a stock pi it’s easier to remove the three lines and uncomment the first two lines again. Back to stock.

Save the file by hitting Control X and then Y and enter.

Now open a new file

nano /etc/asound.conf

add the following

pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}



Screenshot 2014-11-28 13.21.11

Yep, Control +X, Y, Enter again. Now reboot.

For some reason I had to first install alas-utils before I could check the sound card / DAC

pacman -S alsa-utils

Screenshot 2014-11-28 13.26.30

now type

aplay -l

Screenshot 2014-11-28 13.28.59

Things are looking good here now!

Now notice it is Card 0, and Device 0. That corresponds with what we entered earlier.

Screenshot 2014-11-28 13.21.11

If for some reason you are Card 1 you need to make the appropriate adjustments to the file above. Change the zeros to ones. I don’t think you’ll have to but just file it away in case you do.

You should be able to make some sound now with the DAC.

Now install wget

pacman -S wget

Screenshot 2014-11-28 13.33.07

Once that is installed lets also install LogitechMediaServer. It’s a whole lot of no fun to install and compile and takes hours but I’ve done it for you so feel free to use my compiled file.

at the prompt type these three commands.

mkdir lms

cd lms

wget http://www.hagensieker.com/downloads-2/files/lms-7.8.0-4-armv6h.pkg.tar.xz

now type

pacman -U lms-7.8.0-4-armv6h.pkg.tar.xz

Screenshot 2014-12-01 09.38.45

now these commands

cd

mkdir squeezelite

cd squeezelite

wget http://squeezelite-downloads.googlecode.com/git/squeezelite-armv6hf

now this

mv ./squeezelite-armv6hf /usr/bin/squeezelite

now this

chmod ug+x /usr/bin/squeezelite

now test it.

squeezelite -l

Screenshot 2014-11-28 13.43.12

Note the blue highlighted card above.

Now do these two commands to start logitechmediaserver and enable it at boot.

systemctl start logitechmediaserver.service

and

systemctl enable logitechmediaserver.service

Now open your browser of choice and type YOUR IP ADDRESS. This is mine. Yours will be different.

http://10.0.1.191:9000

Screenshot 2014-11-28 13.48.21

And there is your media server. Now you have to create an account on LMS. Can’t help you there. Figure it out. Just follow the prompts like any other account you’ve ever created. When you are done come on back here. Select some services as well. I use Spotify, Pandora, and TuneIn Radio.

Ok, I’m logged in but if you notice in the upper right hand corner there is no player. That’s because we haven’t started it yet.
All you see if a little down arrow.

Screenshot 2014-11-28 13.51.08

Now lets start squeezelite. Remember the highlighted Card above. You’re gonna need that.

Issue this command:

squeezelite -o sysdefault:CARD=sndrpihifiberry -n HiFiBerryBPlus -s 127.0.0.1

Dash o is the sound card you are using. Dash n is the name of your player. You can name it anything you want. Dash s is the location of the server. In other words this tells squeezelite where to look for the server. 127.0.0.1 is the localhost address of your computer. This will work. If for example you have another logitechmediaserver somewhere you can point it to that server and your player will show up there. Very slick. But for now let’s just stay self contained.

squeezelite -o sysdefault:CARD=sndrpihifiberry -n HiFiBerryBPlus -s 127.0.0.1


And thar she blows. It shows up as your player. Now try to make some music. Mine works!

Screenshot 2014-11-28 13.55.03

If for some reason you can’t play mp3 streams do this: (TuneIn Radio is mp3 and my streams would start, never play and then go back to zero.) This fixed it.

pacman -S libmad

and restart your server or reboot or something.

Now lets start squeezelite at boot.

To start squeezelite at boot do this. Create a new file in /etc/systemd/system called squeezelite.service and add the following code to it.

[Unit]
Description=Squeezelite
After=network.target

[Service]
ExecStart=/usr/bin/squeezelite -o sysdefault:CARD=sndrpihifiberry -n HiFiBerryBPlus -s 127.0.0.1

[Install]
WantedBy=multi-user.target



nano /etc/systemd/system/squeezelite.service

Screenshot 2014-11-28 14.26.55


Do this:

chmod 755 /etc/systemd/system/squeezelite.service

then this to make it start at boot.


systemctl enable squeezelite.service

That’s about it. Now there is some house keeping you really should do

- Set up WiFi. Who wants to be hooked to a wire?

- Create a user or users (don’t run as root)!

- Set the time and date

- Set a hostname

- Install Samba Filesharing to drop and drag files such as your music files

WiFi
_____

type

wifi-menu

probably see this:

Screenshot 2014-11-28 14.32.20

pacman -S wpa_supplicant

now try agin

wifi-menu

Ok, there it is. Select your network

Screenshot 2014-11-28 14.34.50

Don’t be stupid with the name. Short = better

Screenshot 2014-11-28 14.35.00

Put in your password.

Screenshot 2014-11-28 14.35.16

To enable at boot type this:

netctl enable wlan0


Done. Cut the cord.

Create a user
____________

My name is John. Guess what my user name will be?

useradd -m -g users -G wheel -s /bin/bash john

now set a password

Screenshot 2014-11-28 14.39.40


Set Time and Date
_______________

Type
timedatectl status

timedatectl list-timezones

timedatectl set-timezone Asia/Tokyo

Asia/Tokyo is me. Set yours to where you are.

Now set the time.

if you don’t have ntpd type

pacman -S ntp

now type

ntpd -qg

That should set your system time. Now you have to make sure it happens at boot. NTP that is.

timedatectl set-ntp 1

Set a Hostname
_______________

hostnamectl set-hostname hifiberrydacbplus

then check it with

hostname

Screenshot 2014-11-28 14.45.26

Install Samba
___________

pacman -S samba

then follow below

cd /etc/samba

ls

cp smb.conf.default smb.conf

ls

Screenshot 2014-11-28 14.51.09

now

systemctl start smbd
systemctl start nmbd

then

systemctl enable smbd
systemctl enable nmbd

Add a user

pdbedit -a -u john

smbpasswd john

add your password when prompted.

now edit smb.conf

nano /etc/samba/smb.conf

here I’ve changed my workgroup name to JOHN which is oddly enough the name of my workgroup on all my computers at home.

Screenshot 2014-11-28 14.54.56

Now scroll WAY down to Share Definitions and do something like this

[john]
comment = John's Home
path = /home/john
writeable = yes
browseable = yes

Screenshot 2014-11-28 14.57.08

Control + X, Y, then Enter again.

Just to make sure it’s all good at this point just reboot and please no Samba purists tell me how much better I can be doing it. I know. I know.

From my Mac lets see if it worked or not.

Screenshot 2014-11-28 15.00.24

Of course it worked. You probably are going to get prompted for a user name and password. And I created the folder named Downloads just to make sure it worked.

Now since Samba is working lets see if we can get to our FLAC library on my Mac Mini server

Screenshot 2014-11-30 12.03.45

As you can see I have it on an external drive on the USB.

So now lets edit the /etc/fstab

nano /etc/fstab

Add this line to the bottom changing your details:

//10.0.1.54/Untitled/Music /mnt/samba cifs user=YOURUSERNAME,password=PASSWORD,sec=ntlmssp,cache=none,username=john,domain=JOHNS-MAC-MINI,uid=45,forceuid,gid=45,forcegid,addr=10.0.1.54,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=16384,wsize=17408,actimeo=1

Every once in a while you should run

pacman -Syyu

to keep your installation up to date and hopefully more secure.

And at this point you could and should back up your SD card. You just did a lot of work that could potentially die with your card.

shutdown with

shutdown -h now

Plug your card into a computer (I did this on a Mac) and type

diskutil list

find your card number. Mine ended up being /dev/disk3

Now type

sudo dd if=/dev/rdisk3 of=/Users/hagensieker/Archive/Temp/anyoldname.img bs=4m

Make sure to set your path correctly to whatever folder you want. Really neat trick in Mac......stop typing here

sudo dd if=/dev/rdisk3 of=/

then open Finder and find the folder you want to save your image file to and then just drag it into the Terminal program. Slick. No typing of long location names. And of course name it what you want to name it but make sure to use .img after the name.

Now it will ask for your password and you hit enter. Looks like nothing is happening and depending on the size of your card this could take a while. 15 or 20 minutes. So LEAVE IT BE.

Now on disaster day when your Pi won’t boot take an SD card of the exact same kind or another kind of a larger size. In other words if you use a Kingston 16GB SuperDuper card you must have the exact same card or you’ll have end up having a short write or a fail. It might not fit. All cards are NOT created equal. If you use an 8GB card to negate this problem if you don’t have the exact replacement card, use a 16GB card.

So enough of that. Plug the replacement card in and issue this command.

diskutil list (lets assume your card is /dev/disk3 again but CHECK)

sudo dd if=/Users/hagensieker/Archive/Temp/anyoldname.img of=/dev/rdisk3 bs=4m

wait the requisite 20 or 30 minutes and voila’. Yer doing it.