Building HTPC

Upgrade time... Installing everything from scratch, using same hardware (AT3N7A-I from ASUSTeK) as in previous articles including update. This time Fedora18 64bit and XBMC 12 from RPMFusion will be installed.

Just to comment about: this procedure will not work on 32bit server.

Preparing NFS on server

Create LV for it:

# lvcreate -n fc18xbmc -L6g /dev/rootvg
  Logical volume "fc18xbmc" created
# mkfs.ext4 -j -m0 /dev/rootvg/fc18xbmc
....
# mkdir /fc18xbmc ; mount /dev/rootvg/fc18xbmc /fc18xbmc

Update /etc/fstab about new FS. Add line to /etc/exports

/fc18xbmc       192.168.1.68(rw,no_root_squash)

Command exportfs -a reread config file and start serve new share.

Create yum repository file:

# cat > /etc/yum.repos.d/fc18xbmc.repo << EOF
[fc18xbmc]
name=fc18xbmc
baseurl=http://mirror2.hs-esslingen.de/fedora/linux/releases/18/Fedora/x86_64/os
enabled=0
gpgcheck=0
EOF

Let's populate new FS !!

# yum --disablerepo="*" --enablerepo=fc18xbmc --installroot=/fc18xbmc install yum fedora-release

Create script to easy work within chroot environment, copy resolv.conf, and enter to chrooted environment:

# cd /fc18xbmc && cat > command_mount_chroot << EOF
mount -o bind /proc proc
mount -o bind /sys sys
mount -o bind /dev dev
chroot . /bin/bash -i
umount dev
umount sys
umount proc
EOF
# cp -v /etc/resolv.conf etc/
# sh command_mount_chroot
bash-4.2# export PS1="CHROOT# "
CHROOT#

You are in chrooted, almost empty environment. Now let's install RPM Fusion repository:

CHROOT# rpm -ihv http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-18.noarch.rpm \
	http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-18.noarch.rpm

Configure system as following:

CHROOT# echo "NETWORKING=yes" > /etc/sysconfig/network
CHROOT# cat > /etc/fstab << EOF
192.168.1.10:/fc18xbmc  /    nfs     nolock,nfsvers=3,tcp  0 0
tmpfs                   /tmp         tmpfs   mode=1777       0 0
tmpfs                   /dev/shm     tmpfs   defaults        0 0
devpts                  /dev/pts     devpts  gid=5,mode=620  0 0
sysfs                   /sys         sysfs   defaults        0 0
proc                    /proc        proc    defaults        0 0
EOF

Now install all required packages:

CHROOT# yum install -y kmod-nvidia xorg-x11-drv-nvidia vdpauinfo libvdpau twm xterm kdm xbmc nfs-utils \
	vim dracut-network passwd openssh-server syslog-ng pavucontrol pulseaudio-module-x11 \
	glx-utils xorg-x11-drv-keyboard xorg-x11-drv-mouse binutils gcc make kernel-devel \
	xorg-x11-fonts-cyrillic xorg-x11-font-utils xorg-x11-fonts-Type1 xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi \
	xorg-x11-xdm xorg-x11-drv-evdev lsof strings ntp dhclient autofs alsa-utils

Configure new system:

CHROOT# rm -f /etc/systemd/system/default.target
CHROOT# ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
CHROOT# cat > /etc/syslog-ng/syslog-ng.conf << EOF
@version:3.3
source s_sys {
    file ("/proc/kmsg" program_override("kernel") flags(kernel));
    unix-dgram ("/dev/log");
    internal();
};
destination d_loghost { udp("192.168.200.50" port(514)); };
log { source(s_sys); destination(d_loghost); };
EOF
CHROOT# ln -s /lib/systemd/system/sshd.service /etc/systemd/system/
CHROOT# ln -s /lib/systemd/system/syslog-ng.service /etc/systemd/system/
CHROOT# password

Prepare dracut configuration file and rebuild initrd file:

CHROOT# cat > /etc/dracut.conf.d/NFS_root.conf << EOF
logfile=/var/log/dracut.log
fileloglvl=6
dracutmodules+="nfs network base"
omit_dracutmodules+="xen btrfs dm dmraid dmsquash-live lvm mdraid multipath"
add_dracutmodules+="network nfs"
add_drivers+="r8169"
mdadmconf="no"
lvmconf="no"
EOF
CHROOT# cd /boot && dracut -f initramfs-3.8.4-202.fc18.x86_64.img 3.8.4-202.fc18.x86_64
CHROOT# exit
#

Copy kernel and initrd files to /tftpboot directory:

# cp /fc18xbmc/boot/vmlinuz-3.8.4-202.fc18.x86_64 /tftpboot/fc18xbmc.krl
# cp /fc18xbmc/boot/initramfs-3.8.4-202.fc18.x86_64.img /tftpboot/fc18xbmc.ird

Create PXE boot file and link it to correct MAC address:

# cat > /tftpboot/pxelinux.cfg/fc18xbmc << EOF
DEFAULT fc18xbmc
PROMPT 0
TIMEOUT 0

LABEL fc18xbmc
  KERNEL fc18xbmc.krl
  APPEND initrd=fc18xbmc.ird root=nfs:192.168.1.10:/fc18xbmc:nolock,tcp,nfsvers=3 rd.shell rd.ip=auto rd.debug vmalloc=192MB
  IPAPPEND 2
EOF
# ln -s fc18xbmc /tftpboot/pxelinux.cfg/01-90-e6-ba-cc-b7-2e

Boot HTPC. Probably you can login via SSH, and saw syslog messages on "loghost". If not, try fix things in NFS server and restart HTPC. Log in to HTPC, either local, or by SSH.

Configuring Video

Default xorg configuration work but do not give "native" resolution on HDMI TV. This file is suits fo my hardware and my so called "HDMI ready" (720p) TV.

# cat > /etc/X11/xorg.conf << EOF
Section "ServerLayout"
        Identifier "Default Layout"
        Screen 0 "Screen0" 0 0
        InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "ServerFlags"
        Option "AIGLX" "on"
EndSection

Section "InputDevice"
        Identifier "Keyboard0"
        Driver "kbd"
        Option "XkbModel" "pc105"
        Option "XkbLayout" "us+inet"
EndSection

Section "Device"
        Identifier "Videocard0"
        Driver "nvidia"
        Option "AddARGBGLXVisuals" "True"
        Option "UseEDIDFreqs" "False"
        Option "ModeValidation" "NoWidthAlignmentCheck, NoDFPNativeResolutionCheck"
        Option "UseEvents" "True"
        Option "UseEdidDpi" "FALSE"
        Option "ExactModeTimingsDVI" "TRUE"
EndSection

Section "Monitor"
        Identifier "Vizio37"
        HorizSync 31.0 - 70.0
        VertRefresh 50.0 - 85.0
        Modeline "1368x768_60.00" 85.9 1368 1440 1584 1800 768 769 772 795 -hsync +vsync
        # Option "DPMS"
        Option "ModeValidation" "NoDFPNativeResolutionCheck"
EndSection

Section "Screen"
        Identifier "Screen0"
        Device "Videocard0"
        Monitor "Vizio37"
        Option "UseEdidDpi" "FALSE"
        Option "DPI" "100 x 100"
        #Option "TVStandard" "HD1080i"
        Option "NoLogo" "1"
        Option "TVStandard" "HD720p"
        Option "TVOverScan" ".7"
        Option "ConnectedMonitor" "DFP"
        Option "ExactModeTimingsDVI" "True"
        DefaultDepth 24
        SubSection "Display"
                Viewport 0 0
                Depth 24
                Modes "1368x768_60.00"
        EndSubSection
EndSection

Section "Extensions"
        Option "Composite" "Enable"
EndSection
EOF

Try startx, check /var/log/Xorg.0.log. Set gray background by command xsetroot -gray. Verify that resolution is native. The background should be gray without waves.

Setting Audio

First of all unmute everything by alsamixer -c0. In my case HDMI output named S/PDIF 1. Save the state as system default by alsactl store command.

Command pulseaudio -C starts interactive session to examine current settings and set desired parameters. When started, you can ask for help about commands. Usefull command is list-cards which list your hardware and it's state. Here is an output form my hardware, most relevant info bolded by me:

-bash-4.2# pulseaudio -C
W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).
W: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.Spawn.ExecFailed:
 /bin/dbus-launch terminated abnormally without any error message
W: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.Spawn.ExecFailed: /bin/dbus-launch
 terminated abnormally without any error message
Welcome to PulseAudio! Use "help" for usage information.
>>> list-cards
1 card(s) available.
    index: 0
        name: <alsa_card.pci-0000_00_08.0>
        driver: <module-alsa-card.c>
        owner module: 4
        properties:
                alsa.card = "0"
                alsa.card_name = "HDA NVidia"
                alsa.long_card_name = "HDA NVidia at 0xf9f78000 irq 23"
                alsa.driver_name = "snd_hda_intel"
                device.bus_path = "pci-0000:00:08.0"
                sysfs.path = "/devices/pci0000:00/0000:00:08.0/sound/card0"
                device.bus = "pci"
                device.vendor.id = "10de"
                device.vendor.name = "NVIDIA Corporation"
                device.product.id = "0ac0"
                device.form_factor = "internal"
                device.string = "0"
                device.description = "Built-in Audio"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        profiles:
                output:analog-stereo: Analog Stereo Output (priority 6000)
                output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6060)
                output:analog-surround-40: Analog Surround 4.0 Output (priority 700)
                output:analog-surround-40+input:analog-stereo: Analog Surround 4.0 Output + Analog Stereo Input (priority 760)
                output:analog-surround-41: Analog Surround 4.1 Output (priority 800)
                output:analog-surround-41+input:analog-stereo: Analog Surround 4.1 Output + Analog Stereo Input (priority 860)
                output:analog-surround-50: Analog Surround 5.0 Output (priority 700)
                output:analog-surround-50+input:analog-stereo: Analog Surround 5.0 Output + Analog Stereo Input (priority 760)
                output:analog-surround-51: Analog Surround 5.1 Output (priority 800)
                output:analog-surround-51+input:analog-stereo: Analog Surround 5.1 Output + Analog Stereo Input (priority 860)
                output:analog-surround-71: Analog Surround 7.1 Output (priority 700)
                output:analog-surround-71+input:analog-stereo: Analog Surround 7.1 Output + Analog Stereo Input (priority 760)
                output:iec958-stereo: Digital Stereo (IEC958) Output (priority 5500)
                output:iec958-stereo+input:analog-stereo: Digital Stereo (IEC958) Output + Analog Stereo Input (priority 5560)
                output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5400)
                output:hdmi-stereo+input:analog-stereo: Digital Stereo (HDMI) Output + Analog Stereo Input (priority 5460)
                output:hdmi-surround: Digital Surround 5.1 (HDMI) Output (priority 300)
                output:hdmi-surround+input:analog-stereo: Digital Surround 5.1 (HDMI) Output + Analog Stereo Input (priority 360)
                input:analog-stereo: Analog Stereo Input (priority 60)
                off: Off (priority 0)
        active profile: <output:analog-stereo+input:analog-stereo>
        sinks:
                alsa_output.pci-0000_00_08.0.analog-stereo/#0: Built-in Audio Analog Stereo
        sources:
                alsa_output.pci-0000_00_08.0.analog-stereo.monitor/#0: Monitor of Built-in Audio Analog Stereo
                alsa_input.pci-0000_00_08.0.analog-stereo/#1: Built-in Audio Analog Stereo
        ports:
                analog-output: Analog Output (priority 9900, available: unknown)
                        properties:

                analog-output-headphones: Headphones (priority 9000, available: no)
                        properties:

                analog-input-microphone-front: Front Microphone (priority 8500, available: no)
                        properties:

                analog-input-microphone-rear: Rear Microphone (priority 8200, available: no)
                        properties:

                analog-input-linein: Line In (priority 8100, available: no)
                        properties:

                iec958-stereo-output: Digital Output (S/PDIF) (priority 0, available: unknown)
                        properties:

                hdmi-output-0: HDMI / DisplayPort (priority 5900, available: unknown)
                        properties:

>>> set-card-profile 0 output:hdmi-stereo
>>> list-cards
....
        active profile: <output:hdmi-stereo>
....

Once desired command detected, put it system wide and startup default:

-bash-4.2# echo "set-card-profile 0 output:hdmi-stereo" >> /etc/pulse/default.pa

Setting XBMC

Set up XBMC user and autostart programm.

# groupadd -g 507 xbmc
# useradd -u 507 -g xbmc -G audio,video,pulse-access,pulse xbmc
# password xbmc
Configure HTPS boot to graphic mode:
# rm -f /etc/systemd/system/default.target && ln -s /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Restart HTPC, at graphic login enter user "xbmc", password for it and select XBMC session type (by mouse).

Now fix autologin to xbmc user on system start. Edit file /etc/kde/kdm/kdmrc:

....
# Core config for 1st local display
[X-:0-Core]
# Enable automatic login. USE WITH EXTREME CARE! Default is false
AutoLoginEnable=true
# The user to log in automatically. NEVER specify root! Default is ""
AutoLoginUser=xbmc
# The password for the user to log in automatically. This is NOT required
# unless the user is logged into a NIS or Kerberos domain. If you use this
# option, you should "chmod 600 kdmrc" for obvious reasons.
# Default is ""
#AutoLoginPass=secret!
....

Misc settings

My HTPC mounts it's media sources via automount. Edit /etc/sysconfig/autofs file to use NFSv3 instead of NFSv4. Enable autofs service by:

# systemctl enable autofs.service
# systemctl start autofs.service

Remote control

Download Official XBMC Remote - Android Apps on Google Play. Now your android phone is xbmc remote control.
If this was helpfull, please donate
Updated on Thu Jun 6 13:38:36 IDT 2013 by Oleg Volkov More documentations here