|HOWTO - Install Debian Onto a Remote Linux System|
HOWTO - Install Debian Onto a Remote Linux System
Back to Top
This document attempts to describe the steps required to change the Operating System running on a remote system to Debian. While tested under a Redhat system and also a bit under an existing system (woo! I converted Debian to... DEBIAN!), it should be applicable under any linux variant, and most likely other Unix's as well.
Also, this procedure should be applicable to installing any system that allows you to ssh (or maybe telnet - although not recommended) into it. It would also have to respect the chroot environment while installing. But why would you want a non-Debian server? :)
You need to have ROOT access to the server of course, and access to certain utilities.
Here's a few programs that I used, you may use any that can accomplish the same effect.
Everything else is downloaded and configured separately. I tried to think of as much detail as I could, but there's always another problem that might come up that I didn't see. Taking the proper precautions should allow you to recover from almost any situation however. But feel free to let me know of any ideas or problems you might have. Contact information is at the bottom
Also, be sure to read the references as well. They have a lot of useful information, and the Linux From Scratch book is a wonderful resource.
Back to Top
You may want to consider the possibility of making a cron job to reboot every 20 minutes or something just in case. Although if you have someone to do a reboot you will recover (as we will tell lilo to do a one time image).Exit the chroot. Start getting ready for the reboot. Copy over your kernel image from the chroot to your boot partition, tell your boot loader about your new partition. Also, if supported, tell your boot loader to reboot on a kernel panic, and to only boot into the new image once. Copy over your new lilo.conf (or whatever) to your new filesystem. Install your new boot map.
This way, only the next boot will be to the new OS, and any reboot or kernel problems will take you back to safety. Cool, huh? :)Unmount your new filesystem manually to be safe.
Now, we need to safely move the filesystem over to the main partition. And to do that we need a reboot, as certain things are in use, and it's just a safer way of doing it.Reboot! If all goes well you should be in your new OS. Albeit on the wrong partition. Otherwise, you'll have to reboot and figure out what went wrong. Now, mount your original partition and copy the new one over the original. Make sure you resize the filesystem if needed. Set up your bootloader and fstab to boot into the original partition again (copy the files over to the other partition). Make it so it will reboot back into the current partition if something goes wrong, as you know it to be working properly. Reboot part deux! Now you should be on the home stretch. Change your temporary partition back into swap, and make sure fstab reflects the changes. Redo your boot loader into a more permanent configuration. And that should be it! You can now configure your shiny new install.
Back to Top
In the following examples, the commands are shown literally, maybe with some context around them. The ``unf:~#'' would be my default prompt. Be SURE that you change any commands so they apply to your installation. Like don't use /dev/sda5 if that wasn't your swap partition.
If you have ANY doubts, ask someone who knows first to be sure.
Also, it is a good idea to try this first on a local computer that you don't have a problem with restoring if something goes wrong. If you have a copy, VMware <http://www.vmware.com/> is an excellent utility for testing. Try it at least once locally before you do it remotely, unless you have an easy way to recover the remote system if something goes wrong.
Also, this process is recoverable and shouldn't do any permanent damage until you go to reboot. More specifically, when you change lilo to point to the new partition. Even then, during the first boot you should be able to recover to your original install by using a ``panic='' line in lilo. That entry will automatically boot back to the old install if something goes wrong with the new kernel. You do however have to ensure network connectivity in the case of a successful boot, or you will have a working box that you can't access. :) However, if you can get someone to manually reboot it for you, you can recover from there as well. As the lilo command I use for the first time will only take effect once. But more on that later.
NOTE: Any lines starting with ``>'' are most likely shell continuation lines. When you end a shell command with ``&&'', ``\'', or using a ``heredoc'' syntax (>> ``EOF'') it will give you a new line to type. Don't type in the ``>'' character literally. One way to avoid this is if you type/paste one line at a time (rather then pasting multiple lines at once) when entering multiline commands. I know some of you are a bit impatient, so was just heading off a potentially hard to track down error. ;)
Also, make sure you note down any vital information. Specifically your network configuration, partition arrangement, and hardware. Most hardware you don't have to worry about on the server except the network card, which makes things easier. I'll be using my own hardware in the examples, so make sure you change the data appropriately.
To install debian into the chroot, you can use a number of ways. The easiest is probably to use debootstrap. Debootstrap is a very nice little program that will configure your chroot for you with the debian base packages, which it will download and install for you.
You can get an rpm of debootstrap here:
Due to the recent problems with p.d.o., I have a secondary copy I made (alien -rkv debootstrap*.deb) That you can use. The first is current as of this time from unstable. The second is from woody, and should work with older versions of glibc. Try the first link, and use the second if that doesn't work.
You can use wget/scp/ftp or whatever to get it on your shell. OR you can just enter the URL manually in RPM. You may want to verify the version from the above url. The filename below was the current one at the time of this writing.
To install with rpm:
unf:~# rpm -ivh \ > http://people.debian.org/~blade/install/debootstrap/debootstrap-0.1.16.4-2.i386.rpm
If you downloaded the rpm manually, just give it the pathname instead of the url.
Note that debootstrap has a few dependencies that it needs to download and extract things. Most should be obvious from the rpm messages, but it needs to use the 'ar' decompression program, which may not be shown with the current version of debootstrap. You can find this in the binutils rpm package.
Since we are going to use your existing swap partition for the install, we need to turn off swap:
unf:~# swapoff -a
Use fdisk to make the swap partition a Linux partition. While this may not be necessary, it doesn't hurt to do it. It will also show you your available partitions. You will need to specify your disk. It will likely be /dev/hda if an IDE disk, or /dev/sda if SCSI. It will complain if you pick the wrong one, so don't worry.
unf:~# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 5362 MB, 5362882560 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 584 4690948+ 83 Linux /dev/sda2 585 652 546210 5 Extended /dev/sda5 585 652 546178+ 82 Linux swap
/dev/sda5 would be your swap partition from above(See where it says swap?). If you don't have a swap partition, well ermmm... Look into using resize2fs or something to make one for yourself.
Also, take note of your boot partition above. It will typically be the smallest partition on the
disk if it is present. Although not everyone has a separate partition for boot. You can check it
by looking in your /etc/fstab, or by running
df -h to see the mounted partitions. Look at what
/boot is mounted from. You will want to know this for Later.
Now change swap to Linux, and write out the partition table. You may want to look at the help (press m) to see what the commands do. The partition number would be the number at the end of the device (sda5 == 5):
Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 83 Changed system type of partition 5 to 83 (Linux) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks.
Don't worry about any complaining, it doesn't come into play until the reboot anyway. ;)
Turn swap partition into an ext3 partition for chroot. Pick a filesystem that you are comfortable with, otherwise you will have to convert it later. Ext3 has been around for a while, and is a fairly well supported fs. You may also want to look into something like ReiserFS.
The -j (journaling) switch tells mke2fs to do ext3, otherwise it uses ext2.
unf:~# mke2fs -j /dev/sda5 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux ... ... ... This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
You will likely want to make sure the dir_index flag is disabled, as the older version of fsck that woody uses doesn't understand it. If you have a version of fsck that doesn't support the option, you get very nasty results (as I discovered the hard way). Basically fsck will see the extra option when you boot up and die a horrible horrible death. And because the older version of tune2fs doesn't know about the flag, you can't turn it off:
unf:~# tune2fs -O ^dir_index /dev/sda5
If there was an error, you probably didn't have the flag anyway, so don't worry. You can re-enable it later after everything is done.
For ease of typing, export mount point to a variable (I'm using LFS so I can paste from the LFS book :p ):
unf:~# export LFS=/mnt/lfs
Now, any time you see $LFS, just type it literally and the OS will automagically put /mnt/lfs in for you.
Mount the device onto $LFS (/mnt/lfs):
unf:~# mkdir -p $LFS unf:~# mount /dev/sda5 $LFS
Now we need to run debootstrap (which will take a little while). There are several arguments that need to be provided. The architecture, distribution, directory, and url to the debian archive.
The architecture we will be using is i386, although you may need to use a different one depending on your hardware. The possibilities are as follows: alpha, arm, hppa, i386, ia64, m68k, mips, mipsel, powerpc, s390, or sparc
The distribution is any valid debian distribution name. The typical ones are Stable, Testing, and Unstable. The current code names for each are Woody for Stable, Sarge for testing, and Sid is always Unstable. There is also an occasional ``frozen'' distribution, which is Testing before it becomes Stable. I would recommend using Woody (Stable) for the initial install, as you should have minimal problems. Unfortunately Stable tends to be using software a few years old (with the exception of security patches). Testing has fairly current software, but is of course still having certain kinks worked out (although many tend to be compatibility across different architectures, as Debian has a good group of maintainers who normally wont upload known bad code.) I personally am happy with using unstable (which is still damn stable compared to most other distros), and just keep a close eye on new packages. :) Anyhoo, just wanted to cover those quick, but it is a good idea to stick with stable for the initial install, as it can be upgraded later if needed.
For the URL at the end, it can be any valid debian mirror. The one I'm using is one of the main mirrors, so should always be there. But for the same reason, it will be fairly slow. This will take a while to run, as quite a few files are downloaded.
Now, if something goes wrong here, just wipe all the files in /mnt/lfs, and run debootstrap again:
unf:~# /usr/sbin/debootstrap --arch i386 woody $LFS http://http.us.debian.org/debian I: Retrieving http://http.us.debian.org/debian/dists/woody/Release I: Validating /mnt/lfs/var/lib/apt/lists/debootstrap.invalid_dists_woody_Release I: Retrieving http://http.us.debian.org/debian/dists/woody/main/binary-i386/Packages.gz ... ... ... Starting system log daemon: syslogd Warning: Fake start-stop-daemon called, doing nothing . I: Base system installed successfully.
Now, copy in resolv.conf, hostname, and hosts. As they should all be the same in your new system. Take down the output of the hostname command as well (should be the same as the /etc/hostname file)
unf:~# cp /etc/resolv.conf $LFS/etc/resolv.conf unf:~# cp /etc/hosts $LFS/etc/hosts unf:~# cp /etc/hostname $LFS/etc/hostname
Now that we have all the files and everything copied, here is where we go into the chroot. Type the following to do so (and it sets a few things for you at the same time):
unf:~# chroot $LFS /usr/bin/env -i HOME=/root \ > TERM=$TERM PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin \ > /bin/bash --login
We need to tell the system how to mount your partitions on boot. First, lets make a basic fstab:
unf:/# cat > /etc/fstab << "EOF" > # filesystem mount-point fs-type options dump fsck-order > > /dev/sda5 / auto defaults 0 1 > proc /proc proc defaults 0 0 > EOF
Now, mount proc:
unf:/# mount -t proc proc /proc
Before we forget, lets set the hostname. Replace mybox.domain.com with whatever your hostname is.
Verify it with typing
hostname --fqdn If you get an error from that command, check your man files for
info on how to fix it. You may also want to fiddle with some of the values in /proc (/proc/sys/net I believe)
As you can set host and domain from there. See the proc manpage for more details.
unf:~# hostname mybox.domain.com
Configure Keyboard - while this may not be necessary, might as well do it in case something wants it:
unf:/# dpkg-reconfigure console-data
You will get a series of dialogs. You may want to change some of the settings depending on your prefs. Not really sure how much this effects the shell environment.
Read all the dialogs carefully. Here is what I did:
"Select Keymap from Arch list" What is the layout family? "qwerty" What is the keys layout of your keyboard? "US american" Which variant do you have? "standard" Which specific keymap do you want? "standard"
Now we finish configuring the network. If you don't know the following information, simply open a second session to your box and look in the relevant files. (In the original environment, not the chroot)
Debian has a file that won't be found in other linux's I believe.
The syntax is fairly simple. And the one I provide should work fine. Just be sure to change the
IP addresses as shown below.
You will have to do a different configuration if you need dhcp, there is documentation in the debian manpages. ``man interfaces'' I believe is the appropriate one. They should be available in the chroot.
Setting up /etc/network/interfaces:
unf:/# cat > /etc/network/interfaces << "EOF" > # The loopback interface > auto lo > iface lo inet loopback > > # The first network card (network, broadcast, and gateway are optional) > auto eth0 > iface eth0 inet static > address 188.8.131.52 > netmask 255.255.254.0 > network 184.108.40.206 > broadcast 220.127.116.11 > gateway 18.104.22.168 > EOF
You can get the above info by opening another session to your box outside the chroot. Type the following commands to get the info for address/netmask/network/broadcast/gateway:
First, we do ifconfig to get the real important stuff -
[root@plain root]# ifconfig eth0 Link encap:Ethernet HWaddr 00:01:80:31:81:AD inet addr:22.214.171.124 Bcast:126.96.36.199 Mask:255.255.254.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 ... ... ...
The second line above has the relevant info, with address/broadcast/netmask in that order.
To find the ``network'', type
route -n (-n so you can see the whole IP):
[root@plain root]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 188.8.131.52 0.0.0.0 255.255.254.0 U 0 0 0 eth0 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo default 184.108.40.206 0.0.0.0 UG 0 0 0 eth0
The first ``Destination'' IP address on the eth0 line is the Network, most likely it will be your IP with a 0 for the last quad. The Gateway is listed under ``Gateway'' on the ``default'' line.
Configure Timezone, users, and APT
Pretty much self explanatory. If any questions (like timezone) are unknown, answer what you think best. You can rerun this after if you want to change any answers.
Here's my suggested answers:
Timezone - Look at displayed time, and see if it looks like GMT. Otherwise say no. You can either figure out the timezone, or just give your own. You can adjust the time later within linux if necessary. Or maybe file a ticket to get them to set the bios properly. Shall I enable md5 passwords? "Yes" Shall I enable shadow passwords? "Yes" Enter/Verify Root password - Make it secure. At least one of each of the following: lowercase letter, uppercase letter, number, and symbol. Minimum of 8 chars to be safe. Remember, you shouldn't be using your root login that much anyway. Shall I create a normal user account now? "Yes" (So we can LOG IN!) Make an admin user, either call it admin, or use your own login. This will likely be your primary administrative account, and you can give it access to do most things root can (by using groups properly, etc). I'd recommend using a password following the same guidelines as for root. Although I tend to use something slightly easier to remember. Do you want to use a PPP connection to install the system? "No" Choose the method apt should use to access the Debian archive: "http" Use non-US software? "Yes" Use non-free software? "Yes" Use contrib software? "Yes" Select a country: "United States" Choose the Debian mirror to use: "mirrors.kernel.org" (Pick any mirror other then the *debian.org ones, as they will be under the most load. I'd suggest going with some of the more well known sites like kernel.org, or one of the *.edu hosts) Don't worry too much about this step, as we will be using netselect to find a better mirror next. But we have to install it first! :) Enter http proxy information, or leave blank for none: Leave blank Then it will attempt to download the package listings. If it fails, it will let you choose a different mirror. ;) The next few questions are not needed as we will be making our own sources file in a minute. Add another apt source? "No" Use security updates from security.debian.org? "No" (you could do this, but netselect will overwrite it) Run tasksel? "No" (You can run this after you get everything running if you want) Run dselect? "No" Do you want to erase any previously downloaded .deb files? [Y/n] "y" Exim Config - Depends on your situation, make sure you read the answers carefully. You can reconfigure this later by rerunning base-config. This can vary widely depending on your needs. The defaults should be fine for now. You must choose one of the options below: ... ... ... Enter value (default=`1', `x' to restart): [Enter] What is the `visible' mail name of your system? This will appear on From: lines of outgoing messages. Enter value (default=`unf', `x' to restart): [Enter] Does this system have any other names which may appear on incoming mail messages, apart from the visible name above (unf) and localhost? ... ... ... Enter value (default=`none', `x' to restart): [Enter] If there are any, enter them here, separated with spaces or commas. You can use wildcards. If there are none, say `none'. If you want to relay mail for all domains that specify you as an MX, then say `mx' Enter value (default=`none', `x' to restart): [Enter] Are there any networks of local machines you want to relay mail for? ... ... ... Enter value (default=`none', `x' to restart): [Enter] Which user account(s) should system administrator mail go to ? Enter one or more usernames separated by spaces or commas . Enter `none' if you want to leave this mail in `root's mailbox - NB this is strongly discouraged. Also, note that usernames should be lowercase! Enter value (`x' to restart): admin (Or whichever non-root user was the one you made) Is this OK ? Hit Return or type `y' to confirm it and install, or `n' to make changes (in which case we'll go round again, giving you your previous answers as defaults. (Y/n) [Enter]
Now you can use apt! Woohoo!
First off, we want to get a better mirror for apt. So let's install netselect. Netselect is a nice little script that takes a list of sites and finds the most responsive. It comes with a wrapper script called netselect-apt that auto-downloads the debian mirror list and makes a sources file for you. Great for lazy people like me who can't tell one mirror from another.
Netselect also needs wget to download the mirrors list, so we'll get that as well. Typically apt-get will follow all dependencies automatically, but wget is not really a dependency for netselect, as you can get the mirror list manually if you wanted. But wget is good to have anyway. The following line installs both.
unf:/# apt-get install netselect wget
Now we run netselect-apt. This is a simple script that takes the distribution as an argument, and outputs a sources.list in the current directory. We'll just put it right in the proper directory. If you aren't using woody/stable (you rebel you), change the name to your distro.
unf:/# cd /etc/apt; netselect-apt woody
That will get the best mirror for you. You may want to periodically rerun netselect-apt every couple months just to make sure you always have a good mirror. If you are running stable/woody you will want to add in security updates. Use the following command to add the proper deb line for the patches.
unf:/etc/apt# echo "deb http://security.debian.org stable/updates main contrib non-free" \ > >> /etc/apt/sources.list
You can change the stable to the name of your distribution (woody or stable). Although I believe that they are now starting to support patches for testing (sarge). There are no patches for unstable (sid) though. As they will just release a new package. ;)
Now that we have a new sources.list, we'll need update the package listings. You'll want to ALWAYS do this before running apt-get. (It was automatically run on base-config, but that doesn't apply with a different list) We'll also throw in an upgrade just in case.
unf:~# apt-get update;apt-get dist-upgrade
Now, we need ssh so we can log in later. Without ssh, we'll have a tough time getting into our system.
unf:~# apt-get install ssh
Once it downloads, it will ask you a few config questions. The most important being if you want to run sshd.
Allow SSH protocol 2 only "Yes" (More secure) Do you want /usr/lib/ssh-keysign to be installed SUID root? "Yes" Do you want to run the sshd server ? "YES"
Configure Locales - If you plan on using non-English characters, you need to install locales. NOTE: SKIP this step if you are fine with the plain old English ASCII/``C'' character set.
unf:~# apt-get install locales unf:~# dpkg-reconfigure locales
Now we need a Kernel -
unf:~# apt-cache search kernel-image
This will show a list of possible kernels. SMP is for multi processor systems (You dual-xeon bastards) The comments to the right of each package describe the systems they are meant for. And you most likely don't want a pcmcia kernel either. ;) Basically, pick the highest kernel version you see there that suits your system. For my purposes, that will be the 686 2.4.18 kernel (For my widdle Celeron)
unf:~# apt-get install kernel-image-2.4.18-686
If you get any messages about Initrd images, ignore them and continue.
Do you want to stop now? [Y/n] n
If it asks about making a link from vmlinuz, you can answer yes (Although it doesn't really matter now). It will ask to run LILO now. DON'T DO IT! It won't work right inside the chroot.
Do you wish to set up Linux to boot from the hard disk? [Yes] No
Now, lets make an attempt at making sure some modules are loaded. Especially the ethernet module.
apt-get install discover
This may whine a bit about some paths. Don't worry. Discover is a handy utility for seeing what modules you need loaded. Any comments about its effectiveness are appreciated.
Now, you can use discover to see what your hardware is (and even manually add the module to /etc/modutils/aliases). Use the following line to see what modules it thinks are needed for your hardware. It will leave certain parts blank if it doesn't know:
unf:/etc/apt# discover --enable-all --format="%m on %d - %V %M\n" bridge ide scsi usb ethernet
What you'll want to check is the output of an lsmod command on your original rackshack box compared to what discover reported. If any of it is different, you will need to manually edit the /etc/modutils/aliases file to load your driver (add a line anywhere in the format ``alias eth0 8139too'' - You can use the vendor info to google for the proper module.) If you edit the aliases file, you will need to run ``update-modules'' after. I will document this a bit better in the future, but the man pages on update-modules were quite good from what I remember.
As it so happened, on my server, I happened to have the ONE ethernet card (8139too) which seems to give discover problems. Try googling for 8139too ethernet modules on debian to see what I mean. Apparently it used a different name on older kernels, and isn't quite auto detected properly with discover. Just one of the little things that can cause much hair pulling. If discover is finding the wrong module for something, You will need to manually enter an alias, and add a skip line to discover.conf (see man discover)
Most should be fine as is, but make SURE you have that ethernet driver.
Lets configure /etc/discover.conf (although the default config should work):
unf:/# cat >> /etc/discover.conf << "EOF" > # /etc/discover.conf: hardware detection settings > > # Enable the PCI, USB, IDE, and SCSI bus scans: > enable pci,usb,ide,scsi > > # Disable PCMCIA - We're not running a laptop! > disable pcmcia > > # Scan for these devices at boot > boot bridge ethernet ide scsi usb > EOF
You may want to add a ``skip'' line at the end if you know it will try some modules that won't work.
Lets run MAKEDEV just to be safe (probably not necessary):
unf:/# cd /dev; ./MAKEDEV generic
Now, log out of the chroot!
Copy your kernel and initrd image (if it exists) to the boot partition. You will need to specify the ones that you installed.
unf:~# cp $LFS/boot/vmlinuz-* /boot unf:~# cp $LFS/boot/initrd.img-* /boot
Now, we need to add an entry to lilo.conf(leave out the initrd line if you don't have one) Be sure to specify your new kernel. The panic=30 line tells linux to reboot in 30 seconds if the kernel chokes.
The problem is if you weren't previously using lilo, then the rest of the file may not be correct. You may want to refer to the lilo man pages, or ask someone who knows how to configure your current boot loader.
unf:~# cat >> /etc/lilo.conf << "EOF" > > image=/boot/vmlinuz-2.4.18-686 > label=Debian > root=/dev/sda5 > initrd=/boot/initrd.img-2.4.18-686 > read-only > append="panic=30" > EOF
Synchronize lilo.conf, and make sure all the proper files are in your chroot.
unf:~# cp /etc/lilo.conf $LFS/etc unf:~# cp $(grep "image.*=" /etc/lilo.conf | cut -f 2 -d "=") $LFS/boot
And tell lilo to update (VERY IMPORTANT that you logged out of the chroot earlier, or it won't work) The -R is a nice command. It tells lilo to only use the specified image for the next boot. So once you reboot it will revert to your old kernel:
unf:~# /sbin/lilo -v -R Debian
NOTE: If lilo gives some kind of error with the preceding command, you may need to run it by itself first.
unf:~# /sbin/lilo -v -v
Then run the first command again, and it should be fine. If you see anything that looks like an error, DON'T reboot. Make sure it is alright first. To recover, just edit lilo.conf and take out that last block we added.
Skip fsck, as we'll be rebooting again soon anyway:
Unmount your chroot and proc:
unf:~# umount $LFS/proc unf:~# umount $LFS
If the unmount commands seem to be giving you a problem unmounting, try calling umount with the ``-l'' switch. This is known as a lazy unmount, and not all versions support it. But it can help if you are having problems. Use the above commands, but just insert the switch after the umount (umount -l $LFS...)
Ok.... Last chance to chicken out! You can fix everything back to the way it was by undoing any changes to lilo and re-enabling swap (need to run mkswap) at this point. Once you reboot, you start to enter the point of no return. ;)
unf:~# shutdown -r now
With luck.... You should now have your base debian install.
Wait a few minutes for the reboot, then log in via ssh to the IP you set up earlier. You should be able to use either the user or root account you set up previously during base-config.
Hopefully it did boot successfully. Give it 10 or so minutes before you give up on it though. If it didn't come back, you will need to find a way to manually reboot it and hope it does. The next reboot should bring it back to the original setup for you.
If you had a separate boot partition (as noted towards the beginning), you will likely want to mount it again. The minimal fstab we made did not account for a separate boot partition, so we will add it back in. If you did not have a separate partition (or don't want one), just skip this section.
First, lets turn our old partition into an ext3 fs just in case it wasn't already. This will erase any data there, but we have a second copy already in our own /boot. So, lets say my boot partition was /dev/sda2 for the purposes of discussion. So, the command to turn it into ext3 is easy enough:
unf:~# mke2fs -j /dev/sda2
Now, we need a place to mount it. Lets call it /boot2 (as we already have a /boot that has data in it). So we need to make that directory.
unf:~# mkdir /boot2
Now, we mount the partition in the new directory.
unf:~# mount /dev/sda2 /boot2
Lets copy all the files from /boot over onto the partition.
unf:~# cp /boot/* /boot2
Now that the files are copied over, we can unmount the partition.
unf:~# umount /boot2
And remove the mount point.
unf:~# rmdir /boot2
We are now going to mount the partition in place of where the /boot directory was.
unf:~# rm -rf /boot/*
We also need to tell the kernel how to mount it on boot. So fstab needs to be edited.
unf:~# cat >> /etc/fstab << "EOF" > /dev/sda2 /boot ext3 defaults 1 2 > EOF
The following command should mount everything in fstab, if it works here, then it should work on boot.
If there were any problems, get them resolved before you reboot. You can check if /boot is mounted
df -h and looking for /boot.
Now we need to copy our file system back over to the main partition over the original OS. You may want to run fdisk to see your partitions if you forgot. Look up top for how to do it. Use ``p'' to see the table, then ``q'' to quit.
First, lets do a quick reformat (although dd should technically take care of it I believe...). This seemed to fix some problems I encountered one time. ;)
unf:~# mke2fs -j /dev/sda1
To copy over the file system, we'll use dd. The good thing about this, is if your connection dies you can just run it again. This will take a while to run. For the arguments to dd, ``if='' will point to your current partition, and ``of='' will be the partition you are writing to (the original one). ``of='' will most likely be /dev/hda1 (or sda1 if scsi). You may want to use a larger blocksize, but 1024 works fine.
unf:~# dd if=/dev/sda5 of=/dev/sda1 bs=1024
Now go get some lunch while this runs (maybe 10-20 minutes). ;)
There is one last thing you need to do to the new partition. When you copy it over, the filesystem isn't aware of the new partition size, so you have to resize the filesystem.
First, make sure the filesystem is coherent by running fsck on it (use the same partition that was used in ``of='' at the last step). The -y switch assumes yes to all prompts. You may want to remove that if you know what you are doing. This may cause you to have to answer hundreds of questions about inodes though. ;)
unf:~# e2fsck -f -y /dev/sda1 e2fsck 1.32 (09-Nov-2002) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 3A: Optimizing directories Optimizing directories: 16321 32674 48981 49481 65722 82085 114671 Pass 4: Checking reference counts Pass 5: Checking group summary information
You should run this command repeatedly until you see output similiar to above (as in no extra actions taken that change your file system). It should say at the end if it did modify anything.
Now, we resize the partition. This command may tell you to run another command first to move all the data to the beginning of the disk. If so, run that command, and then run this one again.
unf:~# resize2fs -p /dev/sda1 resize2fs 1.32 (09-Nov-2002) Begin pass 1 (max = 431) Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 2 (max = 25) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 8) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 5 (max = 8) Moving inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/sda1 is now 14366126 blocks long.
You may want to run e2fsck on the partition again to make sure everything went smoothly (see above).
Now, we need to tell lilo to boot to the final partition. Basically what you need to do is move the section you added last time to the top of the list, and add a new entry for the partition we are about to make.
Unfortunately, I don't know what other options you might have in your lilo config, so I can't just give you the whole file. You'll have to open an editor and manually make the changes. And since this is a base installation, most likely the best editor to use is vi. You may want to apt-get install your editor of choice quickly if you really don't understand how to use vi. Although the editor won't be in your final installation as we already over everything. It's not too hard though.
To edit something in vi, there's only a few commands you need to know. The first thing to understand is that it runs in different ``modes'', mainly because certain keys do different things in different modes. In order to type in a file, you have to put it in ``insert'' mode. TO do this, you press the ``i'' button on your keyboard. Then you can type normally. Press escape to leave this mode (pressing escape more then once doesn't hurt anything).
The confusing part is when you want to do something else. In normal vi, the arrow keys may not work as expected. There is a much more robust editor called ``vim'' (vi improved) where they do. To move around the cursor, you need to be in command mode (the original mode, or what you get after pressing escape). Then you use the keys ``HJKL'' to navigate around the file. To delete a line in command mode, press ``dd'', and to delete a single character in command mode, press ``x''. To exit without saving, press escape a couple times, and then press ``:'' (colon) and type ``q!''. Do that if you accidentally start typing in command mode and don't know what you did. ;)
Once you are satisfied with your changes, you need to tell it to write out the file and quit. Hit escape to get back into command mode and then type ``:wq!''. Hopefully that is enough to get you going. If you get really confused and can't figure out how to exit, just press escape a couple times, and then hit your control (Cntrl) and ``z'' key at the same time. That should drop you back to the shell. Although you will need to kill off the editor process. You can do that as follows. If you have problems, don't worry too much as it shouldn't hurt anything. But you may want to ask someone how to use an editor so you can comfortably edit files in the future.
+ Stopped vi /etc/fstab unf:~# ps -eo pid,command | grep vi 14735 vi /etc/fstab unf:~# kill -9 14735
This should stop your vi process. Note that the above command will return ALL running programs that have the letters ``vi''
next to each other. Pick the proper one (should be fairly obvious), and supply the number it gives to the
kill -9 command.
So... on to the editing.
/etc/lilo.conf is layed out in sections. Each section starts with an ``image='' line, and ends at the next ``image='' line. What you want to do is edit out all images before the last one (that we added previously. Then we want to rename that image to linux.old (change where it says Debian on the ``label='' line to linux.old).
After that, go to the bottom of the file and copy that block exactly. Change where it says linux.old to linux, and change the ``root='' line to point to your new partition (/dev/sda1 or whatever). Everything else should be the same.
Once you are done with that, save the file. This should give you two sections each using the same kernel and pointing to a different partition. Now, you need to install lilo. To avoid trouble we will do a normal install, and then a ``boot once'' flag as before. This is due to sometimes lilo complains if you don't run it normally first.
The commands to install lilo are as follows:
unf:~# lilo -v -v unf:~# lilo -v -R linux
As usual, if you saw any errors, get them resolved before continuing.
We also need to make a new fstab for the other partition so it knows how to mount everything. Lets mount it first so we can copy the files over easily.
unf:~# mkdir /tmpmount unf:~# mount /dev/sda1 /tmpmount
First, copy over the lilo config you just made.
unf:~# cp /etc/lilo.conf /tmpmount/etc/lilo.conf
Now, lets make a nice little fstab that should have everything you need to boot smoothly. Be sure to replace the devices with your own. /dev/sda2 below being my main partition, /dev/sda1 being my boot partition, and /dev/sda5 being my swap partition. You may want to use ``auto'' in place of ``ext3'' below. We will comment out swap for now, as it won't work until we reformat the partition.
unf:~# cat > /tmpmount/etc/fstab << "EOF" > # filesystem mount-point fs-type options dump fsck-order > > /dev/sda2 / ext3 defaults 0 1 > proc /proc proc defaults 0 0 > /dev/sda1 /boot ext3 defaults 1 2 > none /dev/pts devpts gid=5,mode=620 0 0 > #/dev/sda5 swap swap defaults 0 0 > EOF
Now unmount the partition.
unf:~# umount /tmpmount unf:~# rmdir /tmpmount
And, the final reboot! All the previous warnings and such apply. It should boot back into this partition if things go wrong.
unf:~# shutdown -r now
Wheee! You should now be in your final system. Unless something went wrong and crashed horribly.... But lets pretend that didn't happen.
Now we need to just make some changes more permanent, and you can go on configuring your squeaky clean system. It's nice having a small installation without all that extra crap isn't it? :)
Before we go any further, lets make lilo more permanent.
unf:~# lilo -v -D linux
The -D tells it to use that label for booting, similar to -R, but not just one time. You may want to edit out the ``linux.old'' block entirely, and just run lilo with no arguments. Actually, once we are done, linux.old will not work at all, so it is probably a good idea. But for now, this will be fine.
Now, lets reactivate your swap partition. You do remember where it was right? First, uncomment the swap line in your fstab. (vi /etc/fstab) The commands for vi are still the same as before. Just move the cursor down to the ``#'' in front of the swap line we commented out before, and press ``x'' to delete the ``#''. Then press ``:wq!'' to save and exit.
Now, to reformat and enable the partition.
unf:~# mkswap /dev/sda5 unf:~# swapon -a unf:~# sync;sync;sync
Lets make sure you have all the devices you might need as well (will take a couple minutes most likely).
unf:~# cd /dev;./MAKEDEV update
And that's it! From Redhat (or whatever - I happened to do this from Redhat) to Debian in 2973407 easy steps!
Back to Top
On the methodology of wrapping the chroot and getting everything else to work outside of the actual install (the hard stuff :) ):
On installing Debian into the chroot:
Back to Top
This was put together by Erik Jacobson <Azhrarn@darkgalaxy.com> at that productive time around 1AM. Feel free to send me any feedback or extra money you don't want anymore. :)
MSN: email@example.com (Don't email me here)
IRC: #chatspike on irc.chatspike.net
Homepage: http://www.burnproject.com/ - http://trilldev.sourceforge.net/
Back to Top
For what it's worth, this document is Copyright (2003) to the
person(s) listed under AUTHOR up above.
Feel free to distribute it or use the information within wherever you want for whatever purpose. Just
give me credit where it is due.
The other specific names and linked documents (Debian, Redhat, LFS, etc) are all copyright to their respective owners of course.
Back to Top
11/18/2004 - Fixed linuxfromscratch URL, as they moved the old one. (Thanks Keith Nasman)
4/1/2004 - Added note about 'ar' dependency for debootstrap. (Thanks to Lucas Albers)
1/12/2003 - Added alternate debootstrap RPM urls due to p.d.o. downtime.
11/18/2003 - Added -n to route, so the hostname isn't cut off for some people.
5/31/2003 - Added -y to e2fsck, as you can end up with hundreds of questions. And added part about running more then once.
5/24/2003 - Changed part about ``killall vi'' to recommend the safer ``ps'' then manually enter pid number. Those damn unixes and their overzealous commands. ;)
First revision: 4/21/2003
Back to Top
|HOWTO - Install Debian Onto a Remote Linux System|