Bootstrapping ubuntu server on an external drive
I have a new 2TB drive that I am going to use to replace a drive on a much used server that is currently running gentoo (which I have increasingly less time to tend). So. I have this new drive in an external enclosure, and I want to bootstrap it with the new OS without having to do that “go reboot your computer with a USB key thing”. I want my OS on the disk, I want to test that all the services can be coerced to behave the way I need them to behave, and I want to do all this with a minimum of fuss and gymnastics.
This whole setup is now sitting next to me crunching away, and as it is a combination of my experience bootstrapping gentoo in a chroot, and some of the (off the beaten path) instructions for creating debian chroots, I thought I'd throw them together in one place in case they help someone else out.
So, to get this working (my target is ubuntu trusty (server), and I'm working from ubuntu precise (desktop), you can swap as appropriate):
- I am fundamentally lazy, and hate having to type sudo all the time.
sudo /bin/bash
- Get your drive configured.
In this case, I'm only going to use a small chunk of the 2TB for the OS so I can get things prepped, and then do some insane moving around of data once I have things going. Use your favorite tool for this, there are lots. - Mount your target partition where you want it, let's say /mnt/trusty
- Make sure you have debootstrap
The instructions on the page are good, for me:
apt-get install debootstrap
- I did not bother with schroot, because that setup isn't what I'm after. debootstrap is enough.
- Use debootstrap to bootstrap your new OS on the mounted partition. This is roughly akin to gentoo's stage3 tarball extract:
debootstrap trusty /mnt/trusty http://archive.ubuntu.com/ubuntu/
And off it goes setting up the fundamentals of a new/fresh OS installation on your new shiny partition. Fun! - As it says on the debootstrap page above, there are a few more things you need to do to make this a usable chroot you can then use to set up your new system (install services, test configuration, blahblah)
cp -L /etc/resolve.conf /mnt/trusty/etc/
— copy the resolv.conf file which contains the DNS information we need- Mount certain filesystems so things function properly, namely:
mount -t proc proc /mnt/trusty/proc
mount -t sysfs sys /mnt/trusty/sys
mount --bind /dev /mnt/trusty/dev
mount --bind /dev/pts /mnt/trusty/dev/pts
- Chroot into the new file system, so you can then do some stuff.
chroot /mnt/trusty /bin/bash
- Start setting up your new OS! Good recommendations:
apt-get update
- If you get messages about unknown keys, use the following to rectify, and then run update again:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <the number from the message>
- If you get messages about unknown keys, use the following to rectify, and then run update again:
Cheers!
p.s. You might also be able to do this from the distribution .iso, a la
debootstrap --arch i386 feisty /mnt/target file:/mnt/iso
I didn't try it, so YMMV
p.p.s. also: