Playing Music on CentOS using codec's installed on Ubuntu: My little experiment
A personal computer doesn't look really personal until it is able to play multimedia content. I started using CentOS to deploy Xen server but still, I need my music. Just like Ubuntu, due to licensing issues, it doesn't come with pre-installed codecs to play proprietary formats. And before installing them on CentOS manually, I thought what if I could use the ones installed on Ubuntu(which is on the same disk) to make it work. And people, it did
.
The trick that I have used here can be used in almost all linux based distributions, its the chroot jail.
- First I mounted the Ubuntu partition on /mnt
- Then mount the critical virtual filesystems to it
- Now, change the root directory to /mnt using chroot
[root]# mount /dev/sda2 /mnt
[root]# mount --bind /dev /mnt/dev
[root]# mount --bind /proc /mnt/proc
[root]# mount --bind /sys /mnt/sys
[root]# chroot /mnt
For those of you who are unaware of chroot, it can be considered as a type of virtualization, not a full blown guest operating system, but if we think about it we are actually running a different operating system on the current one. Using 'chroot' we present a completely different "/" directory to a filesystem. In our case, it was the ubuntu's root directory and filesystem. Every process running in the chrooted environment, considers /mnt as the root directory.
The chrooted environment is not allowed to access any parent directories or memory outside it. They provide a sandbox/restricted environment and hence are used for testing system critical applications. You might have come across it while recovering grub/grub2, this is another area of its usage.
Anyway, back to the music part. Since, I didn't know how to run graphical applications using chroot, I went for mocp, a brilliant console audio player. And it worked like a charm
. In case you are wondering how, thats because now we are inside the Ubuntu OS environment. The audio player, installed on Ubuntu, is using the required libraries from the same OS and since it already has the required driver to access the sound card and also the access to it (note the mounting of /dev, /proc & /sys partitions), the whole thing works.
Doing stuff regular way always works, but making them work differently is fun. Do try it out.
Post new comment