# How to install Gentoo remotely over a Red Hat install

## SubZero

How to install gentoo remotelly over a Red Hat install

Because of the way gentoo is installed, it's very easy to install it remotelly, wihtout getting your hands at the machine. Only using ssh.

You only need a machine running linux with networking and sshd working. I installed over RedHat 7.2, but I think that installing over another distro would be the same steps.

This isn't the best way to install, it was the way I managed to install. If anyone knows a better way, or have some way to jump some steps, please send it too. Tha major problem was that if something went wrong, I would need to call support, and probably they would install RedHat again.

The server had these partitions already set up and running:

/dev/hda1: 300 Mb - ext3 mounted as /boot

/dev/hda2: 1 Gb - swap

/dev/hda3: 57 Gb - ext3 mounted as /

Only after finishing installing gentoo I saw that I could install it at the swap partition, that is larger than the boot one, that in that case I used. As the machine has 512Mb RAM, the swap could be disabled with swapoff, or even I could partition it as a smaller one to be used as swap, only to be sure. Another thing to be in mind is that /dev/hda1 will be at the first 1024 cilinders, and I don't know if gentoo will boot with the boot files after the 1024 cilinders. I could use /dev/hda1 only for the boot partition then. Like mom say: It's over now...

Is a good thing to try this with a machined at the same network of you, then you can pratice before messing anything at the server.

Let's start the way I did:

1. stop all unnecessary daemons but sshd;

2. write down all things related to the machine, like modules loaded (lsmod), network configuration (ifconfig) and the gateway (route -n);

3. download stage2-i686-1.2.tbz2 to your home dir (/root);

4. create the directories for holding the new gentoo;

As I would like to have a fresh gentoo system, I did not used the root mount (/), instead, I used the boot partition, but the swap partition could be used, and beeing larger, the installation would be easier.

5. Umount /boot and mount it as gentoo (optional);

```
# mkdir /mnt/gentoo

# umount /dev/hda1

# mount /dev/hda1 /mnt/gentoo

```

Because of the lack of space that I had to install gentoo, I created some binds to use the space at the root partition, that has 57 Gb:

```
# mkdir /mnt/gentoo/boot

# mkdir /mnt/gentoo/tmp

# mkdir /mnt/gentoo/usr

# mkdir /mnt/gentoo/usr/portage

# mkdir /mnt/gentoo/usr/src

# mkdir /mnt/gentoo/var/tmp/portage

```

The first directory is need by the default installation of gentoo, and the rest are used by the portage system, and needs a lot of temporary space, as to download the packages too. The src dir will hold the kernel source, that isn't small. These directories aren't needed to run gentoo linux, so gentoo will boot even without mounting them after.

6. mount the addictional directories

```
# mkdir /tmp/tmp2

# mkdir /tmp/portage

# mkdir /tmp/src

# mkdir /tmp/tmp3

# mount -o bind /tmp/tmp2 /mnt/gentoo/tmp

# mount -o bind /tmp/portage /mnt/gentoo/usr/portage

# mount -o bind /tmp/src /mnt/gentoo/usr/src

# mount -o bind /tmp/tmp3 /mnt/gentoo/var/tmp/portage

```

This way all temporary directories used by gentoo, as the kernel source will be stored at the biggest partition, freeing valuable disk space at the 300Mb partition we're using.

7. Follow steps 9, 10, 11, 12 and 13 from the default gentoo installation: http://www.gentoo.org/doc/en/build.xml

As we are using the stage2 tarball, we don't need to bootstrap this installation.

Pay attention at "Code listing 16" that you're using the stage from /root and not from the cd-rom.

8. The gotcha: kernel and system logger

When using the bind method of mount, the portage system was unable to install the kernel at /usr/src. I didn't see any errors emerging the kernel, but only some files appeared at /usr/src/linux. So, instead of using the emerge to install the kernel, I did it manually:

```
# cd /usr/src

# tar -xzf /usr/portage/distfiles/linux-2.4.18.tar.bz2

# ln -s linux-2.4.18 linux

```

Because emerge has downloaded the kernel for me, I used it from distfiles, but you can get the kernel yourself too.

9. Configure and compile the kernel

Don't forget to include ext3 inside the kernel, and not as a module, or you'll have problems when booting!

```
# make menuconfig

# make dep && make clean bzImage modules modules_install

# cp /usr/src/linux/arch/i386/boot/bzImage /boot

```

After compiling the kernel, install a system logger too, as step 14.

10. Follow step 16;

Here we only need to list the /dev/hda1 partition as the root partition (/) and the swap partition.

```
/dev/hda1           /           ext3    noatime         0 1

/dev/hda2           none        swap    sw              0 0

proc                /proc       proc    defaults        0 0

```

This is very important

After configuring the network and modules (please, don't forget to configure the modules for the network card (/etc/modules.autoload), as editing /etc/conf.d/net and adding it with rc-update or you'll have troubles!) add sshd to the initializations system:

```
# rc-update add sshd default

```

We'll need sshd running after the boot!

11. Grub of lilo?

As I know more lilo than grub, I emerged lilo and used it as the boot loader. Don't forget to setup the boot loader to boot automatically, removing any "prompt" line at lilo.conf, for example. You wouldn´t like to call for support only for hitting enter at your box!

12. It's now or never

The time for booting has come, please check if network configuration is ok, and if ssh will run after the boot, looking at /etc/runclevels/default and seeing if there is a net.eth0 and sshd listed there.

Follow step 17 to exit the chrooted shell, umount everything but the root partition and swap (remember, the old linux is still there running) and boot your machine! You will loose your shell, wait some minutes, don't stay nervous, the ssh daemon will create it's keys and so on, and try to connect into your new gentoo box!

13. Another installation?

I hope that you got here and is very happy with your new linux installation, but there are some steps that need to be followed before finishing.

First, your gentoo linux is running in a 300Mb of space, and we have a 57Gb unused and unmounted partition!

A more expert linux user could just format and move the directories into the new partition, but how I know nothing about moving linux between partitions, I made another install of gentoo over the new partition.

So:

```
# mke2fs -j /dev/hda3

# mkdir /mnt/gentoo

# mount /dev/hda3 /mnt/gentoo

```

Another issue is how I would link /dev/hda1, that is mounted as root (/) as the boot partition for the mounted partition /dev/hda3 that was using /dev/hda to hold its mount point. The way I found was using the cool feature from mount, the bind operation:

```
# mkdir /tmp3

# mkdir /mnt/gentoo/boot

# mount -o bind /tmp3 /mnt/gentoo/boot

```

I was afraid that lilo won't boot using this bind operation, but it worked like a charm.

14. Follow steps 9 to end from Gentoo Installation Instructions.

Now the installation will happen at the right partition, only using one bind mount. If you find more space, you can copy the files at /dev/hda3/tmp/portage/distfiles to /mnt/gentoo/usr/portage/distfiles before formatting it, then you don't need to download them again.

Warning: Don't forget again that you need to set up the module needed by the network card (/etc/modules.autoload), the network (rc-update add net.eth0 default) and the ssh daemon!

I think that setting a root password is well needed too.

The boot partition isn't needed to be set up at /etc/fstab.

15. After booting

After installing and booting gentoo linux, you need to clear the boot partition and leave there only the files needed by grub/lilo and the kernel you compiled:

```
# mount /dev/hda1 /boot

# mv /boot/tmp3 /tmp/tmp3

# unmount /dev/hda1

# mke2fs -j /dev/hda3

# mount /dev/hda1 /boot

# mv /tmp/tmp3/* /boot

```

Edit fstab and put your boot partition there.

Run lilo/grub again and boot.

16. Congratulations

Now you've setup gentoo at a machine without getting your hands at it! In my case, I even don't know how the machine is, because it is at another country!

Gentoo developers has proved again that they made the best linux distro ever created! Keep up the good work!

Paulo Assis

paulo@phpdbform.com

----------

## mr-simon

After completing my first install of Gentoo on my laptop, and then reelling my tongue back into my mouth, I decided to try this on my new co-lo red-hat box.

I found a better way of dealing with the partitions initially, that saves having to install gentoo twice. Note, this is blatantly plagiarised from this post by HappyByte on the Rackshack.net forums...  :Smile:  - The original post discussed replacing red-hat with freeBSD. I was tempted, but gentoo seems like an easier solution considering my *BSD experience is not great.

Assume for the purposes of this example:

```
# /dev/hda1 -> /boot (ext3/100m)

# /dev/hda2 -> / (ext3/56G)

# /dev/hda3 -> swap (1G)
```

Un-install everything unnessecary on the red-hat box, so it will fit in the 1Gb swap partition. Then, you need to switch off swap, as above, and create a new, blank, partition. Like so:

```
swapoff -a

fdisk /dev/hda

   #change swap partition to "linux native"

   t, 3, 83, w

mke2fs -j /dev/hda3
```

Then, you need to edit your /etc/lilo.conf and duplicate the entry that's there. Call it "linux-new" instead of linux, and set root=/dev/hda3 instead of root=/dev/hda2. It's best not to delete the old one just yet, in-case things go wrong. You'll also want to edit /etc/fstab and comment out the entry for the swap partition.

After this, you're ready to duplicate your root partition into the new smaller one.

```
mount /dev/hda3 /mnt

cd /

find -print0 -mount | cpio -p0dmvu /mnt

   #copy contents of root partition to /mnt, note zero not capital o
```

Your new partition now contains a sensible clone of the root partition with filetimes and permissions preserved.

Lastly, to finish preparing your new partition edit /mnt/etc/fstab and change the root partition to /dev/hda3. Your new partition should now be ready to take over from the old one. Unmount it, and run:

```
lilo

lilo -R linux-new

   #tell lilo to boot this by default on next reboot ONLY

reboot
```

Because all this is fairly safe - we haven't messed up the original partition - it should be a simple matter of calling support and asking them to press reset if you have messed anything up, and you'll end up with your original configuration again, minus swap.

So, reboot, and cross your fingers. If it works, you should be able to log in again in a minute or so, and calling df should tell you that you're running pretty low on hard disk space.

Don't forget to edit /etc/lilo.conf again, and remove the new "linux-new" settings, and modify "linux" to point at /dev/hda3 - so you only have a default configuration again.

Then it's just a matter of:

```
lilo

mke2fs -j /dev/hda2

   #or mkreiserfs, or whatever floats your boat.
```

Then you can mount /dev/hda2 in /mnt/gentoo and proceed as above.

Once your gentoo installation is done, the new 1 gig red-hat partition can be replaced with swap. An inverse of the first step here. The /boot partition can remain untouched throughout the installation.

I haven't done this yet, but I think it will also be wise to install a cron job to reboot the server after finishing the gentoo install, and use the lilo -R trick above for the initial boot of the gentoo partition. That way, if your box fails to come up with networking and ssh enabled, it will eventually reboot back into red-hat which is known to work. Saving you an embarrasing call to support, and possibly a small fee.

Hope this helps! I've just tried it and it works. Now to proceed with the gentoo install.

----------

## PJ

I'm curious if anyone has done this on using the newer 1.4 based gentoo packages. 

Given what I've read here, I don't foresee any problems, but I'd still like to go ahead and ask.

----------

## Andersson

Not that I think you're still following this thread, but questions need answers... I just finished installing gentoo 1.4 using this guide, and I had no problems at all! (At least no problems related to this article.) I had a suitable empty partition to use, so I didn't have to bother with that like the guys above. I also didn't notice the problem about the kernel not being installed. Piece of cake!

----------

## io-

I used this basic method to install a fresh gentoo image over a redhat install. I had a swap partition that was 4gigs so I used that as a temp / to boot off of. Worked great! You don't HAVE to have swap space, so installing from stage1 remotely worked out ok using it. After I was into my new / partition and everything was happy I setup swap again and updated /etc/fstab.

----------

## Rabbitt

I've been going through the process of switching from RH9 --> Gentoo on a remote server however, this server is using grub not lilo. For those who would like to be able to use the 'lilo -R' method of rebooting to a specific config only once, you can do so usually providing you are using redhat's (patched) grub. you'll know you have the correct grub if you, while in grub shell you type and see the following:

```

grub> help savedefault

savedefault: savedefault [--stage2=STAGE2_FILE] [--default=DEFAULT] [--once]

    Save DEFAULT as the default boot entry in STAGE2_FILE. If

    '--once' is specified, the default is reset after the next reboot.

```

If you do indeed have the correct grub, then you can mimick the -R for lilo. Once you get to the part of setting up your grub.conf, make a note of which entry the new entry you add, is in the list. Numbering starts at zero so, given a grub conf that looks like so:

```

default=1

timeout=10

splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.4.20-19.8)

        root (hd0,0)

        kernel /vmlinuz-2.4.20-19.8 ro root=/dev/hda3

        initrd /initrd-2.4.20-19.8.img

title Red Hat Linux (2.4.20-18.7)

        root (hd0,0)

        kernel /vmlinuz-2.4.20-18.7 ro root=/dev/hda3

        initrd /initrd-2.4.20-18.7.img

title Red Hat Linux (swap drive as root)

        root (hd0,0)

        kernel /vmlinuz-2.4.20-18.7 ro root=/dev/hda2

        initrd /initrd-2.4.20-18.7.img

```

the "Red Hat Linux (2.4.20-19.8)" is entry ZERO and the one following it is entry ONE (and so on).  Make a note of what the corresponding number is for your new entry. Then complete the install of your new boot record (root  (...)  followed by setup (...) ) in grub shell. Once you've finished that, and while still in grub shell, do the following (where # is the number of the entry that you just added to grub.conf):

```

grub> savedefault --default=# --once

```

this tells grub to make the specified entry the default entry for the next bootup only so, if anything goes wrong, just have your colo reboot the box and it should come up with your previous settings intact.

Cheers and good luck,

----------

## Andersson

Rabbitt, great tip! I've seen people asking for that feature in some lilo/grub flame war  :Very Happy: 

You should post this as a new thread, otherwise people will miss it.

----------

## jpr5

I hadn't realized anyone else gave instructions on how to do this, so I worked out my own HOWTO and only found this forum post after the fact.

In any case, my HOWTO is fairly detailed (and IMO simpler), so if you're looking to install Gentoo over any other distribution remotely, RedHat or otherwise, check this out.

http://www.darkridge.com/~jpr5/doc/rh-gentoo.html

Have fun!

--jordan

----------

## Rabbitt

A nice way to automate your system rebooting back to a known 'safe' version (following the second comment on this thread) is to add the following to your /etc/inittab:

```

xx:3:once:/bin/sh -c 'sleep 15; reboot'

```

This tells the system to reboot 15 minutes after successfully entering runlevel 3. So if, for whatever reason, you can't log in to your system after reboot, just wait fifteen minutes and your system should reboot back to the 'known good' version (providing you used the lilo -R method or the grub savedefault --once method).

If you were able to successfully get in, just kill the process that's hanging out in the background, tick tick ticking away ;-)

Note: This information was gleaned from the following url:

http://www.webhostingtalk.com/showthread.php?s=&threadid=235241

Cheers,

----------

## benow

 *Quote:*   

> xx:3:once:/bin/sh -c 'sleep 15; reboot' 

 

Yes, luckly 15s is enough time to edit inittab to be

```
xx:3:once:/bin/sh -c 'sleep 15m; reboot'
```

Hrm, perhaps I should not be blindly copying critical instructions   :Embarassed: 

----------

## RexM

 *benow wrote:*   

>  *Quote:*   xx:3:once:/bin/sh -c 'sleep 15; reboot'  
> 
> Yes, luckly 15s is enough time to edit inittab to be
> 
> ```
> ...

 

lol.

This tutorial looks very interesting and I think I'm going to try it when I get my dedicated server.  Although the company I was going to get the dedicated server from installs gentoo as one of the default OS's.

----------

## tropicalhandler

I used mr-simon's method and it worked great!  Pretty simple and effective.  I have a remote dedicated server that had Red Hat 9 installed, it contained lots of packages that are safe to remove like X and all the RH gui configuration utilities.  Thanks!

----------

## deprave

has anyone tried any of these methods with debian

----------

