BIPEDU

my ideas in action

Monthly Archives: July 2013

install Debian on USB stick for a ATOM board based server

I have a Intel ATOM board D525MW and I use this for a small home server. Normally the Intel support for Linux is not great but the ATOM boards are special. They are forced (by Intel) to boot only from disks that have FAT bootable partition. So how to install Linux ( Debian Wheezy in my case) ? First I have to trick the ATOM board BIOS to think that the USB stick boots from FAT partition . To do this I have to create a small ( 10MB ) partition formatted with FAT16. I set this to be bootable. But the partition is empty and is never used. Then I create a second partition with EXT2 ( or ext3, ext4…) and I install my Debian on it. So the Debian system will be installed in to a second partition.
How to create a USB stick with this arrangement ? Answer : with fdisk.

Insert the USB stick into a USB port and from linux terminal type (you must be root !):

# fdisk /dev/sdb (or sdc or sdd or whatever is the device name in your case)

then delete (d) all the partitions and create (n) a new FAT16 partition with 10MB and set it bootable

Then write (w) the changes to the disk and unplug the USB stick.

Then plug it again so that the OS read the new partition.

Then create (n) a second partition in the available space. For this use a Linux compatible format like ext2, ext3 or ext4. You can create now any partition scheme you want.

Then write (w) the changes to the disk and unplug the USB stick.

Then plug it again.

Now you are ready to format the partitions.

Use mkfs.msdos to format the FAT16 partition

example of the command used :

# mkfs.msdos -v -F 16  -n LABEL /dev/sdb1

Use mkfs.ext2 to format the second partition with command:

# mkfs.ext2 -v /dev/sdb2

Then umount the USB stick and unplug and plug it again.

Now you are ready to install the Debian ( or whatever distro you want). As a reminder the special arrangement with FAT16 partition is only for Intel ATOM boards because the manufacturer did not solved yet this BIOS bug.

The Debian installation is using debootstrap method. In this method the Debian OS is installed directly on a USB stick. The is no Live install ,there is no CD/DVD involved, there is no ISO burning. You need just a Linux machine, a internet connection and a USB stick formatted like described above.

First create a empty folder to mount the USB stick (preferable on /tmp/usb ). I will assume here that the USB stick is sdb and the sdb1 is FAT16 and sdb2 is ext2 partition. I will assume that we install Debian Wheezy 32bit (i386) with GRUB and no GUI, standard system . The only server installed will be SSH but from there you can add whatever you want ( FTP, Samba, Web , …). All the commands below are run from root account.

# mount /dev/sdb2 /tmp/usb/
# debootstrap --arch=i386 wheezy /tmp/usb/ http://ftp.be.debian.org/debian

adapt the command to your needs. read “man debootstrap” if you are not sure. This step will take some time ( 20-30 minutes depending on your network speed)

Then configuration of the new Debian image.

# mount -t proc none /tmp/usb/proc
# mount -t sysfs none /tmp/usb/sys
# mount -o bind /proc /tmp/usb/proc
# mount -o bind /dev /tmp/usb/dev
# mount -o bind /sys /tmp/usb/sys
# LANG=C chroot /tmp/usb/ /bin/bash

Now you enter in chroot mode. The commands that you execute now are inside the new Debian Wheezy OS.

root@debian # mount devpts /dev/pts  -t devpts
root@debian # blkid

the purpose is to find UUID identifier of the dev/sdb2 partition because we will need later the UUID code.

To edit the configuration files you can use various methods: nano, vi, etc… ( personaly I prefere nano)

next edit the /etc/fstab file

root@debian # nano /etc/fstab

and add there the folowing :

# UNCONFIGURED FSTAB FOR BASE SYSTEM
proc /proc proc defaults 0 0
UUID=insert-here-your-UUID / ext2 defaults,noatime 0 1
#/dev/sda1 / ext3 defaults,noatime 0 1
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/tmp tmpfs defaults,noatime 0 0
tmpfs /var/run tmpfs defaults 0 0
tmpfs /var/log tmpfs defaults 0 0
tmpfs /var/lock tmpfs defaults 0 0

Then edit your network card config file: nano /etc/network/interfaces

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp

Then configure your local timezone with

root@debian # dpkg-reconfigure tzdata

then edit you server network name ( the machine name in the local network)

root@debian # nano /etc/hostname

Then edit the sources.list for the apt-get/aptitude:

root@debian # nano /etc/apt/sources.list

add there the folowing (edit them to match your needs) :

deb http://ftp.be.debian.org/debian wheezy main
deb-src http://security.debian.org/ wheezy/updates main
deb http://secirity.debian.org/ wheezy/updates main

Then make refresh for the aptitude packages with:

root@debian # aptitude update

next install the locales :

root@debian # aptitude install locales
root@debian # dpkg-reconfigure locales

Next install console-data, linux image and grub:

root@debian # aptitude install console-data
root@debian # aptitude install linux-image-486
root@debian # aptitude install grub

next edit the grub config file like this:

root@debian # nano /etc/default/grub

and inside add something like this :

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
#GRUB_CMDLINE_LINUX_DEFAULT="verbose console=ttyS0,38400n8 reboot=bios"
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=38400"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
GRUB_TERMINAL=console
#GRUB_TERMINAL=serial

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Then open a new terminal in your Linux machine ( outside the chroot !) and add this in the /boot/grub/device.map :

(hd0) /dev/sdb

Then update the grub configuration (you are now back on the chroot environment) :

root@debian # grub-install /dev/sdb
root@debian # update-grub

Please check and edit the /boot/grub/device.map so that your USB stick is on hd0 and not hd1.

Then check if you have hd1 in the /boot/grub/grub.cfg. If yes then please replace it with hd0

Now change the root password for your new Debian Wheezy:

root@debian # passwd root

Next install the utility packages like sudo, ssh-server, standard Debian packages…or whatever you want to install :

root@debian # aptitude install rsyslog sudo
root@debian # tasksel install standard
root@debian # tasksel install ssh-server

now the installation is finished and you need to exit from chroot environment. Please be careful that if you do not use the correct exit method you can damage the newly installed OS.

So do :

root@debian # umount /dev/pts
root@debian # exit

So now you are not in chroot anymore and you are back at your linux terminal.

Now umount :

# umount /tmp/usb/proc/
# umount /tmp/usb/sys
# umount /tmp/usb/dev
# umount /tmp/usb
# umount /dev/sdb2

Now you are ready to unplug the USB stick and to use it on the ATOM board !

Advertisements