Tuesday, July 24, 2012

Linux Howto: Clone your active system to get a N-1 OS version available in case of update troubles or instability




If you are in the same situation as i am, your Linux XBMC Box became the Multimedia center for all the family, let's say it's now in "production" and as any client would, they won't accept any downtime due to system or application upgrade issue :-)

There is off course several solutions you may use to backup and restore your system if required, in my opinion the easiest is to have a secondary N-1 version system available and ready to run in case the last update you absolutely had to applied (because you're such a geek you cannot keep running an outdated system ^^) broke your nice and stable installation!

Naturally, this will be applicable for any Linux installation.


************************ CAUTION ***************************************************************

These operations may easily break your system if you don't pay attention, 
please follow this Howto with many cautions and very carefully!


*************************************************************************************************


Methods and requirements:


I recommend the following method using "partclone" to clone your system.

First and in any case, ensure you have a secondary partition with a size strictly identical to your base system. (obligatory for partclone)

This secondary partition will be uased by our cloned system.

Also, i would recommend you install "/home"' under a dedicated third partition.

So, let's say as an example you installation is partitioned that way (all formatted in ext4) :

  • "/dev/sda1" is your main OS installation
  • "/dev/sda2" will be your N-1 OS version
  • "/dev/sda3" is your "/home" partition

Note: With partclone, your 2 system partitions must have strictly the same size, use Gparted when you are in your Live OS to modify your partitions as required, you resize, create move and so on.
But be careful, you can easily break everything if you don't pay attention ^^


Clone your system with partclone


Limitations and constraints:

You can't clone a partition being used and mounted, so the easiest method is to use a USB Live Distribution you will use to boot and clone your system.

This is very easy, just download any Linux distribution (i recommend Xubuntu) and use "Unetbootin" to create the Live USB key.

Also, ensure your live system will be able to access to Internet as you will need to install some packages.

Step 1: Boot to Live OS


Insert your Live USB Key and boot the system, when the system is ready install some requirements:
sudo apt-get install partclone
Notes: Ensure you are connected to Internet before the apt-get, no need to update first but you also can do it if you want


Step 2: Clone the system


Recommended:

I recommend to first backup the partition to an external image you may need later and after that restoring it to the secondary partition:

First check and correct the filesystem if required:
sudo fsck.ext4 -yf /dev/sda1

Clone sda1 to an external image:
sudo partclone.ext4 -c -d -s /dev/sda1 -o <MY DESTINATION FOLDER>/sda1_partclone_ext4_MMDDYYYY.img

Restore sda1 image to sda2 partition:
sudo partclone.ext4 -r -d -s <MY DESTINATION FOLDER>/sda1_partclone_ext4_MMDDYYYY.img -o /dev/sda2

Step 3: Update secondary partition UUID and Label



This a very important operation, i you don't update the secondary partition UUID, it will have the same than your first OS and you can be sure you're going into big troubles!

Install requirements:
sudo apt-get install uuid e2label

List actual UUID, sda1 and sda2 have the same UUID and same label which is really is bad thing:

sudo blkid
Note: You can also use the command "sudo tune2fs -l /dev/sda1 | grep UUID"

Output example before update:
/dev/sda1: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"                                                          
/dev/sda2: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"

Update "/dev/sda2" UUID:
sudo tune2fs -U `uuid` /dev/sda2

Update "/dev/sda2" Label:
sudo e2label /dev/sda2 SYSTEM2

Check and note the new configuration:
sudo blkid
/dev/sda1: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"                                                          
/dev/sda2: LABEL="SYSTEM2" UUID="8e1e225a-d51e-11e1-b5aa-00012e409020" TYPE="ext4"

Everything is fine, we have different UUID and Labels for both partitions, let's mount the secondary partition and update "/etc/fstab" with this new information:

Mount the partition:
sudo mkdir /mnt/sda2 && sudo mount -t ext4 /dev/sda2 /mnt/sda2

Edit "/mnt/sda2/etc/fstab" and replace initial UUID by the new one, in this example we replace:
UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 /               ext4    errors=remount-ro,noatime 0       1                                       

By:
UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 /               ext4    errors=remount-ro,noatime 0       1                                       

Save and umount the partition:
sudo umount /dev/sda2 && sudo rm -rf /mnt/sda2


Step 4: Reboot to main system and update grub


Notes: Os prober from Grub should be able to generate a functional boot configuration finding our cloned system in "/dev/sda2", for an unknown reason this doesn't work so i recommend a manual operation which will be more reliable.


Leave the Live USB system and reboot to the main system, then open "/boot/grub/grub.cfg" and copy main system boot lines to clipboard or a temporary text editor, in our example we will find the original kernel lines:
menuentry 'Ubuntu, avec Linux 3.2.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os {                                   
recordfail
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root affe0f48-6b88-43a5-b131-20a58cd776b8
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 ro quiet splash $vt_handoff
initrd /boot/initrd.img-3.2.0-26-generic
}
menuentry 'Ubuntu, avec Linux 3.2.0-26-generic (mode de dépannage)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root affe0f48-6b88-43a5-b131-20a58cd776b8
echo 'Chargement de Linux 3.2.0-26-generic ...'
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 ro recovery nomodeset
echo 'Chargement du disque mémoire initial ...'
initrd /boot/initrd.img-3.2.0-26-generic
}


Add "(on /dev/sda2) behind the kernel version in "menuentry" and replace "msdos1" by "msdos2" and the old UUID by the new one and put these lines into "/etc/grub.d/40_custom", in our example our new lines will be:
menuentry "Ubuntu, avec Linux 3.2.0-26-generic (on /dev/sda2)" --class gnu-linux --class gnu --class os {                                   
recordfail
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set=root 8e1e225a-d51e-11e1-b5aa-00012e409020
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 ro quiet splash $vt_handoff
initrd /boot/initrd.img-3.2.0-26-generic
}
menuentry "Ubuntu, avec Linux 3.2.0-26-generic (mode de dépannage) (on /dev/sda2)" --class gnu-linux --class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set=root 8e1e225a-d51e-11e1-b5aa-00012e409020
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 ro recovery nomodeset
initrd /boot/initrd.img-3.2.0-26-generic
}

Update grub:
sudo update-grub 


Reboot from your main system and test booting to the secondary OS, it should boot with no problem and you will get exactly the same system than the main one.

You can test whatever you need in the secondary system such as important system and application upgrade without the risk of breaking down your main system.

Therefore, don't forget that if you have a third partition for "/home", any issue not related to the system partition but related to the home partition (such as deleting user's files) will off course exist in both systems!

So a best practice will always be to also backup the /home partition ^^

As now you have 2 systems available, if you want to update the secondary system, you don't have to boot again with a Live OS:

  • Boot to secondary system
  • Create the partclone image from primary system to an external image
  • Boot to primary system
  • Restore the external image to secondary partition
  • Re do UUID change and fstab correction


Step 5: Optional - Home Directory


If you want to be completely independent of your first installation, you may also copy your initial main user home directory, example to "/home/user_system2".

Then just ensure to change the home directory in your second system by editing "/etc/passwd". (remember to adapt from where you edit it)





Feel free to comment :-)







Linux Howto: Clone your active system to get a N-1 OS version available in case of update troubles or instability




If you are in the same situation as i am, your Linux XBMC Box became the Multimedia center for all the family, let's say it's now in "production" and as any client would, they won't accept any downtime due to system or application upgrade issue :-)

There is off course several solutions you may use to backup and restore your system if required, in my opinion the easiest is to have a secondary N-1 version system available and ready to run in case the last update you absolutely had to applied (because you're such a geek you cannot keep running an outdated system ^^) broke your nice and stable installation!

Naturally, this will be applicable for any Linux installation.


************************ CAUTION ***************************************************************

These operations may easily break your system if you don't pay attention, 
please follow this Howto with many cautions and very carefully!


*************************************************************************************************


Methods and requirements:


I recommend the following method using "partclone" to clone your system.

First and in any case, ensure you have a secondary partition with a size strictly identical to your base system. (obligatory for partclone)

This secondary partition will be uased by our cloned system.

Also, i would recommend you install "/home"' under a dedicated third partition.

So, let's say as an example you installation is partitioned that way (all formatted in ext4) :

  • "/dev/sda1" is your main OS installation
  • "/dev/sda2" will be your N-1 OS version
  • "/dev/sda3" is your "/home" partition

Note: With partclone, your 2 system partitions must have strictly the same size, use Gparted when you are in your Live OS to modify your partitions as required, you resize, create move and so on.
But be careful, you can easily break everything if you don't pay attention ^^


Clone your system with partclone


Limitations and constraints:

You can't clone a partition being used and mounted, so the easiest method is to use a USB Live Distribution you will use to boot and clone your system.

This is very easy, just download any Linux distribution (i recommend Xubuntu) and use "Unetbootin" to create the Live USB key.

Also, ensure your live system will be able to access to Internet as you will need to install some packages.

Step 1: Boot to Live OS


Insert your Live USB Key and boot the system, when the system is ready install some requirements:
sudo apt-get install partclone
Notes: Ensure you are connected to Internet before the apt-get, no need to update first but you also can do it if you want


Step 2: Clone the system


Recommended:

I recommend to first backup the partition to an external image you may need later and after that restoring it to the secondary partition:

First check and correct the filesystem if required:
sudo fsck.ext4 -yf /dev/sda1

Clone sda1 to an external image:
sudo partclone.ext4 -c -d -s /dev/sda1 -o <MY DESTINATION FOLDER>/sda1_partclone_ext4_MMDDYYYY.img

Restore sda1 image to sda2 partition:
sudo partclone.ext4 -r -d -s <MY DESTINATION FOLDER>/sda1_partclone_ext4_MMDDYYYY.img -o /dev/sda2

Step 3: Update secondary partition UUID and Label



This a very important operation, i you don't update the secondary partition UUID, it will have the same than your first OS and you can be sure you're going into big troubles!

Install requirements:
sudo apt-get install uuid e2label

List actual UUID, sda1 and sda2 have the same UUID and same label which is really is bad thing:

sudo blkid
Note: You can also use the command "sudo tune2fs -l /dev/sda1 | grep UUID"

Output example before update:
/dev/sda1: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"                                                          
/dev/sda2: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"

Update "/dev/sda2" UUID:
sudo tune2fs -U `uuid` /dev/sda2

Update "/dev/sda2" Label:
sudo e2label /dev/sda2 SYSTEM2

Check and note the new configuration:
sudo blkid
/dev/sda1: LABEL="SYSTEM1" UUID="affe0f48-6b88-43a5-b131-20a58cd776b8" TYPE="ext4"                                                          
/dev/sda2: LABEL="SYSTEM2" UUID="8e1e225a-d51e-11e1-b5aa-00012e409020" TYPE="ext4"

Everything is fine, we have different UUID and Labels for both partitions, let's mount the secondary partition and update "/etc/fstab" with this new information:

Mount the partition:
sudo mkdir /mnt/sda2 && sudo mount -t ext4 /dev/sda2 /mnt/sda2

Edit "/mnt/sda2/etc/fstab" and replace initial UUID by the new one, in this example we replace:
UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 /               ext4    errors=remount-ro,noatime 0       1                                       

By:
UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 /               ext4    errors=remount-ro,noatime 0       1                                       

Save and umount the partition:
sudo umount /dev/sda2 && sudo rm -rf /mnt/sda2


Step 4: Reboot to main system and update grub


Notes: Os prober from Grub should be able to generate a functional boot configuration finding our cloned system in "/dev/sda2", for an unknown reason this doesn't work so i recommend a manual operation which will be more reliable.


Leave the Live USB system and reboot to the main system, then open "/boot/grub/grub.cfg" and copy main system boot lines to clipboard or a temporary text editor, in our example we will find the original kernel lines:
menuentry 'Ubuntu, avec Linux 3.2.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os {                                   
recordfail
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root affe0f48-6b88-43a5-b131-20a58cd776b8
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 ro quiet splash $vt_handoff
initrd /boot/initrd.img-3.2.0-26-generic
}
menuentry 'Ubuntu, avec Linux 3.2.0-26-generic (mode de dépannage)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root affe0f48-6b88-43a5-b131-20a58cd776b8
echo 'Chargement de Linux 3.2.0-26-generic ...'
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=affe0f48-6b88-43a5-b131-20a58cd776b8 ro recovery nomodeset
echo 'Chargement du disque mémoire initial ...'
initrd /boot/initrd.img-3.2.0-26-generic
}


Add "(on /dev/sda2) behind the kernel version in "menuentry" and replace "msdos1" by "msdos2" and the old UUID by the new one and put these lines into "/etc/grub.d/40_custom", in our example our new lines will be:
menuentry "Ubuntu, avec Linux 3.2.0-26-generic (on /dev/sda2)" --class gnu-linux --class gnu --class os {                                   
recordfail
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set=root 8e1e225a-d51e-11e1-b5aa-00012e409020
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 ro quiet splash $vt_handoff
initrd /boot/initrd.img-3.2.0-26-generic
}
menuentry "Ubuntu, avec Linux 3.2.0-26-generic (mode de dépannage) (on /dev/sda2)" --class gnu-linux --class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set=root 8e1e225a-d51e-11e1-b5aa-00012e409020
linux /boot/vmlinuz-3.2.0-26-generic root=UUID=8e1e225a-d51e-11e1-b5aa-00012e409020 ro recovery nomodeset
initrd /boot/initrd.img-3.2.0-26-generic
}

Update grub:
sudo update-grub 


Reboot from your main system and test booting to the secondary OS, it should boot with no problem and you will get exactly the same system than the main one.

You can test whatever you need in the secondary system such as important system and application upgrade without the risk of breaking down your main system.

Therefore, don't forget that if you have a third partition for "/home", any issue not related to the system partition but related to the home partition (such as deleting user's files) will off course exist in both systems!

So a best practice will always be to also backup the /home partition ^^

As now you have 2 systems available, if you want to update the secondary system, you don't have to boot again with a Live OS:

  • Boot to secondary system
  • Create the partclone image from primary system to an external image
  • Boot to primary system
  • Restore the external image to secondary partition
  • Re do UUID change and fstab correction


Step 5: Optional - Home Directory


If you want to be completely independent of your first installation, you may also copy your initial main user home directory, example to "/home/user_system2".

Then just ensure to change the home directory in your second system by editing "/etc/passwd". (remember to adapt from where you edit it)





Feel free to comment :-)







Friday, July 20, 2012

Mini How-to : Installation of Avermedia Green Volar HD under Linux



****************************************************************************************************
Edit 10/11/2012:

This how-to is outdated, if you have this device, i recommend you to install a kernel beginning on 3.5, this DVB adapter will automatically be taken in charge by new kernels.
The only required operation will be to download the firmware as usual.

In a few words:


For Ubuntu 12.04:

Go to http://kernel.ubuntu.com/~kernel-ppa/mainline/

Then choose your kernel, eg. http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.5.5-quantal/

32 bits kernel, download:
linux-headers-3.5.5-030505_3.5.5-030505.201210021510_all.deb
linux-headers-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb
linux-image-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb
linux-image-extra-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb



64 bits kernel, download:
linux-headers-3.5.5-030505_3.5.5-030505.201210021510_all.deb
linux-headers-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb
linux-image-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb
linux-image-extra-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb


Then install:

$ sudo dpkg -i *.deb


Reboot.

Download firmware:

cd /lib/firmware
sudo wget http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-02.fw


And you're done, just plug, and check your kernel log (command "dmesg")

****************************************************************************************************



So you bought this cheap DVB Tuner USB key and was thinking it would work under Linux with no efforts...well not absolutely in fact :-)

Let's see how to deal with this key, see my post on tvheadend and XBMC for more information on getting live TV using such DVB Tuners:
http://youresuchageek.blogspot.fr/2012/07/xbmc-pvr-how-to-enhance-your-xbmc-media.html

We will use v4l-DVB drivers from Linux TV:

First install some requirements:
For Ubuntu 12.04:

sudo apt-get install libdigest-sha-perl make gcc git patch patchutils libproc-processtable-perl linux-source linux-headers-`uname -r`


For Ubuntu 11.10 and previous:

sudo aptitude install libdigest-sha1-perl make gcc git patch patchutils libproc-processtable-perl linux-source linux-headers-`uname -r`


Download modules, when the process will begin to compile abort it with "ctrl+c", this is very unusual but we don't need the compilation to complete:

git clone git://linuxtv.org/media_build.git
cd media_build
./build


So you aborted compilation, then we will compile and install DVB modules (NB: I you have double core processor using "make -j 2" will speed up the compilation, you may also use standard command with "make")

make allyesconfig
make -j 2
sudo make install


NOTE for Ubuntu kernel 3.2.0-26, compilation could fail, proceed with:
creating "media_build/linux/include/linux/v4l2-common.h" with the following content and relaunch compilation

#ifndef V4L2_COMMON_H
#define V4L2_COMMON_H

/* Hints for adjustments of selection rectangle */
#define V4L2_SEL_FLAG_GE 0x00000001
#define V4L2_SEL_FLAG_LE 0x00000002

/* Selection targets */

/* Current cropping area */
#define V4L2_SEL_TGT_CROP 0x0000
#define V4L2_SEL_TGT_CROP_ACTIVE 0x0000
/* Default cropping area */
#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001
/* Cropping bounds */
#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002
/* Current composing area */
#define V4L2_SEL_TGT_COMPOSE 0x0100
#define V4L2_SEL_TGT_COMPOSE_ACTIVE 0x0100
/* Default composing area */
#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101
/* Composing bounds */
#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102
/* Current composing area plus all padding pixels */
#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103

#endif //V4L2_COMMON_H


Download Firmware:

cd /lib/firmware
sudo wget http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-02.fw


Plug your DVB USB Key and check kernel message, if you're ok you will get this kind of message:

dvb-usb: found a 'AVerMedia AVerTV Volar HD/PRO (A835)' in cold state, will try to load a firmware
dvb-usb: downloading firmware from file 'dvb-usb-af9035-02.fw'
af9035: firmware version=11.5.9.0
dvb-usb: found a 'AVerMedia AVerTV Volar HD/PRO (A835)' in warm state.
dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
DVB: registering new adapter (AVerMedia AVerTV Volar HD/PRO (A835))
dvb-usb: MAC address: 00:00:00:00:00:00
af9033: firmware version: LINK=11.5.9.0 OFDM=5.17.9.1
DVB: registering adapter 0 frontend 0 (Afatech AF9033 (DVB-T))...
tda18218: NXP TDA18218HN successfully identified.
Registered IR keymap rc-empty
input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:12.2/usb1/1-1/rc/rc0/input7
rc0: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:12.2/usb1/1-1/rc/rc0
dvb-usb: schedule remote query interval to 250 msecs.
dvb-usb: AVerMedia AVerTV Volar HD/PRO (A835) successfully initialized and connected.
usbcore: registered new interface driver dvb_usb_af9035

That's all you're done :-)

Some sources:











Mini How-to : Installation of Avermedia Green Volar HD under Linux



****************************************************************************************************
Edit 10/11/2012:

This how-to is outdated, if you have this device, i recommend you to install a kernel beginning on 3.5, this DVB adapter will automatically be taken in charge by new kernels.
The only required operation will be to download the firmware as usual.

In a few words:


For Ubuntu 12.04:

Go to http://kernel.ubuntu.com/~kernel-ppa/mainline/

Then choose your kernel, eg. http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.5.5-quantal/

32 bits kernel, download:
linux-headers-3.5.5-030505_3.5.5-030505.201210021510_all.deb
linux-headers-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb
linux-image-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb
linux-image-extra-3.5.5-030505-generic_3.5.5-030505.201210021510_i386.deb



64 bits kernel, download:
linux-headers-3.5.5-030505_3.5.5-030505.201210021510_all.deb
linux-headers-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb
linux-image-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb
linux-image-extra-3.5.5-030505-generic_3.5.5-030505.201210021510_amd64.deb


Then install:

$ sudo dpkg -i *.deb


Reboot.

Download firmware:

cd /lib/firmware
sudo wget http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-02.fw


And you're done, just plug, and check your kernel log (command "dmesg")

****************************************************************************************************



So you bought this cheap DVB Tuner USB key and was thinking it would work under Linux with no efforts...well not absolutely in fact :-)

Let's see how to deal with this key, see my post on tvheadend and XBMC for more information on getting live TV using such DVB Tuners:
http://youresuchageek.blogspot.fr/2012/07/xbmc-pvr-how-to-enhance-your-xbmc-media.html

We will use v4l-DVB drivers from Linux TV:

First install some requirements:
For Ubuntu 12.04:

sudo apt-get install libdigest-sha-perl make gcc git patch patchutils libproc-processtable-perl linux-source linux-headers-`uname -r`


For Ubuntu 11.10 and previous:

sudo aptitude install libdigest-sha1-perl make gcc git patch patchutils libproc-processtable-perl linux-source linux-headers-`uname -r`


Download modules, when the process will begin to compile abort it with "ctrl+c", this is very unusual but we don't need the compilation to complete:

git clone git://linuxtv.org/media_build.git
cd media_build
./build


So you aborted compilation, then we will compile and install DVB modules (NB: I you have double core processor using "make -j 2" will speed up the compilation, you may also use standard command with "make")

make allyesconfig
make -j 2
sudo make install


NOTE for Ubuntu kernel 3.2.0-26, compilation could fail, proceed with:
creating "media_build/linux/include/linux/v4l2-common.h" with the following content and relaunch compilation

#ifndef V4L2_COMMON_H
#define V4L2_COMMON_H

/* Hints for adjustments of selection rectangle */
#define V4L2_SEL_FLAG_GE 0x00000001
#define V4L2_SEL_FLAG_LE 0x00000002

/* Selection targets */

/* Current cropping area */
#define V4L2_SEL_TGT_CROP 0x0000
#define V4L2_SEL_TGT_CROP_ACTIVE 0x0000
/* Default cropping area */
#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001
/* Cropping bounds */
#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002
/* Current composing area */
#define V4L2_SEL_TGT_COMPOSE 0x0100
#define V4L2_SEL_TGT_COMPOSE_ACTIVE 0x0100
/* Default composing area */
#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101
/* Composing bounds */
#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102
/* Current composing area plus all padding pixels */
#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103

#endif //V4L2_COMMON_H


Download Firmware:

cd /lib/firmware
sudo wget http://xgazza.altervista.org/Linux/DVB/dvb-usb-af9035-02.fw


Plug your DVB USB Key and check kernel message, if you're ok you will get this kind of message:

dvb-usb: found a 'AVerMedia AVerTV Volar HD/PRO (A835)' in cold state, will try to load a firmware
dvb-usb: downloading firmware from file 'dvb-usb-af9035-02.fw'
af9035: firmware version=11.5.9.0
dvb-usb: found a 'AVerMedia AVerTV Volar HD/PRO (A835)' in warm state.
dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
DVB: registering new adapter (AVerMedia AVerTV Volar HD/PRO (A835))
dvb-usb: MAC address: 00:00:00:00:00:00
af9033: firmware version: LINK=11.5.9.0 OFDM=5.17.9.1
DVB: registering adapter 0 frontend 0 (Afatech AF9033 (DVB-T))...
tda18218: NXP TDA18218HN successfully identified.
Registered IR keymap rc-empty
input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:12.2/usb1/1-1/rc/rc0/input7
rc0: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:12.2/usb1/1-1/rc/rc0
dvb-usb: schedule remote query interval to 250 msecs.
dvb-usb: AVerMedia AVerTV Volar HD/PRO (A835) successfully initialized and connected.
usbcore: registered new interface driver dvb_usb_af9035

That's all you're done :-)

Some sources:











Wednesday, July 18, 2012

Mini Howto XBMC : Install an MCE remote control to take over your Linux XBMC Box


The Goal: 

The better and easiest way to control your XBMC box is naturally a remote control. (moreover for the rest of the family ^^) 

If your HTPC wasn't provided with one or if you want to change, that's my opinion but my advise would be to buy an MCE remote, also called Microsoft remote control.

They will easily work in any Linux installation and will work without any suffering effort in XBMC !

What you need:

  • A functional XBMC Linux installation
  • An MCE remote control associated with its IR receiver. (prefer an external USB IR receiver)
For my personal installation, i bought this one (french link):


It works perfectly in Linux and XBMC and comes with a great IR USB reveiver.
The remote itself has a good quality, nothing to regret.

You may also look for one on ebay, you'll easily find a lot of MCE remotes that will work with no issues in XBMC and Linux.

Step 1: Install and configure LIRC

Plug the IR and check kernel messages:

First plug the IR receiver and check kernel messages, you should find such a message telling your the IR receiver has been detected and installed:


[   11.560051] input: MCE IR Keyboard/Mouse (mceusb) as /devices/virtual/input/input9                                                       
[ 11.563329] IR MCE Keyboard/mouse protocol handler initialized
[ 11.572910] lirc_dev: IR Remote Control driver registered, major 249
[ 11.574374] rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0
[ 11.574382] IR LIRC bridge handler initialized
[ 11.624101] mceusb 4-2:1.0: Registered Topseed Technology Corp. eHome Infrared Transceiver with mce emulator interface version 1
[ 11.624110] mceusb 4-2:1.0: 2 tx ports (0x0 cabled) and 2 rx sensors (0x1 active)


Here you can see Linux recognized the IR device has an "mceusb", the driver will be loaded directly by the kernel itself.

Install and configure LIRC:

If LIRC is already installed in your system, my advise is to completely uninstall it, you could use "dpkg-reconfigure lirc" but it my case it was not completely working as expected.

Moreover, in Ubuntu 12.04 there seems to be problem identiying a kernel directory when installing LIRC, if you have any issue starting LIRC, the workaround is:

$ sudo ln -s /lib/modules/3.2.0-26-generic/kernel/drivers/staging/media/lirc /lib/modules/3.2.0-26-generic/kernel/drivers/staging/lirc


NB: Replace with your kernel version (eg. 3.2.X-XX-....), use the command "uname -a" if you don't know it


So backup your config files if required (in directory "/etc/lirc") and:

sudo apt-get remove --purge lirc


Install LIRC:

sudo apt-get install lirc


Accept the installation and when requested in first configuration screen, choose the "Windows Media Center Transceivers/Remotes [all]" :



And choose none for the second screen and valid.


Step 2: Test


use the LIRC provided tool to test your remote control:

$ irw


Press some randoms remote keys, if your MCE remote works, you will get keys signals.
If you don't have nothing, you might have a problem with LIRC or with your configuration:

  • double check that LIRC is started, in case of and to check messages restart it (sudo /etc/init.d/lirc restart)
  • If LIRC is failing to start, check the workaround at the beginning of this article, a kernel directory location change seems to break LIRC!
  • check your receiver, on various IR receivers you'll get a red light when pressing a remote key
  • perhaps your remote control will need a other driver, ask Google :-)


Step 3: XBMC Test


Restart XBMC and test your remote control, in my case (and in general with an MCE remote) you absolutely have nothing more to configure ^^

And you're done, enjoy :-)











Mini Howto XBMC : Install an MCE remote control to take over your Linux XBMC Box


The Goal: 

The better and easiest way to control your XBMC box is naturally a remote control. (moreover for the rest of the family ^^) 

If your HTPC wasn't provided with one or if you want to change, that's my opinion but my advise would be to buy an MCE remote, also called Microsoft remote control.

They will easily work in any Linux installation and will work without any suffering effort in XBMC !

What you need:

  • A functional XBMC Linux installation
  • An MCE remote control associated with its IR receiver. (prefer an external USB IR receiver)
For my personal installation, i bought this one (french link):


It works perfectly in Linux and XBMC and comes with a great IR USB reveiver.
The remote itself has a good quality, nothing to regret.

You may also look for one on ebay, you'll easily find a lot of MCE remotes that will work with no issues in XBMC and Linux.

Step 1: Install and configure LIRC

Plug the IR and check kernel messages:

First plug the IR receiver and check kernel messages, you should find such a message telling your the IR receiver has been detected and installed:


[   11.560051] input: MCE IR Keyboard/Mouse (mceusb) as /devices/virtual/input/input9                                                       
[ 11.563329] IR MCE Keyboard/mouse protocol handler initialized
[ 11.572910] lirc_dev: IR Remote Control driver registered, major 249
[ 11.574374] rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0
[ 11.574382] IR LIRC bridge handler initialized
[ 11.624101] mceusb 4-2:1.0: Registered Topseed Technology Corp. eHome Infrared Transceiver with mce emulator interface version 1
[ 11.624110] mceusb 4-2:1.0: 2 tx ports (0x0 cabled) and 2 rx sensors (0x1 active)


Here you can see Linux recognized the IR device has an "mceusb", the driver will be loaded directly by the kernel itself.

Install and configure LIRC:

If LIRC is already installed in your system, my advise is to completely uninstall it, you could use "dpkg-reconfigure lirc" but it my case it was not completely working as expected.

Moreover, in Ubuntu 12.04 there seems to be problem identiying a kernel directory when installing LIRC, if you have any issue starting LIRC, the workaround is:

$ sudo ln -s /lib/modules/3.2.0-26-generic/kernel/drivers/staging/media/lirc /lib/modules/3.2.0-26-generic/kernel/drivers/staging/lirc


NB: Replace with your kernel version (eg. 3.2.X-XX-....), use the command "uname -a" if you don't know it


So backup your config files if required (in directory "/etc/lirc") and:

sudo apt-get remove --purge lirc


Install LIRC:

sudo apt-get install lirc


Accept the installation and when requested in first configuration screen, choose the "Windows Media Center Transceivers/Remotes [all]" :



And choose none for the second screen and valid.


Step 2: Test


use the LIRC provided tool to test your remote control:

$ irw


Press some randoms remote keys, if your MCE remote works, you will get keys signals.
If you don't have nothing, you might have a problem with LIRC or with your configuration:

  • double check that LIRC is started, in case of and to check messages restart it (sudo /etc/init.d/lirc restart)
  • If LIRC is failing to start, check the workaround at the beginning of this article, a kernel directory location change seems to break LIRC!
  • check your receiver, on various IR receivers you'll get a red light when pressing a remote key
  • perhaps your remote control will need a other driver, ask Google :-)


Step 3: XBMC Test


Restart XBMC and test your remote control, in my case (and in general with an MCE remote) you absolutely have nothing more to configure ^^

And you're done, enjoy :-)











Monday, July 16, 2012

Mini How-to : Google Drive under Linux: Synchronize your Google Drive under Linux with grive ! (waiting for the official Google client ^^)



Edit 10/18/2012:
Take a look at new project https://www.insynchq.com/, it's very easy to install and use, offers much more integration in Linux desktop than grive.

Very great !!!



Official Linux Google drive version is still lacking... if you are as i am addicted to various Google Services this lack is very frustrating ! (what does Google waits for ???)

Fortunately, you can now, thanks to "grive" and its author, synchronize your local documents to your Google Drive in command line :-)

Here's how in a few command lines:

Install grive:

Install grive (under Ubuntu and derived distributions)

sudo add-apt-repository ppa:nilarimogard/webupd8

sudo apt-get update

sudo apt-get install grive

Configure first launch to authorize grive to access to your Google Drive:

Go to the directory you to be synchronize with Google Drive and configure grive

$ cd <My Local Directory to synchronize>
$ grive
-----------------------                                                                                                                     
Please go to this URL and get an authentication code:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2F
auth%2Fuserinfo.profile+https%3A%2F%2Fdocs.google.com%2Ffeeds%2F+https%3A%2F%2Fdocs.googleusercontent.com%2F+https%3A%2F%2Fspreadsheets.goog
le.com%2Ffeeds%2F&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=22314510474.apps.googleusercontent.com

-----------------------
Please input the authentication code here:


Open your Web browser, paste this URL and login with your Google account when asked and finally copy the code that Google will provide to paste into the terminal

grive will execute the first synchronization:

Reading local directories
Synchronizing folders
Reading remote server file list
Detecting changes from last sync
Synchronizing files
Finished!


You're done, now every time you want to synchronize your local data with your Google Drive, just enter a terminal, "cd" to your directory and enter "grive" command line.

It is not necessary anymore to run it with "-a" option as its purpose was to configure and associate your computer with your Google drive account, just run grive with no option to initiate synchronization.

You may also want to see others options such as "-v" to enable more verbose mode or "--dry-run" to simulate execution, just see help:

grive --help                                                                                                         
Grive options:
-h [ --help ] Produce help message
-v [ --version ] Display Grive version
-a [ --auth ] Request authorization token
-V [ --verbose ] Verbose mode. Enable more messages than normal.
-d [ --debug ] Enable debug level messages. Implies -v.
-l [ --log ] arg Set log output filename.
-f [ --force ] Force grive to always download a file from Google Drive
instead of uploading it.
--dry-run Only detect which files need to be uploaded/downloaded,
without actually performing them.



Really great work from the author (see man):

AUTHOR                                                                                                                                      
The software was developed by Nestal Wan.

This manpage was written by Jose Luis Segura Lucas (josel.segura@gmx.es)


  
Now we (all Linux Google services users) are still waiting from Google to finally provide us their official client... Google listen to us, it would be nice not to forgive Linux users :-)