Weblog entry #3 for figjam
#3
amd64 and i386 on a USB key
Posted by figjam on Fri 2 May 2008 at 10:50
I sometimes need to boot machines with an external device that has all the tools I need to repair it. After mucking around with various live solutions, I have found the easiest and most flexible solution is to simply bootstrap the installations into separate partitions and install grub.
I'm using a 2GB key (device is /dev/sda on my machine), so I partition it up as follows:
/dev/sda1 100MB (shared /boot)
/dev/sda2 900MB (amd64)
/dev/sda3 900MB (i386)
Those figures aren't exact, it's basically a case of 100MB for /boot and split the rest of the key between the other two partitions.
Next I use e2label to name the partitions as boot, amd64 and i386. If you're updating or working on the key itself it just makes it easier. You can also use "mount -L label /dir" instead of the devicename if you want.
e2label /dev/sda1 boot
e2label /dev/sda2 amd64
e2label /dev/sda3 i386
Format the partitions up as ext3:
mkfs.ext3 /dev/sda1
mkfs.ext3 /dev/sda2
mkfs.ext3 /dev/sda3
Mount the partitions we need for the amd64 (64bit) installation on /mnt:
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /boot
Install a very minimal set of packages with debootstrap:
/usr/sbin/debootstrap --arch amd64 etch /mnt http://http.us.debian.org/debian
Find and make a note of the filesystem uuids on the USB key. We need them because if you are using the key on machines with varying numbers of SATA hard drives, you can't guarantee which device will be assigned to your key. This causes lots of problems with grub and fstab.
tune2fs -l /dev/sda1 | grep -i uuid
Filesystem UUID: d386494f-c4f5-4e69-8fdc-6741797e521e
tune2fs -l /dev/sda2 | grep -i uuid
Filesystem UUID: fcdf1bde-c16f-4cf3-9e66-248b9f40741a
tune2fs -l /dev/sda3 | grep -i uuid
Filesystem UUID: 5dc6ba69-719b-4461-af40-7b8b0dd83bd4
Chroot into the new installation to set up a few things.
LANG=C chroot /mnt /bin/bash
Make a basic fstab
vi /etc/fstab
Copy and paste the following, replacing the uuids with the ones from your key.
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
UUID=63c0907e-3d17-4124-b8ca-74d6c22bf057 /boot ext3 defaults 0 2
UUID=84db6c63-1f99-43f3-8025-9e78dd59d8aa / ext3 defaults,errors=remount-ro 0 1
Make a basic interface config.
vi /etc/network/interfaces
Copy and paste.
auto eth0
iface eth0 inet dhcp
Create /etc/resolv.conf
vi /etc/resolv.conf
Configure a couple of nameservers.
nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy
Set the hostname.
echo "usb-amd64" > /etc/hostname
Add localhost to /etc/hosts
vi /etc/hosts
127.0.0.1 localhost
Create /etc/apt/sources.list
vi /etc/apt/sources.list
Copy and paste the following:
deb http://http.us.debian.org/debian etch main contrib non-free
deb-src http://http.us.debian.org/debian etch main contrib non-free
deb http://security.debian.org/ etch/updates main contrib non-free
deb-src http://security.debian.org/ etch/updates main contrib non-free
Run the following commands:
apt-get update
apt-get install console-data locales
Select "Don't touch keymap" when prompted.
dpkg-reconfigure locales
Depending on where you are, select the appropriate locales. The ones I use are:
[*] en_GB ISO-8859-1
[*] en_GB.ISO-8859-15 ISO-8859-15
[*] en_GB.UTF-8 UTF-8
[*] en_IE@euro ISO-8859-15
[*] en_NZ ISO-8859-1
[*] en_NZ.UTF-8 UTF-8
[*] en_US ISO-8859-1
[*] en_US.ISO-8859-15 ISO-8859-15
[*] en_US.UTF-8 UTF-8
Create /etc/kernel-img
vi /etc/kernel-img.conf
Copy and paste the following:
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = yes
relative_links = yes
do_bootloader = yes
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
Install the kernel, grub and mdadm
apt-get install linux-image-amd64 grub mdadm
Select (or type in) all when prompted for: MD arrays needed for the root filesystem
(Ignore the mdadm errors)
Exit the chroot:
exit
Install grub:
grub-install --no-floppy --recheck --root-directory=/mnt /dev/sda
Re-enter the chroot:
LANG=C chroot /mnt /bin/bash
Create the boot menu/options:
update-grub
(press "y" when it asks: Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N)
Set grub to use the UUIDs.
vi /boot/grub/menu.lst
Find the line that starts with: # kopt=root=/dev/something ro
Replace the /dev/something with the uuid for your root filesystem (/dev/sda1 in my case).
# kopt=root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro
Find the menu entries at the end of the file:
title Debian GNU/Linux, kernel 2.6.18-6-amd64
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-amd64 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.18-6-amd64
savedefault
title Debian GNU/Linux, kernel 2.6.18-6-amd64 (single-user mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-amd64 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.18-6-amd64
savedefault
Remove /boot on the lines beginning with "kernel" and "initrd".
On the kernel lines, replace /dev/something as you did for the "kopt" line. They should look something like this when finished:
title Debian GNU/Linux, kernel 2.6.18-6-amd64
root (hd0,0)
kernel /vmlinuz-2.6.18-6-amd64 root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro
initrd /initrd.img-2.6.18-6-amd64
savedefault
title Debian GNU/Linux, kernel 2.6.18-6-amd64 (single-user mode)
root (hd0,0)
kernel /vmlinuz-2.6.18-6-amd64 root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro single
initrd /initrd.img-2.6.18-6-amd64
savedefault
Update /etc/kernel-img.conf
vi /etc/kernel-img.conf
Change do_bootloader = yes to: do_bootloader = no
Paste the following to the end of the file:
## Automatically update /boot/grub/menu.lst on
## installation or removal of Debian kernels.
postinst_hook = update-grub
postrm_hook = update-grub
Install any additional packages you want such as iproute, psmisc, lvm2, xfsprogs, less and exit the chroot. You should now be able to boot on the key.
Once you have booted on the key and checked it works, repeat the process to install i386 on the third partition (/dev/sda3 in my case). Mount /dev/sda1 as /mnt/boot again and use i386 instead of amd64 in the debootstrap command. This has become an extremely useful tool to me in my job.
I'm using a 2GB key (device is /dev/sda on my machine), so I partition it up as follows:
/dev/sda1 100MB (shared /boot)
/dev/sda2 900MB (amd64)
/dev/sda3 900MB (i386)
Those figures aren't exact, it's basically a case of 100MB for /boot and split the rest of the key between the other two partitions.
Next I use e2label to name the partitions as boot, amd64 and i386. If you're updating or working on the key itself it just makes it easier. You can also use "mount -L label /dir" instead of the devicename if you want.
e2label /dev/sda1 boot
e2label /dev/sda2 amd64
e2label /dev/sda3 i386
Format the partitions up as ext3:
mkfs.ext3 /dev/sda1
mkfs.ext3 /dev/sda2
mkfs.ext3 /dev/sda3
Mount the partitions we need for the amd64 (64bit) installation on /mnt:
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /boot
Install a very minimal set of packages with debootstrap:
/usr/sbin/debootstrap --arch amd64 etch /mnt http://http.us.debian.org/debian
Find and make a note of the filesystem uuids on the USB key. We need them because if you are using the key on machines with varying numbers of SATA hard drives, you can't guarantee which device will be assigned to your key. This causes lots of problems with grub and fstab.
tune2fs -l /dev/sda1 | grep -i uuid
Filesystem UUID: d386494f-c4f5-4e69-8fdc-6741797e521e
tune2fs -l /dev/sda2 | grep -i uuid
Filesystem UUID: fcdf1bde-c16f-4cf3-9e66-248b9f40741a
tune2fs -l /dev/sda3 | grep -i uuid
Filesystem UUID: 5dc6ba69-719b-4461-af40-7b8b0dd83bd4
Chroot into the new installation to set up a few things.
LANG=C chroot /mnt /bin/bash
Make a basic fstab
vi /etc/fstab
Copy and paste the following, replacing the uuids with the ones from your key.
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
UUID=63c0907e-3d17-4124-b8ca-74d6c22bf057 /boot ext3 defaults 0 2
UUID=84db6c63-1f99-43f3-8025-9e78dd59d8aa / ext3 defaults,errors=remount-ro 0 1
Make a basic interface config.
vi /etc/network/interfaces
Copy and paste.
auto eth0
iface eth0 inet dhcp
Create /etc/resolv.conf
vi /etc/resolv.conf
Configure a couple of nameservers.
nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy
Set the hostname.
echo "usb-amd64" > /etc/hostname
Add localhost to /etc/hosts
vi /etc/hosts
127.0.0.1 localhost
Create /etc/apt/sources.list
vi /etc/apt/sources.list
Copy and paste the following:
deb http://http.us.debian.org/debian etch main contrib non-free
deb-src http://http.us.debian.org/debian etch main contrib non-free
deb http://security.debian.org/ etch/updates main contrib non-free
deb-src http://security.debian.org/ etch/updates main contrib non-free
Run the following commands:
apt-get update
apt-get install console-data locales
Select "Don't touch keymap" when prompted.
dpkg-reconfigure locales
Depending on where you are, select the appropriate locales. The ones I use are:
[*] en_GB ISO-8859-1
[*] en_GB.ISO-8859-15 ISO-8859-15
[*] en_GB.UTF-8 UTF-8
[*] en_IE@euro ISO-8859-15
[*] en_NZ ISO-8859-1
[*] en_NZ.UTF-8 UTF-8
[*] en_US ISO-8859-1
[*] en_US.ISO-8859-15 ISO-8859-15
[*] en_US.UTF-8 UTF-8
Create /etc/kernel-img
vi /etc/kernel-img.conf
Copy and paste the following:
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = yes
relative_links = yes
do_bootloader = yes
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
Install the kernel, grub and mdadm
apt-get install linux-image-amd64 grub mdadm
Select (or type in) all when prompted for: MD arrays needed for the root filesystem
(Ignore the mdadm errors)
Exit the chroot:
exit
Install grub:
grub-install --no-floppy --recheck --root-directory=/mnt /dev/sda
Re-enter the chroot:
LANG=C chroot /mnt /bin/bash
Create the boot menu/options:
update-grub
(press "y" when it asks: Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N)
Set grub to use the UUIDs.
vi /boot/grub/menu.lst
Find the line that starts with: # kopt=root=/dev/something ro
Replace the /dev/something with the uuid for your root filesystem (/dev/sda1 in my case).
# kopt=root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro
Find the menu entries at the end of the file:
title Debian GNU/Linux, kernel 2.6.18-6-amd64
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-amd64 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.18-6-amd64
savedefault
title Debian GNU/Linux, kernel 2.6.18-6-amd64 (single-user mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-amd64 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.18-6-amd64
savedefault
Remove /boot on the lines beginning with "kernel" and "initrd".
On the kernel lines, replace /dev/something as you did for the "kopt" line. They should look something like this when finished:
title Debian GNU/Linux, kernel 2.6.18-6-amd64
root (hd0,0)
kernel /vmlinuz-2.6.18-6-amd64 root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro
initrd /initrd.img-2.6.18-6-amd64
savedefault
title Debian GNU/Linux, kernel 2.6.18-6-amd64 (single-user mode)
root (hd0,0)
kernel /vmlinuz-2.6.18-6-amd64 root=UUID=fcdf1bde-c16f-4cf3-9e66-248b9f40741a ro single
initrd /initrd.img-2.6.18-6-amd64
savedefault
Update /etc/kernel-img.conf
vi /etc/kernel-img.conf
Change do_bootloader = yes to: do_bootloader = no
Paste the following to the end of the file:
## Automatically update /boot/grub/menu.lst on
## installation or removal of Debian kernels.
postinst_hook = update-grub
postrm_hook = update-grub
Install any additional packages you want such as iproute, psmisc, lvm2, xfsprogs, less and exit the chroot. You should now be able to boot on the key.
Once you have booted on the key and checked it works, repeat the process to install i386 on the third partition (/dev/sda3 in my case). Mount /dev/sda1 as /mnt/boot again and use i386 instead of amd64 in the debootstrap command. This has become an extremely useful tool to me in my job.