Monday, April 7, 2008

Dual Booting OS 2008 Step 3: The Actual Dual boot

Ok, so now we have root access, we have a partitioned mmc/sd card.. we are ready for the cool part.

First things first, either plug in your tablet or make sure you have a full battery, you don't want the power to go out during this part.

From the tablet you need to download this;
http://fanoush.wz.cz/maemo/initfs_flasher.tgz

(for more information about fanoush's work and info on this flasher, see http://fanoush.wz.cz/maemo/#initfs)

By default the tablet will want to save to your Documents folder in your /home directory (/home/user/MyDocs/.documents/)

Don't save it on your card, not because that will cause problems, but because you can't execute applications by default from your cards. This program is going to replace the initfs section of the device with the dual boot, but first lets look at that extension...tgz

This means that this is a tar file, compressed with gzip compression.. if it read tar.gz it would mean the same thing. In linux file extensions don't mean anything. They are just there to help the user know what to do with the file.

We are going to use the version of tar that comes with the tablet to open this file. This will probably be the last time we use that version, more on this later.

In xterm as root run the following;

cd /home/user/MyDocs/.documents
tar xvzf initfs_flasher.tgz
cd initfs_flasher
./initfs_flash

The first command (cd) Changes Directory to your documents folder. The "." before a file or directory means its a hidden file and won't show up in a listing with out the -a switch (google for "manpage ls" for more info). The second command opens the archive file the switch (xvzf) means X=extract V=verbose(more info) Z=gzip format F=specified file. Then we are switching into the directory that we just extracted, and finally we are running a local application (./). Unix uses something called your "PATH" (try "echo $PATH" at xterm). The path is where the system looks for executables. Since your documents folder isn't in your path, we tell the system to run the local app directly (./ means "here" ../ means "one level above me" ../../ "two levels above" and so on and so forth)

Read the applications instructions carefully, but you should be safe answering yes to all the questions.

When it says press enter to reboot.. do so. If upon boot for some strange reason your highlighted selection is not "internal flash" hit the menu key, and then the up key to highlight it, then hit the square button. If it is highlighted, you can either wait the 30 seconds for the menu to finish, or hit the menu key, then the square key.

Congratulations! You can now dual-boot, but dual boot to what? Continued Next Time.

Just kidding.. man wouldn't that have sucked!

We are going to copy the whole rootfs over to the card. Remember when I talked about that other version of tar.. well here it is. We are going to use GNUtar.. it has more features.. though it will look and feel pretty much the same.

To install, open Xtem, and run this command

apt-get -d install tar

Apt-get is the front end for dpkg, the debian package managment software, and we are telling it to fetch and install tar...well almost. See that -d? That means download only. In this case that is 147% important! Without that it will delete your whole system and you will have to flash and start over. Don't be worried though, just double check for the -d before you hit enter.

If you made sure the -d was there you can ignore the warnings and go ahead and enter "Y".

Once it has downloaded, we will run the following commands as root in an xterm.

cd /var/cache/apt/archives/
mkdir /tar-temp/
dpkg -x tar*.deb /tar-temp/

Ok, you already know what the cd command does. The mkdir command makes a new directory where you tell it to. This new directory we are making is called tar-temp, and it is being made in the top level directory "/" also called the root. The last command uses the debian package management software to extract the tar program to that directory.

Now we need to mount our partitions to locations that we can copy over the files

Again, as root in an xterm;

insmod /mnt/initfs/lib/modules/2.6.18-omap1/mbcache.ko (this is .21-omapl in OS2008)
insmod /mnt/initfs/lib/modules/2.6.18-omap1/ext2.ko
mkdir /opt/
mount /dev/mmcblk0p2 /opt
mkdir /floppy/
mount -t jffs2 /dev/mtdblock4 /floppy

Now to explain those commands.

Insmod is a command to load a module into the running kernel space. We load the two modules needed to mount an ext2 partition. Then we make an /opt directory, and mount the ext2 second partition internal card to that directory. Then we make a directory called /floppy and mount the running rootfs to it.

Now for the magic.

/tar-temp/bin/tar cf - -C /floppy . | /tar-temp/bin/tar xvf - -C /opt

*editors note.. the above command is one long line. On some screens it gets cut into two lines. I blame blogspot :-)

That command will use our new version of tar to properly copy everything over to
our card's partition. The tall bar in the middle is called a pipe. It is located
on the finger keyboard of the third tab fifth key from the right.


again root with xterm;

umount /opt
umount /floppy
chroot /mnt/initfs cal-tool --set-root-device ask:immc2
shutdown -r now

What this does is unmounts our card and rootfs. The chroot sets a little jailed system of our initfs and the rest of it adjusts the boot menu to default to the internal card's boot. Finally we reboot with the shutdown.

When the system comes back up the internal card will be selected. You can either wait the 30 seconds for the boot to start or hit the menu key, then the square key to start it right along.

Ok, a few things to be aware of running off your internal card. Sometimes because of how the card works, your system can get a little off... if you notice items missing from menus or it's just not working right, reboot to the internal flash and run this command as root from the xterm

fsck -fy /dev/mmcblk0p2

The fsck command is a file system checker, the -fy is a force run saying yes to all fixes.

These are the only other caveats I have to booting off the internal card. First, if you hook up to usb, only the external card will be usable on the pc and the internal card will not remount for use once you disconnect without a reboot. If you have to do alot of usb work, boot off the internal flash for that time. Second, sometimes the system may lock up a bit.. just pull the battery out.. boot to internal flash, run the fsck then reboot to the card and all will be well.

Enjoy

*all procedures are attempted at your own risk. I claim no responsibility if you ruin your tablet.

Props..
www.internettablettalk.com
http://maemo.org/maemowiki/HowTo_EASILY_Boot_From_MMC_card

Friday, April 4, 2008

Dual Booting OS 2008 Step 2: Partitioning

First you need to make sure you have root access, which was described in my previous post. Now we need to partition the ssd/mc card in order to be able to handle both the OS(Operating System, in this case also called the "*rootfs", and storage space for your music/videos etc.

This entire process can be done from your tablet. I always do it from my n800, you can to. It's easy.

Step 1: Unmount the mmc/sd

Since your already root in an xterm (right???) we are going to "unmount" the card. Everything in linux is a file, harddrives, soundcards, your mmc/sd.. all files. Unix "mounts" certain devices to be seen in different locations and to make them accessible. How ever we want to make major changes to that card, so we don't want the OS controlling it.
_
umount /dev/mmcblk0p1
or
umount /media/mmc2

Now to explain what those mean.

umount is the command that removes a mounted location from the system.

/dev/mmcblk0p1 is the hardware device file for the internal card partition 1

mmcblk0 == internal card
mmcblk1 == external card
p1 == partition 1;p2 == partition 2;etc

If you are in the dir anywhere, or maybe have extended memory running on the card it won't unmount.. stop playing music, cd out of the dir, turn off your extended virtual memory.. try again.

Step 2: Partition the card

We need some tools for formating and partitioning so we have to do two things

First we have to add a new repository to our applications list.

To add a repository Click
MENU - > SETTINGS -> APPLICATION MANAGER

Then click on the file button or the title bar of Application manager and select TOOLS -> APPLICATION CATALOG

We want to add a repository so click NEW.

Catalog name: Maemo Repository
Web address: http://repository.maemo.org/
Distribution: bora
Components: free non-free

Make sure that "disabled" is unchecked

Click OK, then click CLOSE

Ok, now back in xterm as root

apt-get install e2fsprogs

now that thats installed. We are going to use sfdisk to partition the card. Sfdisk is kinda clunky and no user-friendly... however its on the tablet.

Start the app with this command

sfdisk -uM /dev/mmcblk0

the -uM means display and accept Megabyte units, and you remember that /dev/mmcblk0 is your internal card

Now once your in there you need to setup 4 partitions.. well really just two but its gonna make you set up 2 empty ones too.. don't worry it will make sense.

I am going to use my card as an example, you can modify fairly easily. I have a 2 gig sd card. I am going to give 356 megs to my first partition for use by the applications for music and files and what not, and approximately 1.6 gigs for my rootfs(where the os and applications go). I am going to show all for lines of entry, then explain them.

,356,6
,,L
,,
,,

Ok, sfdisk is configured with three items per line sepearted by ",". The first item is the starting point. We leave it blank to use default, or the next point in line. The second spot is the ending spot. In the first line I defined it to stop 356 megs into the card and in the second left it blank because I wanted to use the rest of the space. The third spot is for filesystem type. 6 is a fat16 type and L is a linux partition type(also called a type 83). The last two lines are completely empty because there is no where to start, and no where to end because there is no more space. When prompted to write the information you can type y. Don't worry about any warnings.. its an old format tool and not aware of the advances in linux.

Step 3: Formating the partitions

Now that our partitions are cut, we can begin to format them. Formating a partition gives it space usable by the OS.

The first partition we are going to format fat16 so that its usable by windows via usb and the tablets software can access it just like it could before you formated.

*The difference between the rootfs and the initfs is that the initfs is part of your firmware, replaced by flashing. It holds the kernel, that part of the unix OS that handles everything else. The rootfs is the userspace file system. All your applications, device files, program libraries etc go here. The following command will handle this

mkdosfs /dev/mmcblk0p1

As you recall mmcblk0p1 is the internal card, partition 1. The second partition we will format for the rootfs a filesystem type called EXT2.

mke2fs /dev/mmcblk0p2

mmcblk0p2 = second partition.

Now its all done. For the system to be able to recognize these partitions we have to reboot. The easiest way at this point is from the xterm using the shutdown command.

shutdown -r now

The -r means reboot, a -h would mean halt, or turn off. The "now" part defines when this action should happen. After reboot the first partition should operate just like the card did before the partitioning, and the second partition will be discussed in the next section

** Usual props to sites I get tablet info from
www.internettablettalk.com and www.maemo.org

Most of the information in this post was double checked from http://maemo.org/maemowiki/HowTo_EASILYPartition_your_MMC_card