Ubuntu – Reinstall no CD OR USB

lubunturebootreinstallubuntu-core

My system is Ubuntu only, how do I completely reinstall Ubuntu from terminal deleting everything and resulting in a fresh install without USB OR CD

Best Answer

  • (1) Backup Your Files

    MAKE SURE YOU'VE COPIED YOUR FILES AND DATA TO A SAFE PLACE, NOT ON YOUR COMPUTER.

    (2) Download Ubuntu 17.10

    Download the 17.10 ISO from ubuntu.com (ubuntu-17.10-desktop-amd64.iso) and save it in your Downloads folder.

    (2) Create a Partition to Boot the Live ISO From

    Make sure you've completed step #1!!!

    Open the GParted application. If you don't have GParted, install it from the Software Center or use sudo apt install gparted.

    In the top right of the gparted window, you must make sure your current hard disk is selected. Since you mentioned you don't have a USB stick or CD, there should be only be one option in the dropdown for you. It will probably be somethig like /dev/sda, but make sure you have the right disk selected!

    Use gparted to resize your disk and create about 3 GB of space at the end of the disk.

    Then create a new primary partition in this space, and format it to the ext4 file system.

    Note the name of the partition; it may be something like /dev/sda3/.

    You can close GParted now.

    (3) Mount the New Partition

    Open the Disks application and select the partition you created above. (The Disks application calls this a "Device", but make sure it is the same as the partition name you noted in step #3).

    After selecting it, click in the "mount" icon.

    Disks will mount the partition and will display the mount point; it will look something like /media/nightx/xxxxx.

    Make a note of the actual mount point. For the rest of this answer, I will use /media/nightx/xxxxx, so replace as necessary. Make sure you can read and write to /media/nightx/xxxxx (try creating a text file and deleting it).

    You can close Disks now.

    (4) Copy the Live ISO to the New Partition

    Open a terminal, and enter the following:

    sudo cp ~/Downloads/ubuntu-17.10-desktop-amd64.iso /media/nightx/xxxxx
    

    (Make sure /media/nightx/xxxxx/ubuntu-17.10-desktop-amd64.iso is owned by root; using sudo to copy the file ensures this).

    (5) Edit Grub to Boot the Live ISO

    In a terminal, do the following:

    sudo gedit /etc/grub.d/40_custom
    

    Copy the following into this file.

    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
    
    menuentry "Install" {
        set isofile="/ubuntu-17.10-desktop-amd64.iso"
        loopback loop (hd<X>,<Y>)$isofile
        linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noprompt noeject
        initrd (loop)/casper/initrd.lz
    }
    

    In the text above, replace <X> as follows:

    • If your new partition name has an "a" (like "sda") replace <X> with "1"
    • If your new partition name has a "b" (like "sdb") replace <X> with "2"
    • If your new partition name has a "c" (like "sdc") replace <X> with "3"

    In the text above, replace <Y> as follows:

    • If your new partition name ends in "1" (like "sda1") replace <Y> with "1"
    • If your new partition name ends in "2" (like "sda2") replace <Y> with "2"
    • If your new partition name ends in "3" (like "sda3") replace <Y> with "3"

    For example, if your partition name is "sda3", in the 9th line above, you should use...

    loopback loop (hd1,3)$isofile
    

    Also note, there are no angle brackets (< or >) in the the final text.

    Finally, save the file (/etc/grub.d/40_custom) and exit Gedit.

    Type the following to double check that your changes were saved and are correct:

    cat /etc/grub.d/40_custom
    

    (6) Update Grub

    Now, update grub using:

    sudo update-grub
    

    Check the output and make sure you do not get any errors. If you see errors, double check step #5.

    (7) Boot to the Live ISO

    Restart your computer.

    Press the ESC.

    You will see the Grub Menu.

    (If you see your Ubuntu Login screen, you will need to restart and try hitting ESC at the right time).

    One of the Grub options will be "Install", which you had configured in step #5.

    Select "Install" using your arrow keys and press Enter.

    If you get an error message (~ about Grub not being able to find a boot file), that means you did not set <X> and <Y> correctly in step #5. You can return to step #5, and try different number combinations until you find the right designation for your new partition. Be sure to execute step #6 each time you edit /etc/grub.d/40_custom.

    (8) Prepare to Install

    If you were successful, you will boot into the Ubuntu Live ISO directly from your hard disk!!

    Before you click on the installer, be sure to do the following...

    Open a terminal window by typing CTRLALTT. In the terminal, type the following:

    umount -l /dev/sda3
    

    Rememebr to replace /dev/sda3 with the name of the new partition you noted in step #3. This command tricks the installer into thinking this partition is unmounted; in reality, the Live ISO is being accessed from there.

    (9) Install Ubuntu

    Make sure you've completed step #1!!! (This is your last warning!)

    Launch the Ubiquity installer to install Ubuntu.

    During the install, you should select the option "Something else", so you can explicitly avoid formatting /dev/sda3.

    The options "Erase Ubuntu..." or "Erase everything..." may work, but I don't have experience with these. (If you try either of these options, please comment back if they worked).