📜 ⬆️ ⬇️

Install Ubuntu / Debian via debootstrap from another Linux system

image Almost three years have passed since the publication of the last and only article on the topic about this business, and since then some things have changed. I want to immediately say that this post is a simplification and a merger of two great wiki pages written by my friend: one and two . If those pages are aimed at a complete and detailed description of the installation process, then I will try to simplify and speed up the installation process as much as possible, breaking it down into just three steps.

I myself consider this installation method to be the most adequate, since for all its simplicity, it has great flexibility, a freshly installed system has the latest versions of packages, and everything you need to complete the system can be installed before the first download to it. Under the cut, I will bring some scripts,

First, you will need a working Linux system, from which we will install a new system. Any distribution kit, as well as installed, and launched from LiveCD will do.
')

Step Zero: Hard Drive Preparation

First you need to partition the disk as your soul desires. There are many good instructions on the Internet, I usually use the graphical utility GParted. I strongly advise you to allocate / home in a separate section, when reinstalling / changing the distribution, this will avoid hemorrhoids with data transfer.

Mount all partitions in any directory (for example, / mnt / debian /). Further, even outside scripts, instead of / mnt / debian, I will use $ TARGET.

## ,  /dev/sda1 - root,  /dev/sda2 - home mkdir /mnt/debian mount /dev/sda1 /mnt/debian mkdir /mnt/debian/home mount /dev/sda2 /mnt/debian/home 


Step One: Forming the Base System

The script requires a working debootstrap, which is in the repositories of all deb-based distributions. Do not be afraid to correct variables and comment / uncomment the lines.

 #!/bin/bash ARCH=i386 #ARCH=amd64 ## 64-  - 32-   ##   debian OS=debian DISTRO=wheezy #DISTRO=stable ## ubuntu #OS=ubuntu #DISTRO=oneiric ##     TARGET=/mnt/debian ##       cdrom  : #debootstrap --include=sudo,nano,wget --arch $ARCH $DISTRO $TARGET file:/media/cdrom ##       debootstrap --include=sudo,nano,wget --arch $ARCH $DISTRO $TARGET http://$OS.mirror.vu.lt/$OS/ ##     ,       / mount -o bind /dev $TARGET/dev mount -o bind /sys $TARGET/sys 


Step Two: Initial Configuration

Configure the $ TARGET / etc / fstab file with a template:

 # /etc/fstab: static file system information. # # Use 'vol_id --uuid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 /boot ext2 defaults 0 0 /dev/sda2 / ext4 defaults 0 1 /dev/sda3 /home ext4 defaults 0 0 /dev/sda4 none swap sw 0 0 

In the example above, it will look like this:

 # /etc/fstab: static file system information. # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/sda1 / ext4 defaults 0 1 /dev/sda2 /home ext4 defaults 0 0 

And the $ TARGET / etc / apt / sources.list file. It can either be generated (generators for debian , ubuntu ), or use templates:

Template for debian
 deb http://http.debian.net/debian $DISTRO main contrib non-free # deb-src http://http.debian.net/debian $DISTRO main deb http://security.debian.org $DISTRO/updates main contrib non-free # deb-src http://security.debian.org $DISTRO/updates main deb http://http.debian.net/debian-backports $DISTRO-backports main non-free # deb-src http://http.debian.net/debian-backports $DISTRO-backports main deb http://http.debian.net/debian $DISTRO-proposed-updates main contrib non-free # deb-src http://http.debian.net/debian $DISTRO-proposed-updates main 
Ubuntu Template
 deb http://ru.archive.ubuntu.com/ubuntu $DISTRO main universe restricted multiverse # deb-src http://ru.archive.ubuntu.com/ubuntu $DISTRO main universe deb http://security.ubuntu.com/ubuntu $DISTRO-security main universe restricted multiverse # deb-src http://security.ubuntu.com/ubuntu $DISTRO-security main universe deb http://ru.archive.ubuntu.com/ubuntu $DISTRO-updates main universe restricted multiverse # deb-src http://ru.archive.ubuntu.com/ubuntu $DISTRO-updates main universe deb http://ru.archive.ubuntu.com/ubuntu $DISTRO-proposed main universe restricted multiverse # deb-src http://ru.archive.ubuntu.com/ubuntu $DISTRO-proposed main universe deb http://ru.archive.ubuntu.com/ubuntu $DISTRO-backports main universe restricted multiverse # deb-src http://ru.archive.ubuntu.com/ubuntu $DISTRO-backports main universe deb http://archive.canonical.com/ubuntu $DISTRO partner deb http://extras.ubuntu.com/ubuntu $DISTRO main # deb-src http://extras.ubuntu.com/ubuntu $DISTRO main 

Step Three: Everything Else

To do this, run the following script in chroot. Assuming that the script name is postinst.sh and it is in $ TARGET /, you need to run it like this:

 env LANG=C env HOME=/root chroot $TARGET /bin/bash /postinst.sh 

The script itself:

 #!/bin/bash ##    apt-get update ##    dpkg-reconfigure tzdata ##    mount -t proc /proc /proc mount -a ##      apt-get -y install popularity-contest ##    ,   ##   console-cyrillic  ,  , UniCyr,      «» apt-get -y install locales console-cyrillic dpkg-reconfigure locales dpkg-reconfigure console-cyrillic ##  hostname,   HOST='mysuperpc' echo "$HOST" > /etc/hostname echo -e "\n127.0.0.1 localhost $HOST" >> /etc/hosts ##  ,    sudo USER='mynotsuperuser' echo ' ' adduser $USER usermod -a -G sudo $USER ##   root echo '  root' passwd ##     ARCH=i686 #: i386, i486, i686, amd64 ## Debian: apt-get -y install linux-base linux-image-$ARCH linux-headers grub ## Ubuntu: # apt-get -y install linux-image-generic linux-headers-generic ##    apt-get -y install firmware-linux firmware-ralink firmware-realtek ##    ## Debian: apt-get -y install xorg kde-full #KDE #apt-get -y install xorg kde # <= Lenny #apt-get -y install xorg gnome #apt-get -y install xorg xfce lxdm #XFCE #apt-get -y install xorg lxde lxdm #LXDE ## Debian,  apt-get -y install pulseaudio apt-get -y install alsa-base alsa-tools alsa-utils alsa-oss ## Ubuntu: #apt-get -y install xorg kubuntu-desktop #KDE #apt-get -y install xorg ubuntu-desktop #Unity #apt-get -y install xorg gnome-shell gnome-themes-standard gnome-tweak-tool #Gnome3 #apt-get -y install xorg xubuntu-desktop #XFCE #apt-get -y install xorg lubuntu-desktop #LXDE 


If you need to put something else manually before rebooting, you can always enter the chroot environment with the command:

 env LANG=C env HOME=/root chroot $TARGET /bin/bash 

That's all. I posted a full set of scripts for a semi-automatic installation on github, so feel free to make suggestions and improvements in the form of pull-requests.

Source: https://habr.com/ru/post/147522/


All Articles