Tuesday 13 November 2012

Ubuntu everywhere

Technology evolves so fast that it's quite hard to catch up with all the changes (and more if you're into a broad range of its aspects, from hardware to high level development abstractions). So the thing is that some months ago I was taken aback for how easy it's now to create a bootable USB key (even more, a multiboot USB key). Last time I had looked into that had been several years ago, and at that time it was far from trivial and error prone (using dd in Linux and so on, I don't think back then you had many options for doing it from Windows).

So, PendriveLinux was an astonishing discovery that allowed me to create a multiboot key with Ubuntu and several rescue distros. So, I can boot the Ubuntu ISO from there and do a live session or an install, or run some of the rescue distros if my PC has gone into some trouble. So once the mission was accomplished I didn't ponder on it much more until a few weeks ago, when I felt the need to go one step further, and have a "fully usable Ubuntu" on my key, that I could run from my home laptop, my work laptop and so on. What I mean with this is doing a normal Ubuntu installation to the USB key, and use it normally, installing and removing packages and so on.

The idea seemed quite feasible to me. If creating a bootable USB is now so easy and works so neat, installing a bootloader and the OS to the USB Key rather than to the HD (I mean a normal installation, not just a bootable ISO) should not be a problem. I searched the net seeking for confirmation, and It's then when things turned a bit confusing. Most articles seemed to deal with a slightly different scenario, creating a sort of "Live USB" with persistence (space where you can store your settings and even (I think) install new packages). After doing some good readings I decided to follow this detailed and simple article

There's a first point not mentioned there that has to be taken into account. If you (as I did) decide to partition your USB key to leave a Data partition there where you can store data without messing with the OS installation, you should use the first partition for data and install Ubuntu to the second partition. Well, let me be more specific, you must do that if you want to use that data partition from Windows. While Windows has no problem with viewing partitions in an external USB Hard Disk, when it comes to USB Keys, it will only work with the first partition, so you better use that first one as Data partition.
On a side note, my own experience tells me that Ubuntu has no problem working with all the partitions in a USB key, but Android (at least version 2.3) will only see the first partition of a SD card.

So, I used the Startup disk creator utility mentioned in the article, in a few minutes I had my bootable USB. Nevertheless, the persistence option did not seem to work, cause though I had no problem installing a new package and running it (I installed node.js) once I did a restart, the installation was gone (so I guess it just got installed in memory, which confirms the idea that this sort of installations is just a "Live USB".

I decided then to try what I really wanted from the beginning, doing a normal installation, but targeting my USB key instead of the Hard Disk. Well, the process is that simple as it sounds. Boot a Live Ubuntu ISO, start the installation and when presented with the menu to select a target partition, choose your USB key from the combo box. That's all to it, the difference with the other install explained above is that as this is doing a normal install, it takes much longer (while the "Live USB" creation that I did before is very fast).

Once installed, I could happily verify that my "portable Ubuntu installation" works nice on both my Home Laptop and my Work Laptop (Ubuntu 32 bits runs sweet on both my 32 bits and a 64 bits machines). What surprises me most of all of this is that I used to think that at installation time Linux checked what drivers (Kernel modules) were needed for the specific hardware, copied them to disk and generated some sort of list to load them in following start ups (obviously, it would also check for hw changes at boot time, to load or ask for the corresponding new "drivers"). Well, things seem to be quite more dynamic, and at each start up the OS checks the hardware and dynamically loads the needed kernel modules (so no list with the kernel modules needed for the hw present at installation time). This process is done by udev, and is explained here

When your system boots, one of the startup scripts starts up Udev and prods the kernel. The kernel then sends back a stream of events for all the hardware detected when it started up ("add this device", "add that device", ...). Udev picks up these events as if the devices had just been added, creates the appropriate /dev nodes, sends off the appropriate notifications to HAL, and so on.

I guess this also means that Ubuntu seems to copy a whole lot of different kernel modules to disk (not just the ones needed at install time) so that the can be used if needed

All this is really interesting and makes me wonder if it could also be done with Windows, or whether its installation determines the hardware on which that "image" can run

No comments:

Post a Comment