Diskless boot mythtv

Forum regarding Linux Software and Home Automation Domotica.
Post Reply
luria
Starting Member
Starting Member
Posts: 36
Joined: Tue Mar 16, 2010 11:51 am

Diskless boot mythtv

Post by luria »

drmacchi wrote:luria please, could you explain how to set an ion device to reproduce video HD from a Mythtv server ? I can not image how to play a hd movie without OS and player.
Could you give the list of what is necessary (sw i mean)
Your setup is really interesting !
Thanks a lot.
I use ubuntu. On my server i have a gui-less ubuntu lamp server installation which I administer through ssh or X-forwarding when i need a gui. (eg: ssh -X root@myserverip). All clients run the latest ubuntu. In order to get vdpau up and running you need to install a recent nvidia driver and the vdpau library package from synaptic. You should probably be satisfied with the current mythbuntu release, it incorporates VDPAU and the installation/configuration is clear and concise.

I, however, need to compile my own since i have several patches that fix some things I regard as issues (norwegian letters in subtitling being one of them).
I have a ugly bash-script (i'm no programmer) that automagically downloads, compiles and installs mythtv for me. You can select which version (bleeding edge trunk, stable fixes or any version number from the timeline, and if you want a client or server install. Unfortunately it is partly in norwegian, but it should be easily readable. A simple

Code: Select all

apt-get  build-dep mythbuntu
should fetch all packages you need for rolling your own mythtv this way.

Code: Select all

#!/bin/bash

function lastned {
echo "Henter $1"
while ! ( eval "svn $download/$1 2>nedlastingsfeil.txt" )
do
if [ "$unatt" == "no" ]
then
  read -s -n1 -p "nedlasting av $1 feilet: nytt forsoek (y/n)" keypress
  if [ "$keypress" == "n" ]; then exit 1; fi
  echo "(y) Proever paa nytt"
else
echo "Feilet! svn $download/$1"
exit 1
fi  
done

if [ -e "nedlastingsfeil.txt" ]
 then
 rm "nedlastingsfeil.txt"
fi
}

function kompiler {
cd ~/$1__*
echo "Kompilerer $1" `date +%H:%M`
if [ -e "~/$1_gammel/kompileringstid" ]
 then 
 cat  ~/$1_gammel/kompileringstid
fi
SECONDS=0
if ! ( eval "make -j3 -s 1>/dev/null 2>make_errors.txt" )
  then
    echo "$1 kompileringsfeil"
    tail make_errors.txt
    exit 1
  else
    echo "$1 kompilert."
    tid=`echo $(((SECONDS/60)/60)) timer $((SECONDS/60)) minutter $((SECONDS%60)) sekunder`
    echo "$tid" >>kompileringstid
    touch "Kompileringstid $tid"

fi
}

function avinstaller {
cd ~
if [ -d myth_gammel ]
then
  cd myth_gammel/$1__*
  if [ -f "$1 installert!" ]
  then
    echo
    echo  "Avinstallerer $1"
      if ! ( eval "make uninstall 1>/dev/null  2>uninstall_error.txt" )
        then 
          echo "Avinstallering av $1 feilet"
        else
          echo "Avinstallerte $1."
      fi
   else
   echo "Ingen fil funnet i $1 katalogen."
  fi
fi
}

function installer {
cd ~
cd $1__*
   if ! ( eval "make install 1>/dev/null 2>install_error.txt" )
     then
     echo "Installering feilet!"
     tail install_error.txt
     exit 1
   else
    echo "$1 installert." 
    touch "$1 installert!"
   fi
}
type="frontend"
versjon="fixes"
unatt="yes"
stopp="installer"

usage () {
    echo "
Usage: `basename` [-b]  [-t]  [-p] [-h patch:kompiler] [-s version]
-b                (b)ackend [default frontend/klient]
-t                Latest (t)runk-versjon [default stable fixes version] 
-p                (p)rompt or [use defaults]
-h patch|kompiler Only patch|only compile [default install everything]
"
}

[ "$#" -lt 1 ] && usage && exit -1


while getopts "btph:s:" Option; do
    case "$Option" in
        b) type="backend" ;;
        t) versjon="trunk" ;;
        p) unatt="no" ;;
        h) stopp="$OPTARG" ;;
        s) versjon="$OPTARG" ;;
        *) usage; exit -1 ;;
    esac
done

shift $(( $OPTIND - 1 ))

cd "$HOME"
temp=$(ls -d mythtv__*)
gmlversjon=${temp: (-5)}
echo "Siste installerte versjon er :" $gmlversjon
siste=$(svn info -r head http://svn.mythtv.org/svn/trunk/ |grep Revis)
sistver=${siste: -5}

echo "Latest trunk version is:" $sistver

case "$type" in
  backend)
echo -n "./configure --enable-proc-opt     \
--enable-audio-alsa   \
--disable-joystick-menu \
--disable-audio-jack  \
--disable-directfb    \
--disable-lirc         \
--enable-v4l          \
--enable-ivtv         \
--disable-firewire    \
--enable-dvb          \
--dvb-path=/usr/src/linux-headers-`uname -r`/include \
--disable-opengl-video \
--disable-xvmc         \
--disable-hdhomerun    \
--disable-x11          \
--disable-hdpvr        \
--disable-opengl-vsync \
--disable-iptv" > mythtv.conf
chmod 777 mythtv.conf
        ;;
  frontend)
     echo -n "./configure --enable-proc-opt     \
--enable-audio-alsa   \
--disable-audio-jack  \
--disable-directfb    \
--enable-lirc         \
--enable-v4l          \
--disable-ivtv         \
--disable-firewire    \
--disable-dvb          \
--enable-opengl-video  \
--disable-xvmc         \
--disable-hdhomerun    \
--disable-xvmc-vld     \
--disable-xvmc-pro     \
--enable-opengl-vsync \
--disable-iptv   " > mythtv.conf
if grep -i -q "nvidia" "/etc/X11/xorg.conf"
then 
echo "--enable-vdpau" >> mythtv.conf
fi
chmod 777 mythtv.conf
        ;;
  *)
        N=$NAME
	echo "Bruk: $N {-backend|-frontend} [svn version] [-patch|-install]" >&2
        exit 1
        ;;
esac

if [ "$versjon" == "trunk" ]
then 
download="co http://svn.mythtv.org/svn/trunk/"
else
  if [ "$versjon" == "fixes" ]
      then 
      download="co http://svn.mythtv.org/svn/branches/release-0-23-fixes/"
    else
      download="co -r $versjon http://svn.mythtv.org/svn/trunk/"
  fi
fi 

echo "Velger $versjon"

patchdir="patcher"
if [ "$unatt" == "no" ]
then
 read -s -n1 -p "oppdater.sh $1 $versjon $inst  OK? (y/n)" keypress
    if [ "$keypress" == "n" ]
     then 
     exit 1
    fi 
   svar="patcher"
   echo
   echo -n "Which subdirectory contains patches? [$svar]"
   read patchdir
      if [ -z "$patchdir" ]
        then
        patchdir=$svar
      fi
 echo $patchdir
fi

if [ -d myth_gammel ]  # Remove, if exists.
then
  echo
  echo -n "Remove old"
  rm -R myth_gammel
fi

##Foerste gang kjoeres
if [ -d mythtv__* ]
  then
  echo
  echo -n "Make newfolder for myth_gammel"
  mkdir myth_gammel/
  mv  mythtv__* myth_gammel/
  mv  mythplugins__* myth_gammel
  mv  myththemes__* myth_gammel/
fi

########Last ned
echo
echo "Downloading $versjon"
lastned mythtv
lastned mythplugins
lastned myththemes
#####Rydd opp
echo
echo "Downloaded $versjon"
mv mythtv mythtv__$versjon
mv mythplugins mythplugins__$versjon
mv myththemes myththemes__$versjon


####Legg inn konf-filer
cd ~
mv mythtv.conf ~/mythtv__*/
cd mythtv__*
./mythtv.conf > current.config
cd ~
cd mythplugins__*
echo "./configure  \
--disable-mythflix \
--disable-mythmovie " > mythtv.conf
chmod 777 mythtv.conf
./mythtv.conf > current.config
cd ~
cd myththemes__*
./configure
cd ~

echo
echo -n "Moving configuration files"

####Patch mythtv
if [ -n "$patchdir" ]
then
    for file in $patchdir/*
    do
      if [ -e "$file" ]
      then 
        cd mythtv__*  
        echo  
        echo -n "Patcher myth med $file"   
        patch -p3 < "../$file" >> patchlogg.txt 
        cd ..
      else
        echo "No (more) files in $patchdir"
      fi
    done
    cd ~/mythtv__*
    if [ -e "patchlogg.txt" ]
    then
      if grep -i -q "FAILED" "patchlogg.txt"
      then   	
        read -s -n1 -p "Patching failed!  Continue (y/n) ? " keypress
          if [ "$keypress" == "n" ]
           then
           exit 1
          fi
       fi
     fi
else
  echo 
  echo "No patching."
fi
echo
if [ "$stopp" == "patch" ]
then
exit 0
fi

kompiler mythtv


if [ "$stopp" != "installer" ]
then
exit 1
fi

###Stopp mythbackend/frontend
if ps -C mythbackend > /dev/null
then
  echo
  echo "Stopper mythbackend"
  /etc/init.d/mythtv-backend stop
fi
if ps -C mythfrontend > /dev/null
then
  echo
  echo "Stopper mythfrontend"
  killall mythfrontend.start
  killall mythfrontend
fi

###Avinstaller gammel
avinstaller mythtv
avinstaller mythplugins
avinstaller myththemes

####Installer ny
installer mythtv


#Bare hvis frontend
kompiler mythplugins
installer mythplugins
installer myththemes

if [ "$1" == "backend" ]
then

  ### Fikse mythweb for backend
  cd /var/www/
  rm mythweb
  ln -s ~/mythplugins__*/mythweb mythweb
  chown -R www-data mythweb/data
  chmod -R 775 mythweb
  cd ~ 
fi
cd mythtv__*
tid=`echo $(((SECONDS/60)/60)) timer $((SECONDS/60)) minutter $((SECONDS%60)) sekunder`
echo "Brukte $tid"
touch "Kompileringstid $tid"
cd ~

if [ "$type" == "backend" ] 
then 
/etc/init.d/mythtv-backend start
exit 0
fi
if [ "$type" == "frontend" ] 
then
#ln -s /mnt/extras/.mythtv/mainmenu.xml ~/.mythtv/mainmenu.xml
#ln -s /mnt/extras/.mythtv/annet.xml ~/.mythtv/annet.xml
reboot
fi
exit 0

I used the follwing howto in order to get diskless clients running (org: http://dvbn.happysat.org/viewtopic.php? ... kless+boot ). There may be minor changes, I did this a couple of years ago. The howto is pretty self-explanatory and should get you trough anyway, most other howtos regarding this subject are dead ends or unclear.
A note: As you can see, this installs a common image for all clients. However, using several images for different hardware setups is easy. Just copy your original image to a new location within the nfs mount, make a new tftboot subdirectory, copy the files and change the /tftpboot/pxelinux.cfg/default to point to the new nfs location. Finally set your dhcp server to distribute this directory to the other frontend based on it's mac-address. Remember that you can chroot into these images form the server and do maintenance, updates and so on without even powering on the clients. This makes it easy to keep everything WAF-compliant.

MythTV multiple diskless frontends HOWTO


1) First step is to get your backend and at least 1 frontend setup and configured.
There are so many guides with how to do this i can not go into the details in this howto.

2) On the Backend you will need to install some software packages.

Code: Select all

dhcp3-server tftpd-hpa syslinux nfs-kernel-server initramfs-tools
You should be able to apt-get those packages on most debian based systems or for
other distros use your tool of choice.

Let also make some direcotry's we will need

Code: Select all

mkdir -p /tftpboot/pxelinux.cfg
mkdir /nfsroot
cp /usr/lib/syslinux/pxelinux.0 /tftpboot
3)You will need a dhcpd server. If you allready have one on a linux box you can modify
you can use it or we can install dhcpd here on the backend.

4)You need to add two things to the top of your dhcpd.conf once you have it set up for your
liking.

Code: Select all

allow booting;
allow bootp;
These tell your DHCPD that you are allowing diskless clients.
One more change is at the end of your subnet declaration you should add...

Code: Select all

filename "/pxelinux.0";

If your dhcpd is not on the same system as your backend you will need to add...

Code: Select all

next-server xx.xx.xx.xx;

Add this before the filename "/pxelinux.0"; entry, and replace the xx with your backend IP

Your dhcpd.conf should look something like this.

Code: Select all

allow booting;
allow bootp;

subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.xxx 192.168.2.xxx;
  option broadcast-address 192.168.2.255;
  option routers 192.168.2.xxx;
  option domain-name-servers 192.168.2.xxx;
  next-server xx.xx.xx.xx;
  filename "/pxelinux.0";
}

5) You now need to install and configure a tftp server on you backend.

You will need to edit etc/default/tftp-hpa and make it look like this

Code: Select all

#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /tftpboot"

now, start the tftp-hpa service:

Code: Select all

/etc/init.d/tftp-hpa start
Now create a new config file as /tftpboot/pxelinux.cfg/default

Code: Select all

LABEL linux
KERNEL vmlinuz-2.6.15-23-686
APPEND root=/dev/nfs initrd=initrd.img-2.6.15-23-686 nfsroot=192.168.2.2:/nfsroot ip=dhcp rw
Be sure to repace the initrd name and kernel name with the exact ones you are using in /boot
of your frontend machine.

6) Getting NFS setup

Modify /etc/exports on your backend and add...

Code: Select all

/nfsroot             192.168.2.1/24(rw,no_root_squash,async)

Be sure to repace the IP with the IP address range of your frontend, ie if your frontend will get 192.168.2.x put 192.168.2.1/24 that way all addresses in that subnet will be allowed.
Note we are mounting READ and WRITE, this is just initially to get things squared away. Once
you are happy with your setup you can change that back to ro,

Now issue exportfs -rv, that will update your NFS configuration.

7) Now we need to get an image of your working fronend to NFSROOT

You will issue these commands on the frontend and they will copy your installation to the
NFS server.

Code: Select all


mount -tnfs -onolock 192.168.1.x:/nfsroot /mnt
cp -ax /. /mnt/.
cp -ax /dev/. /mnt/dev/.
Replace the IP address in the mount command with the IP of your backend.
THis WILL TAKE A WHILE as it is copying your complete image install to the NFSROOT.

8) You need to make a new initrd as the one you are using probably wond work on a net boot.
This is real simple on the frontend issue...

Code:
mkinitramfs -o /root/initrd.img-2.6.20-16-generic


Of course change the name of the initrd file to match your existing one exactly.
This will drop the new one in roots home dir.

9) Now we will make a few modifications to your NFSROOT image to make it happy with net
booting.

On the backend edit /nfsroot/etc/initramfs-tools/initramfs.conf

Change to BOOT= flag to read BOOT=nfs

Now you do not want the system to bring up your network interfaces cause they are allrady up!

So edit /nfsroot/etc/network/interfaces and make it look like this...

Code: Select all


# The primary network interface, commented out for NFS root
#auto eth0
#iface eth0 inet dhcp
iface eth0 inet manual

Now one last edit is /nfsroot/etc/fstab you need to make it mount / on NFS and change the
other default mounts to use tempfs. It should look something like this.

Code: Select all

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/nfs       /               nfs    defaults          1       1
none            /tmp            tmpfs   defaults        0       0
none            /var/run        tmpfs   defaults        0       0
none            /var/lock       tmpfs   defaults        0       0
none            /var/tmp        tmpfs   defaults        0       0
/dev/hdc        /media/cdrom0   udf,iso9660 user,noauto 0       0
If you mount other things you can leave them as is.

10) Copy your kernel and initrd to your tftp server

Now copy the kernel from /boot on your frontend to /tftpboot on the backend.
Also copy your modified initrd from /root on your frontend to /tftpboot on your backend.

11) Thats it. Be sure your NFS/DHCPD/TFTP are running and reboot your frontend with PXE boot
from LAN. It should grab an IP and then your kernel from TFTP, then start booting your system
from NFS.

12) Now that things are working we need to make a small edit to the /nfsroot to make the front
end assign itself a dynamic hostname based on its MAC so that you can boot multiple frontends
and they each get their own configs in then DB.

Make a file in /etc/init.d/ called 00hosthack

Code: Select all


#!/bin/bash
IPADDR=`/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{ print $2 } ' | awk '{ print $1 }'`
FQHOST=`/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{ print $2 } ' | awk '{ print $1 }'`
HOST=`host 169.237.30.111 | awk '{print $5}'`
echo [zj01] IP ADDRESS: $IPADDR FULLY QUALIFIED HOSTNAME: $FQHOST HOSTNAME: $HOST
echo $FQHOST > /proc/sys/kernel/hostname

Then chmod +x this file so it can execute.
This will make the machine change its hostname to its IP address during boot. This will make the backend
see each frontend as a differnt one and save all settings accordingly.

13) The way things are now, once booted you can ssh to your frontend and make any changes you want or
install new software. Once you get things exactly as you like change your exports file on the backend to make
the nfsroot READ ONLY by chaging rw to ro.


Good luck!
drmacchi
Advanced Member
Advanced Member
Posts: 827
Joined: Wed Aug 08, 2007 5:48 pm
Location: Italy

Re: Diskless boot mythtv

Post by drmacchi »

OH OH, my compliments for your performance ! but it's too difficult for me :)
Post Reply

Return to “Linux Forum”