Tuesday, August 12, 2014

New Arch Linux + XBMC Installation guide







I decided to upgrade my HTPC with a SSD system drive, and a larger HDD for storage. Since I'm changing the system drive, that means a reinstall. As I did it, I found that quite a few things had changed since last time, so I made a new guide.

Compared to before, some things are easier to do, and some are more difficult.


My installation has no window manager, it is just XBMC on top of Arch Linux. If you want to be able to switch to a "normal" desktop environment for using a web-browser etc, then you can easily do that in addition to the things described in this guide, Google is your friend here.

Some of the things in this guide are optional, or HW-dependent. For both these cases I have tried to clearly mark them as such, as well as describing what they are for.

Preparation

Download the latest version of ArchLinux from archlinux.org and burn onto a CD/DVD or use a tool like dd (Don't use Unetbootin, it doesn't work with Arch Linux) to install to a USB-drive. You can find instructions here.

Boot the computer from this drive and select the appropriate version.
Once booted into the live environment, you can open additional terminals and switch between them with ALT+Fx, where x is the number of the terminal, the original one is 1. Login is “root” with no password needed.

The procedure is a little different depending on if you are using UEFI or not, I'm not. If you are, then there are some additional steps needed. Please see the Beginners' guide on the ArchWiki for details.

Later on during the installation, I realized that I had forgotten to create a swap partition, so I'm using a swap file instead. If you want a swap partition, do that during the other partitioning.

Installation

  • If needed change keyboard layout with the “loadkeys” command, the available keymaps can be sound under /usr/share/kbd/keymaps
    • loadkeys sv-latin1 (Swedish keyboard in this case)
  • You might need to setup an internet connection at this stage. If you have a wired DHCP connection, it should work without doing anything, if not, then you'll need to do some work on it.
  • Partition disks
    • First find your disks, and which is which
      • lsblk -o NAME,FSTYPE,SIZE,LABEL
    • Decide if you are going to use MBR or GPT partition tables, for disks over 2 TB GPT is required (you can mix and match MBR and GPT disks)
      • MBR: fdisk /dev/sdx
        • Type "o" + ENTER to create partition table
        • Type "n" + ENTER to create partition
        • For the rest of the options, the only thing you really need to enter is the size of the partition (unless you are using the entire disk, the  you don't even need that), leave the rest as default
        • Repeat from "n" for more partitions
        • Type "p" + ENTER to preview the partitions
        • Type "w" + ENTER to write the partitions to the disk 
      • GPT: cgdisk /dev/sdx
        • Choose "New"
        • For the rest of the options, the only thing you really need to enter is the size of the partition (unless you are using the entire disk, the  you don't even need that), leave the rest as default
        • Choose "Write", then "Quit"
      • Replace x with the letter for the drive you want to partition
  • Format (to ext4 filesystem in this case) and name your root partitions
    • List your partitions
      • lsblk -o NAME,FSTYPE,SIZE,LABEL
    • Format
      • mkfs.ext4 /dev/sdxy
    • Label
      • e2lable /dev/sdxy <label>
    • Replace x with the drive letter and y with the number
  • Repeat previous step for any other partitions you want to format
  • Edit the mirrorlist and move your closest mirror to the top of the list
    • nano /etc/pacman.d/mirrorlist
  • Mount the new root partition under /mnt
    • mount /dev/sdxy /mnt
    • Again, replace x with the drive letter and y with the number for your root partition
  • Install the base system
    • pacstrap /mnt base base-devel
  • Generate basic fstab
    • genfstab -U -p /mnt >> /mnt/etc/fstab
  • chroot into the new system
    • arch-chroot /mnt
  • If you want to have other disks automounted, edit fstab and add drives, find the UUID with blkid. This can be done later during the setup or any other time as well.
    • nano /etc/fstab
#
# /etc/fstab: static file system information
#
# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sdb6 LABEL=root
UUID=fb22b964-b38f-42df-bded-d9ac6df54ec5 / ext4 rw,relatime,data=ordered 0 1
# /dev/sdb5 LABEL=swap
UUID=21ecefbb-1c9d-48fa-a5f3-c9ba9a09b547 swap swap defaults 0 0
# /dev/sdb6 LABEL=home
UUID=d0e114fa-b428-4605-851d-504c86c0e7ac /home ext4 defaults 0 2 
  • Open /etc/hostname and add you computers name
    • echo XBMC > /etc/hostname
    • You can replace "XBMC" as the hostname with whatever you want of course
  • Symlink your local time with the correct timezone
    • ln -s /usr/share/zoneinfo/Europe/Stockholm /etc/localtime
  • Open locale.gen, uncomment the language profile you want and generate the profile
    • nano /etc/locale.gen
    • locale-gen
  • Add language config, I'm using english US here. Use the same as the one you uncommented above
    • echo LANG=en_US.UTF-8 > /etc/locale.conf
  • Export locale
    • export LANG=en_US.UTF-8 
  • Add permanent keyboard mapping (Swedish keyboard in this case)
    • echo KEYMAP=sv-latin1 > /etc/vconsole.conf
  • Set the HW clock to use UTC (careful with this if you are multibooting with other OS's)
    • hwclock --systohc --utc
  • Find NW-card interface, configure and start wired DHCP (again, if you are using something else, set that up), I'm using this temporarily, I'll setup static IP later on
    • Use ip link to find the name of the NW interface
    • systemctl enable dhcpcd@enp4s0.service
    • systemctl start dhcpcd@enp4s0.service
    • Replace enp4s0 with the name of your interface
  • If needed, edit mkinitcpio.conf
    • nano /etc/mkinitcpio.conf
    • HW-dependent: Add “i915” under MODULES if using compatible intel video-card
  • Generate initial RAM-disk
    • mkinitcpio -p linux
  • Install GRUB
    • pacman -S grub
    • grub-install --target=i386-pc –recheck /dev/sdx (where x is the device that root is on. DO NOT USE THE NUMBER THAT USUALLY FOLLOWS, this is installed on the device, not the partition.
  • Configure GRUB
    • If needed you can configure grub in /etc/default/grub
      • nano /etc/default/grub
      • Change GRUB_TIMEOUT to preferred value
      • HW-dependent: If using Intel Sandy Bridge  video drivers, change so that GRUB_CMDLINE_LINUX_DEFAULT="quiet i915.i915_enable_rc6=0" 
      • grub-mkconfig -o /boot/grub/grub.cfg
  • Install and enable ssh, you could do this later, but I like to do it here, so I can do the rest of the setup over ssh
    • pacman -Su openssh
    • systemctl enable sshd
  • Set root password
    • passwd
  • Change the NW setup from DHCP to static IP
    • systemctl stop dhcpcd@enp4s0.service
    • systemctl disable dhcpcd@enp4s0.service
    • cd /etc/netctl
    • cp examples/ethernet-static my_network
    • nano my_network
    • Change the values for the interface, ip-addr, gateway and DNS to ones you are using
    • I had some problem with it not working if the router wasn't on when I started the HTPC, to fix this, add the following line at the end of the file
      • SkipNoCarrier=yes
    • netctl enable my_network
  • Exit chroot
    • exit
  • Unmount root partition
    • umount /mnt
  • Reboot

Setup

  • You should be able to do the rest over ssh if you want now
  • Add multilib support if you are using 64-bit version and think you might need support for 32-bit applications
    • nano /etc/pacman.conf
    • Uncomment "Multilib" rows
  • Install additional packages (The ones marked in red are optional)
    • pacman -Syu mesa alsa-utils ntp avahi nss-mdns shairplay libplist polkit xbmc xorg-server xorg-xinit xorg-utils xorg-server-utils upower udisks
      • ntp: For synching the time with a network serve
      • avahi & nss-mdns & shairplay & libplist: For Airplay support
  • Install video drivers
    • HW-dependent: For Intel: pacman -Syu xf86-video-intel libva-intel-driver
  • HW-dependent: For intel video drivers, add config file to disable compositing
    • /etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
# Option "AccelMethod" "sna"
# Option "TearFree" "true"
EndSection
Section "Extensions"
# fixes tearing
Option "Composite" "Disable"
EndSection
  • Add config file to enable XBMC to power off and reboot
    • /etc/polkit-1/rules.d/10-xbmc.rules
polkit.addRule(function(action, subject) {
if(action.id.match("org.freedesktop.login1.") && subject.isInGroup("power")) {
return polkit.Result.YES;
}
});
  • Add user and add that user to appropriate groups(replace username with your actual username)
    • useradd -m -g users -G video,audio,storage,power,games,network,optical username
  • Set password for new user (replace username with your actual username)
    • passwd username
  • Configure and enable services
    • Optional, perform if ntpd was installed: 
      • Change the ntp servers in /etc/ntp.conf to local ones
      • systemctl enable ntpd
    • Optional, perform if avahi was installed:
      • Not sure if it is needed or not, but I added mdns4 to the end of the hosts line in /etc/nsswitvh.conf
      • systemctl enable avahi-daemon
  • You might want to configure ssh and sftp, depending on how you want the setup to work.
    • nano /etc/ssh/sshd_config
  • Setup a swap file
    • fallocate -l 2048M /swapfile
    • chmod 600 /swapfile
    • mkswap /swapfile
    • swapon /swapfile
    • Add the line below to /etc/fstab
      • /swapfile       none    swap    defaults        0 0 
  • Finally, we need to set it up so that XBMC starts automatically. This got more difficult recently, when xorg-server 1.16 was released... There are a couple of ways of doing this, I chose this one because I found it the easiest.
    •  Add a file: /etc/X11/Xwrapper.config with the following text in it
      • allowed_users = anybody
        needs_root_rights = yes
    • Manually add the xbmc user
      • useradd -m -c 'XBMC user' -G audio,video,network,optical,storage,power,games -d /var/lib/xbmc -s /usr/bin/nologin xbmc
    • Create the xbmc service file: /etc/systemd/system/xbmc.service
      • [Unit]                                                                                                      
        Description = Starts instance of XBMC using xinit
        After = systemd-user-sessions.service network.target sound.target
        Conflicts=getty@tty7.service
        [Service]   
        User=xbmc
        Group=xbmc
        PAMName=login
        Type=simple
        TTYPath=/dev/tty7
        ExecStart=/usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/bin/xbmc-standalone -- :0 -nolisten tcp vt7
        Restart=on-abort

        [Install]                                                                                                       
        WantedBy = multi-user.target
    • Enable the service
      • systemctl enable xbmc
  • Reboot and enjoy