installing Debian with debootstrap and LNX-BBC
Kragen Javier Sitaker
kragen at pobox.com
Mon Feb 19 03:37:02 EST 2007
I'm installing Debian on a machine remotely using debootstrap from
LNX-BBC. Here are my notes.
LNX-BBC automatically mounts your disks:
cd /mnt/rw/discs/disc0/part1
But we have to remount them read-write:
mount -no remount,rw .
Then download debootstrap according to
http://www.debian.org/releases/stable/i386/apcs04.html.en --- although
probably http://www.debian.org/releases/etch/i386/apds03.html.en is
better now! (These are chapters of the Debian GNU/Linux Installation
Guide.)
mkdir debootstrap
cd debootstrap
wget http://ftp.debian.org/debian/pool/main/d/debootstrap/debootstrap_0.3.3.1_all.deb
ar -x debootstrap_0.3.3.1_all.deb
Can't extract data.tar.gz in the root directory (read-only filesystem)
so I am hoping to use DEBOOTSTRAP_DIR to enable debootstrap to find it
here:
tar xzvf data.tar.gz
export DEBOOTSTRAP_DIR=/mnt/rw/discs/disc0/part1/debootstrap/usr/lib/debootstrap
usr/sbin/debootstrap --arch i386 etch /mnt/rw/discs/disc0/part1 \
http://http.us.debian.org/debian
I think this didn't succeed, because of this message:
I: Installing core packages...
W: Failure trying to run: chroot /mnt/rw/discs/disc0/part1 dpkg --force-depends --install var/cache/apt/archives/base-files_4_i386.deb var/cache/apt/archives/base-passwd_3.5.11_i386.deb
It looks like it may have failed because of a PATH problem:
[root at lnx-bbc:/mnt/rw/discs/disc0/part1/debootstrap]# chroot \
/mnt/rw/discs/disc0/part1 dpkg --force-depends \
--install var/cache/apt/archives/base-files_4_i386.deb \
var/cache/apt/archives/base-passwd_3.5.11_i386.deb
chroot: cannot execute dpkg: No such file or directory
That's because dpkg is in /usr/bin, and /usr/bin isn't in the $PATH on
LNX-BBC. So I repeat the process:
export PATH=/usr/bin:$PATH
usr/sbin/debootstrap --arch i386 etch /mnt/rw/discs/disc0/part1 http://http.us.debian.org/debian
Same problem, but this time when I try running dpkg by hand, it says:
dpkg: `install-info' not found on PATH.
dpkg: `update-rc.d' not found on PATH.
dpkg: 2 expected program(s) not found on PATH.
NB: root's PATH should usually contain /usr/local/sbin,
/usr/sbin and /sbin.
And in this case, the absence of /usr/sbin is the problem.
export PATH=/usr/sbin:$PATH
and this time I get
I: Base system installed successfully.
And I'm in:
[root at lnx-bbc:/mnt/rw/discs/disc0/part1/debootstrap]# LANG= chroot .. /bin/bash
So I can
apt-get update
apt-get install vim
vim /etc/fstab
and I put these in my fstab:
/dev/hda1 / ext3 defaults 0 1
/dev/hdb1 /bigdisk ext3 defaults 0 2
/dev/hdb2 /bigdisk2 ext3 defaults 0 2
proc /proc proc defaults 0 0
/dev/fd0 /mnt/floppy auto noauto,rw,sync,user,exec 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,ro,user,exec 0 0
I didn't include /sys, /dev, /dev/pts, /proc/bus/usb, /tmp, or
/dev/shm in the fstab because they aren't in it on my other Debian
system. I didn't include swap because there's no free space on the
disk, and I figure I can use a swapfile anyway. Later.
And then I
mount /proc
I'm kind of guessing about the device names, since LNX-BBC uses devfs,
but this seems to suggest that they are correct:
root at lnx-bbc:/# cat /proc/ide/ide0/hda/model
ST3200826A
root at lnx-bbc:/# cat /proc/ide/ide0/hdb/model
WDC WD800JB-00ETA0
Then
apt-get install console-data # and select qwerty, US American
And then I put this into /etc/network/interfaces:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
Vim kept complaining about not being able to put stuff in
/home/root/.viminfo, which is under LNX-BBC's $HOME, so I did this:
ln -s /root /home/root
I'm pretty sure I'll need "alias eth0 8139too" in /etc/modules.conf or
whatever its modern equivalent is, because apparently the RealTek
8139-based Ethernet card that's in the machine doesn't get
auto-detected; from the LNX-BBC boot:
8139too Fast Ethernet driver 0.9.25
PCI: Found IRQ 5 for device 02:08.0
PCI: Sharing IRQ 5 with 00:02.0
eth0: SMC1211TX EZCard 10/100 (RealTek RTL8139) at 0x1000,
00:10:b5:ec:xx:xx, IRQ 5
eth0: Identified 8139 chip type 'RTL-8139C'
eth0: Setting 100mbps full-duplex based on auto-negotiated
partner ability 45e1.
eth0: no IPv6 routers present
First I have to figure out what the modern equivalent of modules.conf
is, though. For now:
echo 8139too >> /etc/modules
Then
echo gentle.murch-sitaker.org>/etc/hostname
tzconfig
vi /etc/hosts # and paste in the standard hosts, changing DebianHostName
vi /etc/apt/sources.list # and paste in the standard sources
aptitude update
aptitude install locales
dpkg-reconfigure locales # install all, select en_US.UTF-8
It was probably a mistake to install all locales, because it took a
long time to build them all. (The CPU on this old machine is fairly
slow.)
Then to install a kernel and a bootloader:
aptitude install kernel-package
aptitude install screen # so i can read a man page while editing the file
mount -t devpts devpts /dev/pts # to get screen to work
screen
vi /etc/kernel-img.conf # and I put the following in it:
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
warn_initrd = no
postinst_hook = update-grub
postrm_hook = update-grub
aptitude install kernel-image-2.6-386 # this failed due to no grub
aptitude install grub
mknod /dev/hda b 3 0
But then I ran into trouble:
lnx-bbc:/# grub-install /dev/hda
Probing devices to guess BIOS drives. This may take a long time.
Could not find device for /boot: Not found or not a block device.
So I thought maybe I'd strace it.
aptitude install strace
resulted in some more progress on the kernel front:
Could not find /boot/grub/menu.lst file. Would you like
/boot/grub/menu.lst generated for you? (y/N) y
At this point, it hung, and I started to get the idea that aptitude
really isn't better than apt-get after all. I control-Ced it, and it
installed strace and tried again. This time I had strace, but it
wasn't helpful to diagnose the hang.
The main thing strace told me about the grub-install problem was that
grub-install was a shell script. I read some of it, but it's 500+
lines long, so I gave up before understanding clearly what was going
on.
So I gave up on grub and decided to switch to lilo.
aptitude remove grub
vi /etc/kernel-img.conf # remove the *hook lines, set do_bootloader=yes
aptitude install lilo
vi /etc/lilo.conf # and put the following in it:
boot=/dev/hda
root=/dev/hda1
install=menu
delay=20
lba32
image=/vmlinuz
label=Debian
lilo # but this produces an error:
Warning: '/proc/partitions' does not match '/dev' directory structure.
Name change: '/dev/hdc' -> '/dev/hdc'
part_nowrite check:: No such file or directory
(XXX I am hoping that the "lba32" in there is correct.)
I am hypothesizing that this error is from /dev/hda1 not existing, so:
mknod /dev/hda1 b 3 1
lilo
This does seem to improve things:
Warning: '/proc/partitions' does not match '/dev' directory structure.
Name change: '/dev/hdc' -> '/dev/hdc'
Cannot proceed maybe you need to add this to your lilo.conf:
disk=/dev/hdb inaccessible
(real error shown below)
Fatal: open /dev/hdb: No such file or directory
I don't know why it thinks it should be touching /dev/hdb or /dev/hdc,
but I'll go ahead and let it:
mknod /dev/hdb b 3 64
mknod /dev/hdb1 b 3 65
mknod /dev/hdb2 b 3 66
mknod /dev/hdc b 22 0
lilo
And this time it seems to have been successful:
Warning: '/proc/partitions' does not match '/dev' directory structure.
Name change: '/dev/ide/host0/bus0/target0/lun0/disc' -> '/dev/hda'
Added Debian *
Now I exit from the screen and the chrooted shell in order to see my
disk-space status; there appears to be plenty of space left. So I try
the 'tasksel install standard' recommendation from the manual.
LANG= chroot .. /bin/bash
tasksel install standard
But this installs SELinux and Exim, among other things. So:
apt-get remove exim4 # doesn't work
apt-get remove exim4-base # works but uninstalls at, mailx, and mutt
apt-get remove selinux-policy-refpolicy-targeted
Then I needed to remember to install sshd:
apt-get install openssh-server
Then I noticed (via netstat -an) that there were some sockets, so I
lsof | grep TCP and | grep UDP to see who they were. They were
portmap and rpc.statd, so I removed them:
apt-get remove nfs-common portmap
That didn't work --- hung forever trying to stop the portmap daemon.
I ended up killing the process by hand, removing /sbin/portmap, and
then re-removing the package.
Then I figured I'd update the passwd, shadow, and group files so I
could log in; I merged the original versions with the newer ones.
Then I overwrote the stuff in /etc/ssh with the old versions:
lnx-bbc:/kragen/gentle-backup/etc/ssh# cp * /etc/ssh
Hope that's compatible!
Just to test, I used ps x | grep ssh to find the pids of the LNX-BBC
shell process, and then inside screen, I ran this command:
kill -9 641 666; /etc/init.d/sshd start
It worked in the sense that I now had an ssh server running in the
environment that I hoped would become the new system, but it was a
mistake in the sense that I hadn't yet installed sudo! So I asked my
friend with physical access to run these commands before we reboot,
which worked:
chroot /mnt/rw/discs/disc0/part1 apt-get install sudo
chroot /mnt/rw/discs/disc0/part1 visudo # and add me!
It didn't reboot properly --- LILO died with L 00 00 00 ... --- but
LBA wasn't enabled in the BIOS. While debugging this, my friend found
an error in the Portuguese translation of the BIOS. We gave up
debugging it for a while.
Because the machine was down for a long time, the DHCP server gave it
a different address, so I put the new address into DNS.
Now I have a problem; my server is running inside a chroot, but I
can't mount the partitions /bigdisk and /bigdisk2 inside the chroot
because they are already mounted outside of it; and I can't unmount
them because "umount" can't see them.
Apparently even the Linux 2.4.19 used by LNX-BBC does this clever
thing where you can't see /proc/*/cwd for processes chrooted somewhere
above you, so I can't "sudo chroot /proc/1/root bash". However, the
standard C approach to breaking out of the chroot does work (here
without error handling for brevity):
chroot(argv[1]);
chdir("../../../../../../../../../..");
chroot(".");
execl(argv[2], argv[2], 0);
I was going to do things the hard way and inject code into a process
running outside the chroot by means of gdb, but then I added
error-checking to the C code and got it working.
sudo ./unchroot flickr-interesting/ /bin/bash
# and then unmount things in the resulting root shell
sudo mount /bigdisk
sudo mount /bigdisk2
sudo /etc/init.d/chrooted-apache start # this is me-specific
And now my web server is back up and running, for now.
More information about the Kragen-tol
mailing list