I'm bored

Discussion in 'Smalltalk' started by linuxfast, Sep 22, 2005.

  1. linuxfast

    linuxfast New Member

    Was bored so I thought I would try this on one of my unused remote servers.

    http://www.underhanded.org/papers/debian-conversion/remotedeb.html

    It's a method of formatting your swap partition and installing debian remotely, then changing your boot loader to let you boot from it.

    It was very good fun and interesting too.....
    My machine is now dead however, must have done something wrong LOL
    Will probably try again on a test box at home.
    If anyone has any experience in something similar, please let me know. Interested to know if Fedora can be installed remotely, maybe with rpmstrap ? Not been able to find much info on it yet.

    :eek:
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Hi,

    here is a small shell script to install DEBIAN remotely. I've used it and it worked for me. The comments and questions are in german, but with a bit shell scripting knowledge you may understand it as well. The script is intended to be run from a net-booted linux rescue system that most server hosting providers are already offering in germany.

    Code:
    #!/bin/sh
    ##############################################################
    #
    # v1.6
    # 25.03.2003 Christian Ney
    # 
    # ---------------------------------------------------
    # Dieses Dokument unterliegt der GPL,   
    # und darf frei kopiert und geändert werden, so lange
    # die Coprightinformation unverändert beigefügt
    # wird. 
    # Bei Veröffentlichung und / oder kommerzieller
    # Nutzung ist der Autor ([email protected]) zu
    # informieren.
    # ---------------------------------------------------
    #
    # Die Benutzung dieses Scripts erfolgt auf eigene Gefahr
    # 
    ##############################################################
    
    BLOCKS=`/sbin/fdisk -s /dev/hda`
    SPACE=`expr $BLOCKS / 1024`
    
    echo "---------------"
    echo "Partitionierung"
    echo "---------------"
    echo ""
    
    echo "Größe für das /-Filesystem (in MB) :"
    read ROOT
    LEFT=`expr $SPACE - $ROOT`
    ALL=$ROOT
    echo ""
    echo "OK, / soll also $ROOT MB groß sein. Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für die swap-Partition in MB :"
    read SWAP
    LEFT=`expr $LEFT - $SWAP`
    ALL=`expr $ALL + $SWAP`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /    -> $ROOT MB"
    echo "/dev/hda2 -> swap -> $SWAP MB"
    echo "Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für das /boot-Filesystem in MB :"
    read BOOT
    LEFT=`expr $LEFT - $BOOT`
    ALL=`expr $ALL + $BOOT`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /     -> $ROOT MB"
    echo "/dev/hda2 -> swap  -> $SWAP MB"
    echo "/dev/hda1 -> /boot -> $BOOT MB"
    echo "Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für das /usr-Filesystem in MB :"
    read USR
    LEFT=`expr $LEFT - $USR`
    ALL=`expr $ALL + $USR`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /     -> $ROOT MB"
    echo "/dev/hda2 -> swap  -> $SWAP MB"
    echo "/dev/hda1 -> /boot -> $BOOT MB"
    echo "/dev/hda5 -> /usr  -> $USR MB"
    echo "Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für das /home-Filesystem in MB :"
    read HOMEDIR
    LEFT=`expr $LEFT - $HOMEDIR`
    ALL=`expr $ALL + $HOMEDIR`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /     -> $ROOT MB"
    echo "/dev/hda2 -> swap  -> $SWAP MB"
    echo "/dev/hda1 -> /boot -> $BOOT MB"
    echo "/dev/hda5 -> /usr  -> $USR MB"
    echo "/dev/hda6 -> /home -> $HOMEDIR MB"
    echo "Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für das /tmp-Filesystem in MB :"
    read TMP
    LEFT=`expr $LEFT - $TMP`
    ALL=`expr $ALL + $TMP`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /     -> $ROOT MB"
    echo "/dev/hda2 -> swap  -> $SWAP MB"
    echo "/dev/hda1 -> /boot -> $BOOT MB"
    echo "/dev/hda5 -> /usr  -> $USR MB"
    echo "/dev/hda6 -> /home -> $HOMEDIR MB"
    echo "/dev/hda7 -> /tmp  -> $TMP MB"
    echo "Übrig sind $LEFT MB."
    
    echo ""
    echo "Größe für das /var-Filesystem in MB (noch frei : $LEFT MB) :"
    read VAR
    LEFT=`expr $LEFT - $VAR`
    ALL=`expr $ALL + $VAR`
    echo ""
    echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
    echo "/dev/hda3 -> /     -> $ROOT MB"
    echo "/dev/hda2 -> swap  -> $SWAP MB"
    echo "/dev/hda1 -> /boot -> $BOOT MB"
    echo "/dev/hda5 -> /usr  -> $USR MB"
    echo "/dev/hda6 -> /home -> $HOMEDIR MB"
    echo "/dev/hda7 -> /tmp  -> $TMP MB"
    echo "/dev/hda8 -> /var  -> $VAR MB"
    echo "Übrig sind $LEFT MB."
    
    if [ "$1" = "--with-opt" ]; then
            echo ""
            echo "Größe für das /opt-Filesystem in MB (noch frei : $LEFT MB) :"
            read OPT
            LEFT=`expr $LEFT - $OPT`
            ALL=`expr $ALL + $OPT`
            echo ""
            echo "Deine Partitionierung sieht im Moment folgendermaßen aus :"
            echo "/dev/hda3 -> /     -> $ROOT MB"
            echo "/dev/hda2 -> swap  -> $SWAP MB"
            echo "/dev/hda1 -> /boot -> $BOOT MB"
            echo "/dev/hda5 -> /usr  -> $USR MB"
            echo "/dev/hda6 -> /home -> $HOMEDIR MB"
            echo "/dev/hda7 -> /tmp  -> $TMP MB"
            echo "/dev/hda8 -> /var  -> $VAR MB"
            echo "/dev/hda9 -> /opt  -> $OPT MB"
    	echo "Übrig sind $LEFT MB."
    fi
    
    if [ $ALL -gt $SPACE ]; then
            echo ""
    	echo "Plattengröße : $SPACE MB, du willst aber $ALL MB allokieren."
    	echo "Partitionen sind zu groß für die Platte. Abbruch."
    	exit 1
    fi
    
    echo ""
    echo "---------------------"
    echo "Netzwerkkonfiguration"
    echo "---------------------"
    echo ""
    
    echo "IP-Adresse deines Servers :"
    read IPADD
    echo ""
    
    NETMASK=255.255.255.0
    NETWORK=`echo $IPADD | cut -d "." -f 1,2,3`.0
    BROADCAST=`echo $IPADD | cut -d "." -f 1,2,3`.255
    GATEWAY=`echo $IPADD | cut -d "." -f 1,2,3`.1
    
    echo "Hostname deines Server (pxxxxx.pureserver.info) :"
    read HOSTNAME
    echo ""
    
    cd /
    
    echo "#!/bin/sh" > ./stage2.sh
    echo "export IPADD=$IPADD" >> ./stage2.sh
    echo "export NETMASK=$NETMASK" >> ./stage2.sh
    echo "export NETWORK=$NETWORK" >> ./stage2.sh
    echo "export BROADCAST=$BROADCAST" >> ./stage2.sh
    echo "export GATEWAY=$GATEWAY" >> ./stage2.sh
    echo "export HOSTNAME=$HOSTNAME" >> ./stage2.sh
    echo "chmod u+x ./stage3.sh"
    echo "./stage3.sh" >> ./stage2.sh
    chmod u+x ./stage2.sh
    
    # Get Debian-Start
    wget http://linux.roothell.org/debian-rootie/debian-start.tar.gz
    tar xzvf ./debian-start.tar.gz
    
    # Partitionierung löschen
    for i in `seq 1 9`
    do
            /sbin/parted -s /dev/hda rm $i
    done
    	
    # Partitionieren
    /sbin/parted -s /dev/hda mkpart primary ext2 0 $BOOT && \
    /sbin/parted -s /dev/hda set 1  boot on && \
    /sbin/parted -s /dev/hda mkpart primary linux-swap $BOOT `expr $BOOT + $SWAP` && \
    /sbin/parted -s /dev/hda set 2 swap on 
            SWAP=`expr $BOOT + $SWAP`
    /sbin/parted -s /dev/hda mkpart primary ext2 $SWAP `expr $SWAP + $ROOT` && \
    /sbin/parted -s /dev/hda set 3 root on
            ROOT=`expr $SWAP + $ROOT`
    	if [ "$1" = "--with-opt" ]; then
    		EXTEND=`expr $ROOT + $USR + $HOMEDIR + $TMP + $VAR + $OPT`
    	else
    		EXTEND=`expr $ROOT + $USR + $HOMEDIR + $TMP + $VAR`
    	fi
    /sbin/parted -s /dev/hda mkpart extended $ROOT $EXTEND && \
    /sbin/parted -s /dev/hda mkpart logical ext2 $ROOT `expr $ROOT + $USR` && \
            USR=`expr $ROOT + $USR` && \
    /sbin/parted -s /dev/hda mkpart logical ext2 $USR `expr $USR + $HOMEDIR` && \
            HOMEDIR=`expr $USR + $HOMEDIR` && \
    /sbin/parted -s /dev/hda mkpart logical ext2 $HOMEDIR `expr $HOMEDIR + $TMP` && \
            TMP=`expr $HOMEDIR + $TMP` && \
    /sbin/parted -s /dev/hda mkpart logical ext2 $TMP `expr $TMP + $VAR` && \
    if [ "$1" = "--with-opt" ]; then
                    VAR=`expr $TMP + $VAR`
    	/sbin/parted -s /dev/hda mkpart logical ext2 $VAR `expr $VAR + $OPT`
    fi
    
    # Filesysteme anlegen
    if [ "$1" = "--with-opt" ]; then
            for i in "1" "3" "5" "6" "7" "8" "9"
            do
                    /sbin/mke2fs -j /dev/hda$i
            done
    else
    	for i in "1" "3" "5" "6" "7" "8"
    	do
    		/sbin/mke2fs -j /dev/hda$i
    	done
    fi
    	
    /sbin/mkswap /dev/hda2
    
    # Filesysteme mounten
    /bin/mkdir /mnt/debian
    /bin/mount -t ext3 /dev/hda3 /mnt/debian
    /bin/mkdir /mnt/debian/boot
    /bin/mount -t ext3 /dev/hda1 /mnt/debian/boot
    /bin/mkdir /mnt/debian/usr
    /bin/mount -t ext3 /dev/hda5 /mnt/debian/usr
    /bin/mkdir /mnt/debian/home
    /bin/mount -t ext3 /dev/hda6 /mnt/debian/home
    /bin/mkdir /mnt/debian/tmp
    /bin/mount -t ext3 /dev/hda7 /mnt/debian/tmp
    /bin/mkdir /mnt/debian/var
    /bin/mount -t ext3 /dev/hda8 /mnt/debian/var
    if [ "$1" = "--with-opt" ]; then
    	/bin/mkdir /mnt/debian/opt
    	/bin/mount -t ext3 /dev/hda9 /mnt/debian/opt
    	/usr/bin/touch /mnt/debian/opt/tmpfile
    fi
    
    # debootstrap starten
    /usr/sbin/debootstrap woody /mnt/debian http://ftp.debian.de/debian/ && \
    
    # Stage2-Script ins neue Root verschieben
    /bin/mv /stage2.sh /mnt/debian/
    /bin/mv /stage3.sh /mnt/debian/
    
    # Chroot ins "neue" System
    /usr/sbin/chroot /mnt/debian /stage2.sh
     
  3. linuxfast

    linuxfast New Member

    Cool thanks till.
    Will have a look at this. All my servers are colo so theres no rescue installed.
    Wondering if this is something else I can look at doing myself.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    I dont know how these companies are managing it.

    You can select in the server control area wether the server shall boot from its own harddisk or from a network booted rescue systems. I know how to enable netboot in the bios of my PC, but how to manage my bios remotely???
     
    Last edited: Sep 22, 2005
  5. linuxfast

    linuxfast New Member

    Ah I see
    Worth trying to find out.
    Short of having a second BIOS which is switchable, I have no idea... and obviously nobody would go to that trouble would they ?

    Anyone know how it's done ?

    And yeah, I had a oneandone server until I realised my mistake, they had a system like this

    Thinking about it, surely it can be done by having a seperate partition with the rescue file system, and a custom boot loader which could be activated by a php script maybe.... but then again, the OS would need to be booting to do that (and thus not requiring rescuing !!!)
     
    Last edited: Sep 22, 2005
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes and the customer has full control over the server and even if he/she formats the harddrive, the rescuesystem is working. Maybe they are using something like the ROLF network cards??
     
  7. falko

    falko Super Moderator Howtoforge Staff

  8. domino

    domino New Member

    LOL, Funny how bordom sometimes gets you in big trouble.
     
  9. linuxfast

    linuxfast New Member

    Yeah looked at that Falko, I am sure I will find a use for that Howto but not been through it yet.
    What I was trying to do however, is find a way whereby if your server becomes unbootable (and is a remote server), you could log into an independant system which would change the boot config of your machine, or at least enable you to mount the filesystem from your hard disk in order to let you fix the problems that are preventing it from booting

    And yeah, very true Domino !
     

Share This Page