Browse Source

init

master
Muhammad Hussein Fattahizdeh 5 years ago
parent
commit
696c67f6ec
5 changed files with 303 additions and 0 deletions
  1. +87
    -0
      README.md
  2. +24
    -0
      config.sample
  3. +84
    -0
      create-iso.sh
  4. +87
    -0
      grub.sh
  5. +21
    -0
      preseed.cfg.template

+ 87
- 0
README.md View File

@ -0,0 +1,87 @@
# Ubuntu Overssh Reinstallation
If your ISP/Datacenter dosn't provide standard or trusted iso for your server. Get ugly server from it with installed version of Ubuntu server.
I have same situation installed ubuntu has bad partition table or huge list of stupid package installed. Datacenter network is my primary concern or it's really cheap price but administrators dosn't care. What should i do? That's my way to solve this issue easily.
Ask them to install ubuntu server what ever is it. re install it over ssh.
Create your own netiso and reinstall it over ssh. You can partion yor server as you desire. And set more configuration using [ubuntu preseed](https://help.ubuntu.com/lts/installation-guide/armhf/apbs02.html) just over ssh; no kvm/ipmi/vnc required.
### Requirement
1. Installed ubuntu version on server via ssh access
2. Clone this repo to your server
3. Copy `config.sample` to `config` file and edit field by field exactly:
```
#!/bin/bash
# country
COUNTRY='IR'
# network: check network before create iso file
INTERFACE_DEV='eth0'
INTERFACE_IP='10.1.1.100'
INTERFACE_NETMASK='255.255.255.0'
INTERFACE_GATEWAY='10.1.1.1'
INTERFACE_NAMESERVERS='4.2.2.4'
# preseed file: upload created preseed.cfg to your own host before reboot system
PRESEED_URL="http://10.1.1.2/preseed.cfg"
# ssh installer password
PASSWORD="tHISiSpASSWORD"
# hostname and domain
HOSTNAME="${INTERFACE_IP//\./\-}-$COUNTRY_LOWER"
DOMAIN="servers.aasaam.net"
# lowercase of country code dont change it
COUNTRY_LOWER="${COUNTRY,,}"
```
4. Upload your `preseed.cfg` file to your own host.
#### Clone repository
```
cd /tmp
git clone https://github.com/mhf-ir/ubuntu-overssh-reinstallation.git
cd ubuntu-overssh-reinstallation
```
#### Config
See `config.sample` and change it. Carefull about your network settings. It's can hold your server until get new kvm/ipmi/vnc to restore the ssh again.
```
cp config.sample config
vim config
```
#### Download network mini iso from ubuntu website
```
wget http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso
```
#### Build iso
Remember you must do as root user
```
./create-iso.sh
...
Your network iso is ready '/tmp//ubuntu-overssh-reinstallation/ubuntu-overssh-reinstall.iso'
```
#### Update grub imageboot
Remember you must do as root user also
```
./grub.sh
...
Your password is tHISiSpASSWORD
```
#### Reboot
```
reboot
```
#### Get ssh
Wait it until boot to iso complete and install require packages then
```
ssh [email protected]
```
#### Continue installation of ubuntu
---
This script test on Ubuntu 16.04 Server.

+ 24
- 0
config.sample View File

@ -0,0 +1,24 @@
#!/bin/bash
# country
COUNTRY='IR'
# network: check network before create iso file
INTERFACE_DEV='eth0'
INTERFACE_IP='10.1.1.100'
INTERFACE_NETMASK='255.255.255.0'
INTERFACE_GATEWAY='10.1.1.1'
INTERFACE_NAMESERVERS='4.2.2.4'
# preseed file: upload created preseed.cfg to your own host before reboot system
PRESEED_URL="http://10.1.1.2/preseed.cfg"
# ssh installer password
PASSWORD="tHISiSpASSWORD"
# hostname and domain
HOSTNAME="${INTERFACE_IP//\./\-}-$COUNTRY_LOWER"
DOMAIN="servers.aasaam.net"
# lowercase of country code dont change it
COUNTRY_LOWER="${COUNTRY,,}"

+ 84
- 0
create-iso.sh View File

@ -0,0 +1,84 @@
#!/bin/bash
# logo
echo -e "Ubuntu Overssh Reinstallation: Create iso file"
# check for root user
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# default iso url
DEFAULT_ISO_URL='http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso'
# check dependencies
echo "Checking dependencies...".
REQUIRE_COMMAND[0]='realpath'
REQUIRE_COMMAND[1]='mkisofs'
REQUIRE_COMMAND[2]='dirname'
REQUIRE_COMMAND[3]='awk'
REQUIRE_COMMAND[4]='cut'
REQUIRE_COMMAND[5]='head'
REQUIRE_COMMAND[6]='grep'
REQUIRE_COMMAND[7]='apt-get'
REQUIRE_COMMAND[8]='update-grub'
for command in "${REQUIRE_COMMAND[@]}"
do
if ! type ${command} > /dev/null 2>&1; then
echo "Please install '${command}' for continue installation"
exit 1
fi
done
echo "Done"
SCRIPT=`realpath $0`
PROJECTPATH=`dirname $SCRIPT`
CONFIGFILE=$PROJECTPATH/config
if [ ! -f $CONFIGFILE ]; then
echo "Please create config file config"
exit 1
fi
source $CONFIGFILE
ISO_FILE=$PROJECTPATH/mini.iso
if [ ! -f $ISO_FILE ]; then
echo "File mini.iso not found. Download it $DEFAULT_ISO_URL"
exit 1
fi
# copy iso
umount /mnt/ubuntu-overssh-iso 2> /dev/null
mkdir -p /mnt/ubuntu-overssh-iso
mount -o loop $ISO_FILE /mnt/ubuntu-overssh-iso 2> /dev/null
rm -rf $PROJECTPATH/ubuntu-overssh-iso
mkdir $PROJECTPATH/ubuntu-overssh-iso
cp -rT /mnt/ubuntu-overssh-iso $PROJECTPATH/ubuntu-overssh-iso
# create preseed
cp $PROJECTPATH/preseed.cfg.template $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
# replace vairables
sed -i 's/timeout 0/timeout 1/g' $PROJECTPATH/ubuntu-overssh-iso/prompt.cfg
sed -i 's/timeout 0/timeout 1/g' $PROJECTPATH/ubuntu-overssh-iso/isolinux.cfg
sed -i "s/INTERFACE_DEV/$INTERFACE_DEV/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/INTERFACE_IP/$INTERFACE_IP/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/INTERFACE_NAMESERVERS/$INTERFACE_NAMESERVERS/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/INTERFACE_NETMASK/$INTERFACE_NETMASK/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/INTERFACE_GATEWAY/$INTERFACE_GATEWAY/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/COUNTRY_LOWER/$COUNTRY_LOWER/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/COUNTRY/$COUNTRY/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/HOSTNAME/$HOSTNAME/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/DOMAIN/$DOMAIN/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s/PASSWORD/$PASSWORD/g" $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg
sed -i "s#append #append priority=critical auto=true preseed/url=$PRESEED_URL netcfg/hostname=$HOSTNAME netcfg/domain=$DOMAIN interface=$INTERFACE_DEV netcfg/disable_dhcp=true netcfg/get_ipaddress=$INTERFACE_IP netcfg/get_netmask=$INTERFACE_NETMASK netcfg/get_gateway=$INTERFACE_GATEWAY netcfg/get_nameservers=$INTERFACE_NAMESERVERS #g" $PROJECTPATH/ubuntu-overssh-iso/txt.cfg
cp $PROJECTPATH/ubuntu-overssh-iso/preseed.cfg $PROJECTPATH/preseed.cfg
mkisofs -D -r -V UBUNTU_SERVER -cache-inodes -J -l -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $PROJECTPATH/ubuntu-overssh-reinstall.iso $PROJECTPATH/ubuntu-overssh-iso
echo "Your network iso is ready '$PROJECTPATH/ubuntu-overssh-reinstall.iso'"

+ 87
- 0
grub.sh View File

@ -0,0 +1,87 @@
#!/bin/bash
# logo
echo -e "Ubuntu Overssh Reinstallation: Update grub"
# check for root user
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# default iso url
DEFAULT_ISO_URL='http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso'
# check dependencies
echo "Checking dependencies...".
REQUIRE_COMMAND[0]='realpath'
REQUIRE_COMMAND[1]='mkisofs'
REQUIRE_COMMAND[2]='dirname'
REQUIRE_COMMAND[3]='awk'
REQUIRE_COMMAND[4]='cut'
REQUIRE_COMMAND[5]='head'
REQUIRE_COMMAND[6]='grep'
REQUIRE_COMMAND[7]='apt-get'
REQUIRE_COMMAND[8]='update-grub'
for command in "${REQUIRE_COMMAND[@]}"
do
if ! type ${command} > /dev/null 2>&1; then
echo "Please install '${command}' for continue installation"
exit 1
fi
done
echo "Done"
SCRIPT=`realpath $0`
PROJECTPATH=`dirname $SCRIPT`
CONFIGFILE=$PROJECTPATH/config
if [ ! -f $CONFIGFILE ]; then
echo "Please create config file config"
exit 1
fi
UBUNTUOVERSSHISO_FILE=$PROJECTPATH/ubuntu-overssh-reinstall.iso
if [ ! -f $UBUNTUOVERSSHISO_FILE ]; then
echo "Please create image first."
exit 1
fi
source $CONFIGFILE
apt-get install -y -qq grub-imageboot
if [ ! -f /etc/default/grub ]; then
echo "Seems be grub dosnt install or not matched version"
exit 1
fi
rm /boot/images -rf
mkdir -p /boot/images/
cp $UBUNTUOVERSSHISO_FILE /boot/images/iso.iso
update-grub
BOOTABLEGRUBNAME=`cat /boot/grub/grub.cfg | grep iso | head -n 1 | cut -d \" -f2`
if [ -z "$BOOTABLEGRUBNAME" ]; then
echo "Seems be grub imageboot not work as expected. try manual"
exit 1
fi
GRUBBACKUPFILE=$PROJECTPATH/grub.backup
if [ ! -f $GRUBBACKUPFILE ]; then
cp /etc/default/grub $GRUBBACKUPFILE
fi
sed -i "s/GRUB_DEFAULT=0/GRUB_DEFAULT='$BOOTABLEGRUBNAME'/g" /etc/default/grub
update-grub
echo "1. Upload 'preseed.cfg' file for $PRESEED_URL"
echo " ==================================== "
cat $PROJECTPATH/preseed.cfg
echo " ==================================== "
echo "2. Reboot current machine and wait to init to ssh installer"
echo "3. Connect using ssh client ssh [email protected]$INTERFACE_IP"
echo "4. Your password is $PASSWORD"

+ 21
- 0
preseed.cfg.template View File

@ -0,0 +1,21 @@
d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string COUNTRY
d-i debian-installer/locale string en_US.UTF-8
d-i netcfg/choose_interface select INTERFACE_DEV
d-i netcfg/link_wait_timeout string 1
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Configure network manually
d-i netcfg/get_ipaddress string INTERFACE_IP
d-i netcfg/get_netmask string INTERFACE_NETMASK
d-i netcfg/get_gateway string INTERFACE_GATEWAY
d-i netcfg/get_nameservers string INTERFACE_NAMESERVERS
d-i netcfg/confirm_static boolean true
d-i netcfg/hostname string HOSTNAME
d-i netcfg/domain string DOMAIN
d-i netcfg/wireless_wep string
d-i hw-detect/load_firmware boolean true
d-i anna/choose_modules string network-console
d-i network-console/password password PAASWORD
d-i network-console/password-again password PAASWORD

Loading…
Cancel
Save