Friday, August 24, 2007

Install Debian 4.0 in Compact Flash using Kubuntu 8.10

Here I am going to explain how to install Debian 4.0 in compact flash. First, you need card reader, compact flash with minimum capacity of 1 GB, and your favourite Linux distro.

I was using compact flash sandisk 2 GB capacity and kubuntu 8.10.

Let's get started.

Steps :
1. Put in your CF to your card reader, and plug the reader to your laptop or PC which using Linux. That compact flash should be detected in your laptop as /dev/sdb.

2. Log in to your linux from terminal as a root, and make new partition in CF. I used fdisk to do this.

# fdisk /dev/sdb

First, erase all your current partition in CF using the command "d". Then, make new primary partition (partition 1) using command "n". Next, use command "w" to display all your contents. I didn't use swap here because it could shorten the CF usage.

3. Format your CF and make ext3 in partition 1

# mkfs.ext3 /dev/sdb1

4. Mount your CF to target folder. I used this target folder to install Debian later.

# mkdir /mnt/debian
# mount /dev/sdb1 /mnt/debian

5. Install debootstrap in your Linux distro. Debootstrap will be used to install Debian to your CF. I used Kubuntu, so the command should be like this :

# apt-get install debootstrap

After you've installed debootstrap, now you can install those debian to CF directly from the debian official site. I used debian local mirror site for this one. You may used other than this.

# debootstrap - -arch i386 etch /mnt/debian

6. Log in as a root to your Debian that was mounted first to /mnt/debian

# chroot /mnt/debian /bin/bash

7. Make fstab file so folders will automount when startup

# nano etc/fstab

write these lines in that file
/dev/hda1 / ext3 defaults 0 0
tmpfs /tmp tmpfs size=128m, mode=1777 0 0
proc /proc proc defaults 0 0

8. Mount folder proc and check whether it has been mounted. If the folder is still empty, then it hasn't mounted yet.

# mount /proc
# ls /proc

9. Configure the interface

# nano etc/network/interfaces

10. Configure the DNS that will be used

# nano etc/resolf.conf

11. Set hostname and make new user

# echo Security-Debian > etc/hostname
# adduser wmn

12. Edit source list repository Debian

deb etch main contrib non-free
deb-src etch main contrib non-free

13. Install kernel and bootloader into CF. I was using grub here for bootloader.

# apt-get install initramfs-tools
# apt-get install linux-image-2.6-486 grub

Then, configure the grub bootloader.

# mkdir -p /boot/grub
# cp /usr/lib/grub/i386-pc/* /boot/grub
# nano boot/grub/menu.lst

Write these lines in menu.lst

default 0
timeout 5

serial -–unit=0 -–speed=19200 -–word=8 -–parity=no -–stop=1
terminal -–timeout=5 serial console

title Wireless Mesh Node - Security
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-486 root=/dev/hda1 ro console=tty0 console=ttyS0,19200n8
initrd /boot/initrd.img-2.6.18-6-486

14. Now we're ready to install grub. Exit from chroot and type this command to install it.

# exit
# grub-install - -no-floppy - -recheck - -root-directory=/mnt/debian /dev/sdb

15. After grub fully installed, go back as root to Debian and edit

# nano boot/grub/

Write these lines

(hdo) /dev/sda
(hd1) /dev/sdb

16. Edit file kernel-img so menu.lst will be updated automatically

# nano etc/kernel-img.conf

Write these lines

do_symlinks = Yes
do_initrd = Yes
do_bootloader = no
do_bootfloppy = no
link_in_boot = no
relative_links = Yes
postinst_hook = update-grub
postrm_hook = update-grub

17. Configure console serial in inittab

# nano etc/inittab

Write these lines

1:2345:respawn:/sbin/getty -L 19200 ttyS0 ansi

18. Quit from chroot and umount

# exit
# cd /
# umount /mnt/debian

Now, Debian has fully installed and you can boot it from laptop/PC or embedded devices.