Reinstall Ubuntu remotely using SSH
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. # Ubuntu Overssh Reinstallation
  2. 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.
  3. 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.
  4. Ask them to install ubuntu server what ever is it. re install it over ssh.
  5. 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.
  6. ### Requirement
  7. 1. Installed ubuntu version on server via ssh access
  8. 2. Clone this repo to your server
  9. 3. Copy `config.sample` to `config` file and edit field by field exactly:
  10. ```
  11. # country
  12. COUNTRY='IR'
  13. # network: check network before create iso file
  14. INTERFACE_DEV='eth0'
  15. INTERFACE_IP='10.1.1.100'
  16. INTERFACE_NETMASK='255.255.255.0'
  17. INTERFACE_GATEWAY='10.1.1.1'
  18. INTERFACE_NAMESERVERS='4.2.2.4'
  19. # preseed file: upload created preseed.cfg to your own host before reboot system
  20. PRESEED_URL="http://yourserver.tld/preseed.cfg"
  21. # ssh installer password
  22. PASSWORD="tHISiSpASSWORD"
  23. # hostname and domain
  24. HOSTNAME="${INTERFACE_IP//\./\-}"
  25. DOMAIN="servers.domain.org"
  26. # lowercase of country code dont change it
  27. COUNTRY_LOWER="${COUNTRY,,}"
  28. ```
  29. 4. Upload your `preseed.cfg` file to your own host.
  30. #### Clone repository
  31. ```
  32. cd /tmp
  33. git clone https://github.com/mhf-ir/ubuntu-overssh-reinstallation.git
  34. cd ubuntu-overssh-reinstallation
  35. ```
  36. #### Config
  37. 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.
  38. ```
  39. cp config.sample config
  40. vim config
  41. ```
  42. #### Download network mini iso from ubuntu website
  43. ```
  44. wget http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso
  45. ```
  46. #### Build iso
  47. Remember you must do as root user
  48. ```
  49. ./create-iso.sh
  50. ...
  51. Your network iso is ready '/tmp/ubuntu-overssh-reinstallation/ubuntu-overssh-reinstall.iso'
  52. ```
  53. #### Update grub imageboot
  54. Remember you must do as root user also
  55. ```
  56. ./grub.sh
  57. ...
  58. Your password is tHISiSpASSWORD
  59. ```
  60. #### Upload your preseed file
  61. Upload your preseed.cfg file to configured location `PRESEED_URL`.
  62. You can test it. We must get 200 response as we expected
  63. ```
  64. curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://yourserver.tld/preseed.cfg
  65. 200
  66. ```
  67. #### Reboot
  68. ```
  69. reboot
  70. ```
  71. #### Get ssh
  72. Wait it until boot to iso complete and install require packages then
  73. ```
  74. ssh [email protected]
  75. ```
  76. #### Continue installation of ubuntu
  77. ---
  78. This script test on Ubuntu 16.04 Server.