Leandro Dorileo

Dorileo`s web place

I needed to prepare a usb flash memory stick to boot, I need it to test the implementation I`m working on for my GSoC project. I recalled the things I learned when I used to be a gentoo user in 2003/2004. That time we needed to install and prepare all the system from scratch by hand, but this is one another history.

Note-1: I assume you know how to use [c]fdisk, debootstrap, chroot, and understand what a partition table means. ;-)

Note-2: These are just few notes I did while preparing my environment, it wasn`t based on some other tutorial or how-to, so you may find better tips and techniques for taking the same results;

Here we go:

1- Plug the stick and delete/create the partitions, for example;

su
cfdisk /dev/sdb2

Log in as root and create the partitions as you want.

I always use to have at least two partitions an 100Mb ext2 partition for /boot dir and the remaining space to root file system - of course it depends on your system usage.

2 - make the file systems;

mkfs.ext2 /dev/sdb1
mkfs.ext3 /dev/sdb2

I created two partitions, sdb1 the boot partition and sdb2 for root file system.

3 - mount your partitions somewhere;

mkdir /media/f-stick
mount /dev/sdb2 /media/f-stick
mkdir /media/f-stick/boot
mount /dev/sdb1 /media/f-stick/boot 
mount proc /media/f-stick/proc -t proc
mount sys /media/f-stick/sys -t sysfs

Mounted the boot and root filesystem, the proc and sysfs as well.

4 - now we have all the needed partitions mounted. Time to prepare the basic system;

apt-get install debootstrap
debootstrap sid /media/f-stick http://ftp.us.debian.org/debian/

Install debootstrap if you don`t have it already and use it to create the basic system. Please read the debootstrap`s manpage for detailed informations on its usage.

5 - chroot your brand new system and maintain it:

cp /etc/hosts /media/f-stick/etc/hosts
chroot /media/f-stick /bin/bash
apt-get install less grub linux-image-2.6-686
exit

Install some basic softwares, debootstrap will not install a linux kernel for you neither a boot loader.

6 - install grub stage1 to your stick`s mbr:

grub-install --root-directory=/media/f-stick /dev/sdb

7 - edit the device.map and leave only hd0 sdb;

vim /media/f-stick/boot/grub/device.map

8 - chroot again and set things up, like root password, add a new user, set its password and so on;

update-grub couldn`t probe the devices and define the sdb device, so it didn`t generate the menu.lst on my system, but I copied it from my main box and edited it to fit my needs.

A friend asked me few days ago to write down some “necessary commands” to work with Ubuntu, well you really need to know how manage your packages, then I wrote him a list like follows:

apt-get update
Downloads and sync your copy of index files, your system must know what is available.

apt-get dist-upgrade
upgrades all your packages to the newest versions.

apt-cache search [expression]
Searches for packages with description, name, etc matching with [expression]

apt-cache policy [package_name]
Shows installed and candidate versions of a given package

dpkg -l [expression] | grep ii
Shows installed packages matching [expression]

dpkg -L [package_name]
Lists all packages installed by a given package

apt-file update
Like apt-get update it downloads indexes of a kind of “reverse” files -> package relation

apt-file find [expression]
Lists all packages which install files matching [expression]

apt-get install [package_name]
Installs or updates a package

apt-get remove [package_name]
Removes/uninstalls a package

I think with those commands you can play a lot with Debian/Ubuntu etc. Now go to your desk and make your homework, try each one of the listed commands.