Install Linux from Linux – How to Install Linux from an Existing Linux System

linuxsystem-installation

I recently purchased an external USB hard drive and wanted to use it as a portable boot drive. I installed Linux Mint 18.1 on it and got everything working.

Then I started to think about using that drive to install Linux on other machines. I assumed that whatever a live boot USB does should be possible from a full-blown Linux installation. I looked around and the only option I found was from Ubuntu: Installation/From Linux. Their solution is to create a partition, fill it with the ISO contents and then boot from that to launch the installer.
I did follow those instructions and got it working as expected, however, I still feel there must be a way to install Linux from Linux without booting into an ISO.

I just found a related question: Installing without booting. There is an answer there that suggests there is some sequence of operations that could be run to install Linux on another partition, but I would need more detail than provided there. Is that process documented somewhere?

Honestly, I would be more comfortable if I could just run the installers that are included in the live boot images of each distro. Or some kind of semi-authoritative script that would do the same thing. Is there a package in the repos that would provide such a thing (eg. a Linux Mint installer package that could be installed using apt-get or yum)?

Best Answer

There is an example to install debian from a Linux-mint live USB (or any debian based distro). If you have a debian based distribution already installed on your hdd , you can install other debian based distro using chroot and debootstrap from the existing OS.

Boot from the live USB .Use gparted to create your root , swap ,/home... partitions.

If you prefer the command line ( fdisk , parted ..) , there is how to activate the swap partition :

mkswap /dev/sdaY
sync
swapon /dev/sdaY

Let's say you need to install debian stretch .

Install the debootstrap package :

sudo apt-get install debootstrap

Create the /mnt/stable then mount your root partition (sdaX)

sudo mkdir /mnt/stable
sudo  mount /dev/sdaX /mnt/stable

Install the base system:

sudo debootstrap --arch amd64 stretch /mnt/stable http://ftp.fr.debian.org/debian
sudo mount -t proc none /mnt/stable/proc
sudo mount -o bind /dev /mnt/stable/dev
sudo chroot /mnt/stable /bin/bash

Set up your root password:

passwd

Add a new user:

adduser your-username

Set up the hostname :

echo your_hostname > /etc/hostname

Configure the /etc/fstab:

add the following lines:

/dev/sdaX        /             ext4    defaults                 0    1
/dev/sdaY         none          swap    sw                      0    0
proc             /proc         proc    defaults                 0    0

use the debian documentation to edit your sources.list (replace jessie by stretch)

Configure locale :

apt-get install locales
dpkg-reconfigure locales

Configure you keyboard:

apt-get install console-data
dpkg-reconfigure console-data

Install the kernel:

apt-cache search linux-image

Then:

apt-get install linux-image-4.9.0-3-amd64

Configure the network:

editor /etc/network/interfaces

and past the following:

auto lo
iface lo inet loopback

allow-hotplug eth0 # replace eth0 with your interface
iface eth0 inet dhcp

allow-hotplug wlan0 # replace wlan0 with your interface
iface wlan0 inet dhcp

To manage the wifi network install the following packages:

apt-get install net-tools network-manager wireless-tools

Install grub :

apt-get install grub2
grub-install /dev/sda
update-grub

You can install a desktop environment through the command tasksel :

apt-get install aptitude tasksel

Run the following command and install your favorite GUI:

tasksel

Finally exit the chroot and reboot your system

Documentation: D.3. Installing Debian GNU/Linux from a Unix/Linux System

Debian wiki:

Related Question