Thursday, February 25, 2010

Install Ubuntu from Alternate CD image; booting from USB flash drive

I recently tried a couple of ubuntu versions, installing them on a partition to play a few hours. In the process I re-discovered unetbootin, a wonderful tool for this: I burned the CD ISO images in a USB flash drive, instead of burning CDs (even if you use rewritable, it is slower than a USB key). UNetbootin let's you make a bootable pendrive from any ISO image; you can even download your favorite distro CD from there.

The main comment of this post is, however, not just the unetbootin process, but two tips that solved issues with these images.

First, the simpler one: You have to mark the partition in the USB drive as bootable, or you will not be able to boot... To do this, run fdisk /dev/sdb (or whichever your drive's device is), and add its boot flag.

The second on is subtler. With the Ubuntu 9.10 Desktop CD everything worked perfectly; I was able to boot. But later I tried the Alternate CD, which after booting it could not find the contents of the "CD" it was installing from. Somehow it missed the point it had boot from USB; so there would not be any contents on CD-ROM to read (in fact, that machine does not even have a CD drive). What I had to do was to add a flag to the kernel boot options: When UNetbootin starts, before pressing Enter on the "Default" option, press Tab to edit it. Edit the kernel line, to make it look like this one:
/ubnkern initrd=/ubninit vga=normal cdrom-detect/try-usb=true -- quiet

(Everything should be in a single line). Your line might not be identical; but the important part is to add "cdrom-detect/try-usb=true" before the "--". With this option the installer found the contents and was able to continue the rest of the install process.

Wednesday, February 24, 2010

Resizing a VirtualBox bootable WinXP drive

I have a couple of Windows images running in VirtualBox machines. (Yes I only boot linux, but still have a couple of windows images confined to their VMs). They ran out of diskspace; I created too small disks. I had attempted to solve this by adding increasingly larger secondary disks; but Windows does not like small "C:" partitions; sooner or later problems arise.

I found tips from several places about how to do this so I am going to compile my experience here. Since VDI images cannot be just resized (disk geometry can be altered), one needs to move the data to another VDI disk. The procedure is then: 1) Create a new (bigger) disk, 2) Clone the old disk into the new disk, 3) replace the disk in the virtual machine.

So far, that's more or less simple if the disk is not the primary, bootable disk. But I tried cloning with Acronis TrueImage, GParted and a couple of other tools, and they all resulted in an unbootable disk with "Disk reader error, press Ctrl+Alt+Del" message when trying to boot. I tried using the windows recovery console rebuild the MBR (fixmbr.exe) or the boot sector (fixboot.exe) but none of them worked. The extra tip was touching a parameter in the boot sector of the disk... find the details below.

Before you start, you might want to backup your entire VDI image; just in case (none of these steps will modify it... but there is always the case of selecting the wrong option).

All the steps then look like:
  1. Create the disk

    1. Shut down the virtual Windows machine
    2. From VirtualBox disk manager, create a new disk (bigger!), and attach it as secondary to that machine.

  2. Copy data. Use some cloning tool to copy the entire disk from the old disk to the new one. In my case, I found the simpler way was:

    1. Download a GParted LiveCD,
    2. Add it to the list of VirtualBox ISO images,
    3. Mount it on the virtual machine, and make sure the CDROM is first in boot order sequence.
    4. Boot GParted. Select the old disk/partition, click "Copy". Select the new disk, create on "Create Partition Table" (type "MSDOS"), then click "Paste" to bring the new data. In the resizing dialog, you can extend the partition to the end of the disk. Click "Apply" and it will take a while until the partition is copied. Then go to "Manage Flags" and enable the "Boot" flag.
    5. Shutdown the virtual machine; remove the ISO cd image.

  3. Enable the new disk (You might want to try seeing if the new disk just boots -- If you do not get a "Disk Read Error" message, skip next steps and you are done!).

    1. Start the virtual machine (still with the old disk as primary). You should be able to view the bigger, secondary disk, with the same contents as the old one.
    2. From within Windows, download Roadkil's Boot Builder. Then a) Read the boot sector of the NEW disk, b) change the "Heads" parameters to 255, c) write the sector back to the NEW disk. (Make sure not to screw up disk names! your old disk is still the backup.). See screenshot.
    3. Shutdown Windows. From VirtualBox, remove the old (smaller) disk, and leave only the new (larger) disk. Start up the VM, it will nicely boot up. (Well, Windows will boot up...)

I have no idea why that Heads parameter needs to be changed; but changing it from 128 to the magic 255 value worked for me (enlarging a 3Gb disk to 10Gb one) and others as well.

Happy cloning!

Sunday, October 11, 2009

Quick DVD authoring, with subtitles

Let's say you have a DivX movie (movie.avi) and a subtitles file (subtitles.srt) and you want to burn this into a DVD, which any player (non divx-capable) can play.

This is called DVD authoring, and there are many tools to do the job (though I have not found one that I really like, yet). For such a simple task, a few commands on the console are the simplest option.

1. Transcode move to MPEG-2

See the mencoder documentation at the end - it contains examples for other formats.
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 \
-o movie.mpg movie.avi


2. Render and multiplex subtitles into movie

Create a file like this one, and save it as sub.xml:
<subpictures>
<stream>
<textsub filename="subtitles.srt" characterset="ISO-8859-1"
fontsize="22.0" font="devedesans.ttf"
horizontal-alignment="center"
vertical-alignment="bottom" left-margin="60"
right-margin="60"
top-margin="20" bottom-margin="40" subtitle-fps="25"
movie-fps="25" movie-width="720" movie-height="574"/>
</stream>
</subpictures>
Run spumux to create a new mpeg file with the subtitles stream:
spumux -s0 sub.xml < movie.mpg > m_subs.mpg


3. Author the DVD


Finally, we need to tell dvdauthor how to create a dvd. Create a file dvd.xml like this one:
<dvdauthor>
<vmgm>
<titleset>
<titles>
<subpicture lang="es">
<pgc>
<vob file="m_subs.mpg">
</pgc>
</titles>
</titleset>
</dvdauthor>
And run dvdauthor:
dvdauthor -o thedvd -x dvd.xml


4. Round up


Voila! The directory thedvd will contain the DVD structure (not an ISO image). You can test the results with mplayer:
mplayer dvd:// -dvd-device thedvd

and if it looks ok, just burn it into a dvd - k3b can burn this (use new Project -> movie DVD)

At the end you can delete *.mpg files, and the thedvd directory.

References:


  • mencoder on dvd authroing: http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
  • spumux: http://dvdauthor.sourceforge.net/doc/spumux.html

Wednesday, October 7, 2009

thunderbird: very small fonts, and links not opening in browser

I recently installed and new kubuntu on my mother's PC (yes!! finally, wiped out Windows completely!!), and of course I am the help desk support since then...

A few days ago I had the chance to solve to curious issues she was having with thunderbird. I had to google a little for both solutions:

Very small fonts: Almost everything in thunderbird had a very, very small font size: menus, message list, etc. I tried changing DPI resolution in KDE, setting global font preferences por KDE and GTK applications, with no avail. Finally the solution was to tweak a property within thunderbird:
layout.css.cpi = 0

(the default value was unset, or -1, I can't remember). So simple! I don't know what is the meaning of the property, but solved the issue and now all fonts are just like in any other application.



Clicking links does not open a browser: When reading an email with a URL, clicking on them did just nothing. I browsed every possible option in the Preferences windows, but there was nothing that fixed it. The solution, again, was hidden in the advanced preferences. I had to set a few variables:
network.protocol-handler.app.http = /usr/bin/firefox
network.protocol-handler.app.https = /usr/bin/firefox
(that can be done for ftp as well -- and any other protocol if needed).



Note: To edit the "advanced" preferences, go to Edit > Preferences > Advanced > Config Editor. Be aware that you can misconfigure it very easily from there!


Both are things far from what a regular end user could change. I wonder why the default install left things that way....

Wednesday, September 9, 2009

so many wifi clients!

Last night I ran a apt-get upgrade after some time updating anything -- over a month. It looked like mostly an update for many, many KDE packages (I think I got 4.3.1). Just in case, I rebooted -- I always do it after upgrading many packages in case something goes wrong, to make it evident. Well, something went wrong: the knetworkmanager would not connect again to my WPA-protected home wifi. As a result, I lost a couple of hours of sleep time last night... things are working again, after some fight.

I thought it would be interesting to remember how many wifi clients I used over the last year or so:
  • network manager from KDE3: I used this one for a long time. Even after starting using KDE4 (in those scary days of betas of the 4.0.x branch, where virtually nothing worked as expected), this rock-solid tool kept me connected to my wireless network. Its biggest problem was just that it was slated to die; it had the KDE3 look, and would be vanished soon. (Image from softpedia)


  • At some point, a plasmoid appeared as a replacement. This one was a nightmare at the beginning, but after some time it started to work. It never worked 100%, there where some inconsistencies (when editing networks' properties, or when showing the current state, some things did not reflect correct status). It worked for some time. (Image taken from here)


  • Just a couple of months ago (from KDE 4.3 betas?) the plasma applet changed is icon to something really ugly, and a tooltip message said that its development was incomplete and suggested to use "knetworkmanager" instead. So I moved... and well, this one worked nicely! I thought it was the end of the journey. Well integrated in KDE4, properties appearing in control panel too... some tiny features where appearing from time to time after upgrades. Very nice.
    Sadly, after yesterday's update, it did not connect anymore. I can click the network names I created, and nothing happens. Just that. I don't know how to debug it.


  • I should also mention that when these things fail, I also resort to wpa_supplicant, connecting from command line with a config file I already have pre-configured and a command line saved right there as I always, always forget the parameters. But again, this is working 100%. It keeps disconnecting, it shows a lot of errors in the console... It kind of works, and saved me sometimes. Last night it was not the exception, so I did not want to continue using it for work over weeks until finding a solution.
  • Looking for solutions last night I found wicd. I just thought 'yet another program to try'... and worse, it depended on gnome libraries so it looked like some gnome-only applet. But comments were very positive, so I tried it. Installing the package also uninstalled knetworkmanager, good job! The package also added a daemon, perfect.... and all I can say is it just works. Ok, the UI is not KDE4-ish. But I can configure everything I need, and it worked perfectly after a couple of reboots. (As a side comment: Ubuntu's repositories had a 1.5.x version, and after installing it and knowing it worked, I moved to wicd's repos which brought 1.6.2 version, which is even nicer).


This can be read as a rant against wifi support on linux. And it is, in part. ((Wireless connections have been more of a problem for me than anything else -- even more than 3d acceleration which has settled down reasonably many months (or years) ago for me. Wireless is still... a pain.)) The web is too confusing as it becomes quickly outdated; when you run a search you will find results for hundreds of methods, drivers, hardware, linux distribution, even different ubuntu versions, and none of them except one will work on your scenario.

My intention is to let others know wicd, and to receive feedback about these things, like: Am I too dumb, that I break my networking so often? Is this regular fight intended for every end user that just intends to keep his ubuntu updated? (I know I play beyond end-user-ness, and I enjoy it, but I also think ubuntu must be something an end user must be able to manage by itself).
Meanwhile... I will happily use wicd -- as long as it works :)

Friday, August 21, 2009

ffmpeg with AMR (.amr/.3gp) and x264 on Ubuntu

A few days ago I needed to convert some AMR audio files (recorded in a phone) to a more common format -- like mp3. I found out this would be difficult since:
  • the ffmpeg from Ubuntu repositories does not suppport AMR
  • ffmpeg dropped support of libamr as it used to have - now they use lib-opencore-amr
Fortunately I found a LOT of help in Ubuntu forums, thanks mc4man for that! I am going to summarize here what I did to finally decode amr files with ffmpeg. Here we will compile ffmpeg and x264 from source code, and install them as packages so we can remove them at any time later.

Following this how-to by FakeOutdoorsman, I downloaded x264 sources (why not? let's compile to support as many formats as possible), compiled it, and downloaded ffmpeg source code:

1. Make sure you don't have any of this installed from ubuntu:
sudo apt-get purge ffmpeg x264 libx264-dev

2. Download and compile x264: (You may need to install some build tools -- see the original how-to if you don't have them)
cd
git clone git://git.videolan.org/x264.git
cd x264
./configure
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1" --default

3. Get libopencore-AMR-NB and libopencore-AMR-WB from DebianMultimedia. These are the urls for i386 and amd64. Download the four files libopencore-amr*, and install them with dpkg -i .

4. Download, configure and build ffmpeg. Note that the ./configure step is different than the one in the mentioned how-to -- it adds the flags for AMR.
cd
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3" --default

And it's done! I am now able to transcode my files to mp3:
ffmpeg -i test.amr -f avi -vcodec xvid -acodec libmp3lame -ar 22050 test.mp3


Now if later you want to remove these packages, remove ffmpeg, x264 and the four libopencore-amr* we have installed. And also, if you ever want to upgrade with a newer source code, see the original post; they instructions are there (I have not tested that yet).

Thursday, August 6, 2009

that ol'university times...

Here is another offtopic. I found this beatiful piece of software, a kind of 'norton commander' -- ok, just a file browser for MS-DOS.... It features a recursive calculator of directory sizes, and a magnificent hex file viewer. Wow! The amazing part is that this fully written on assembler, , for an assignment a group of four friends (Abel Valente, Juan Francisco Pertino, Alejandro Miguez & me) did for the course "Taller de Arquitectura", during our 3rd year of Licenciatura en Informatica, Faculty of Informatics, University of La Plata, Argentina. One of them and me, in parallel, just remembered this work a couple of days ago: almost exactly 10 years after writing it!

Here are a few screenshots. The main screen with the directory size shown (it surprises me that Windows directory size does not overflow...):


Here, the hex viewer!


And finally, the output when exiting, with the date.... August 1999!


One more: source code.... Over 120kb and assembly, sweat and tears:


So many things learned... We will never forget the conditional jumps from the end of a loop.... to the beginning of a loop in a different procedure! And the magic trick of PUSHing and POPing all the flags to make the problem disappear.... ;)

I still can't believe we did it! Those were one of the best 34,687 bytes we ever produced! It's also hard to believe 10 years passed by. I must be getting old.