Updata README.md

This commit is contained in:
Marcos Vallim 2020-01-27 12:26:30 -03:00
parent d0a3d52636
commit 86f0a12fc4
No known key found for this signature in database
GPG Key ID: 25CC9724E702C72F
1 changed files with 142 additions and 83 deletions

185
README.md
View File

@ -6,7 +6,7 @@ This procedure shows how to create a **bootable** and **installable** Ubuntu Liv
Install applications we need to build the environment. Install applications we need to build the environment.
``` ```shell
sudo apt-get install \ sudo apt-get install \
binutils \ binutils \
debootstrap \ debootstrap \
@ -17,14 +17,15 @@ sudo apt-get install \
mtools mtools
``` ```
``` ```shell
mkdir $HOME/live-ubuntu-from-scratch mkdir $HOME/live-ubuntu-from-scratch
``` ```
## Bootstrap and Configure Ubuntu ## Bootstrap and Configure Ubuntu
* Checkout bootstrap * Checkout bootstrap
```
```shell
sudo debootstrap \ sudo debootstrap \
--arch=amd64 \ --arch=amd64 \
--variant=minbase \ --variant=minbase \
@ -32,14 +33,17 @@ mkdir $HOME/live-ubuntu-from-scratch
$HOME/live-ubuntu-from-scratch/chroot \ $HOME/live-ubuntu-from-scratch/chroot \
http://us.archive.ubuntu.com/ubuntu/ http://us.archive.ubuntu.com/ubuntu/
``` ```
> **debootstrap** is used to create a Debian base system from scratch, without requiring the availability of **dpkg** or **apt**. It does this by downloading .deb files from a mirror site, and carefully unpacking them into a directory which can eventually be **chrooted** into. > **debootstrap** is used to create a Debian base system from scratch, without requiring the availability of **dpkg** or **apt**. It does this by downloading .deb files from a mirror site, and carefully unpacking them into a directory which can eventually be **chrooted** into.
* Configure external mount points * Configure external mount points
```
```shell
sudo mount --bind /dev $HOME/live-ubuntu-from-scratch/chroot/dev sudo mount --bind /dev $HOME/live-ubuntu-from-scratch/chroot/dev
sudo mount --bind /run $HOME/live-ubuntu-from-scratch/chroot/run sudo mount --bind /run $HOME/live-ubuntu-from-scratch/chroot/run
``` ```
As we will be updating and installing packages (grub among them), these mount points are necessary inside the chroot environment, so we are able to finish the installation without errors. As we will be updating and installing packages (grub among them), these mount points are necessary inside the chroot environment, so we are able to finish the installation without errors.
## Define chroot environment ## Define chroot environment
@ -49,12 +53,14 @@ mkdir $HOME/live-ubuntu-from-scratch
> Reference: https://en.wikipedia.org/wiki/Chroot > Reference: https://en.wikipedia.org/wiki/Chroot
1. **Access chroot environment** 1. **Access chroot environment**
```
```shell
sudo chroot $HOME/live-ubuntu-from-scratch/chroot sudo chroot $HOME/live-ubuntu-from-scratch/chroot
``` ```
2. **Configure mount points, home and locale** 2. **Configure mount points, home and locale**
```
```shell
mount none -t proc /proc mount none -t proc /proc
mount none -t sysfs /sys mount none -t sysfs /sys
@ -69,12 +75,14 @@ mkdir $HOME/live-ubuntu-from-scratch
These mount points are necessary inside the chroot environment, so we are able to finish the installation without errors. These mount points are necessary inside the chroot environment, so we are able to finish the installation without errors.
3. **Set a custom hostname** 3. **Set a custom hostname**
```
```shell
echo "ubuntu-fs-live" > /etc/hostname echo "ubuntu-fs-live" > /etc/hostname
``` ```
4. **Configure apt sources.list** 4. **Configure apt sources.list**
```
```shell
cat <<EOF > /etc/apt/sources.list cat <<EOF > /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
@ -88,33 +96,40 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
5. **Update indexes packages** 5. **Update indexes packages**
```
```shell
apt-get update apt-get update
``` ```
6. **Install systemd** 6. **Install systemd**
```
```shell
apt-get install -y systemd-sysv apt-get install -y systemd-sysv
``` ```
> **systemd** is a system and service manager for Linux. It provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. > **systemd** is a system and service manager for Linux. It provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic.
7. **Configure machine-id and divert** 7. **Configure machine-id and divert**
```
```shell
dbus-uuidgen > /etc/machine-id dbus-uuidgen > /etc/machine-id
ln -fs /etc/machine-id /var/lib/dbus/machine-id ln -fs /etc/machine-id /var/lib/dbus/machine-id
``` ```
> The `/etc/machine-id` file contains the unique machine ID of the local system that is set during installation or boot. The machine ID is a single newline-terminated, hexadecimal, 32-character, lowercase ID. When decoded from hexadecimal, this corresponds to a 16-byte/128-bit value. This ID may not be all zeros. > The `/etc/machine-id` file contains the unique machine ID of the local system that is set during installation or boot. The machine ID is a single newline-terminated, hexadecimal, 32-character, lowercase ID. When decoded from hexadecimal, this corresponds to a 16-byte/128-bit value. This ID may not be all zeros.
``` ```shell
dpkg-divert --local --rename --add /sbin/initctl dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl ln -s /bin/true /sbin/initctl
``` ```
> **dpkg-divert** is the utility used to set up and update the list of diversions. > **dpkg-divert** is the utility used to set up and update the list of diversions.
8. **Install packages needed for Live System** 8. **Install packages needed for Live System**
```
```shell
apt-get install -y \ apt-get install -y \
ubuntu-standard \ ubuntu-standard \
casper \ casper \
@ -149,7 +164,8 @@ mkdir $HOME/live-ubuntu-from-scratch
</p> </p>
9. **Graphical installer** 9. **Graphical installer**
```
```shell
apt-get install -y \ apt-get install -y \
ubiquity \ ubiquity \
ubiquity-casper \ ubiquity-casper \
@ -175,7 +191,8 @@ mkdir $HOME/live-ubuntu-from-scratch
</p> </p>
10. **Install window manager** 10. **Install window manager**
```
```shell
apt-get install -y \ apt-get install -y \
plymouth-theme-ubuntu-logo \ plymouth-theme-ubuntu-logo \
ubuntu-gnome-desktop \ ubuntu-gnome-desktop \
@ -183,7 +200,8 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
11. **Install useful applications** 11. **Install useful applications**
```
```shell
apt-get install -y \ apt-get install -y \
clamav-daemon \ clamav-daemon \
terminator \ terminator \
@ -197,7 +215,8 @@ mkdir $HOME/live-ubuntu-from-scratch
12. **Install Visual Studio Code (optional)** 12. **Install Visual Studio Code (optional)**
1. Download and install the key 1. Download and install the key
```
```shell
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
@ -208,7 +227,8 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
2. Then update the package cache and install the package using 2. Then update the package cache and install the package using
```
```shell
apt-get update apt-get update
apt-get install -y code apt-get install -y code
@ -217,28 +237,32 @@ mkdir $HOME/live-ubuntu-from-scratch
13. **Install Google Chrome (optional)** 13. **Install Google Chrome (optional)**
1. Download and install the key 1. Download and install the key
```
```shell
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
``` ```
2. Then update the package cache and install the package using 2. Then update the package cache and install the package using
```
```shell
apt-get update apt-get update
apt-get install google-chrome-stable apt-get install google-chrome-stable
``` ```
14. **Install Java JDK 8 (optional)** 14. **Install Java JDK 8 (optional)**
```
```shell
apt-get install -y \ apt-get install -y \
openjdk-8-jdk \ openjdk-8-jdk \
openjdk-8-jre openjdk-8-jre
``` ```
15. **Remove unused applications (optional)** 15. **Remove unused applications (optional)**
```
```shell
apt-get purge -y \ apt-get purge -y \
transmission-gtk \ transmission-gtk \
transmission-common \ transmission-common \
@ -250,14 +274,16 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
16. **Remove unused packages** 16. **Remove unused packages**
```
```shell
apt-get autoremove -y apt-get autoremove -y
``` ```
17. **Reconfigure packages** 17. **Reconfigure packages**
1. Generate locales 1. Generate locales
```
```shell
dpkg-reconfigure locales dpkg-reconfigure locales
``` ```
@ -272,7 +298,8 @@ mkdir $HOME/live-ubuntu-from-scratch
</p> </p>
2. Reconfigure resolvconf 2. Reconfigure resolvconf
```
```shell
dpkg-reconfigure resolvconf dpkg-reconfigure resolvconf
``` ```
@ -290,7 +317,8 @@ mkdir $HOME/live-ubuntu-from-scratch
</p> </p>
3. Configure network-manager 3. Configure network-manager
```
```shell
cat <<EOF > /etc/NetworkManager/NetworkManager.conf cat <<EOF > /etc/NetworkManager/NetworkManager.conf
[main] [main]
rc-manager=resolvconf rc-manager=resolvconf
@ -303,26 +331,30 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
4. Reconfigure network-manager 4. Reconfigure network-manager
```
```shell
dpkg-reconfigure network-manager dpkg-reconfigure network-manager
``` ```
18. **Cleanup the chroot environment** 18. **Cleanup the chroot environment**
1. If you installed software, be sure to run 1. If you installed software, be sure to run
```
```shell
truncate -s 0 /etc/machine-id truncate -s 0 /etc/machine-id
``` ```
2. Remove the diversion 2. Remove the diversion
```
```shell
rm /sbin/initctl rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl dpkg-divert --rename --remove /sbin/initctl
``` ```
3. Clean up 3. Clean up
```
```shell
apt-get clean apt-get clean
rm -rf /tmp/* ~/.bash_history rm -rf /tmp/* ~/.bash_history
@ -339,7 +371,8 @@ mkdir $HOME/live-ubuntu-from-scratch
``` ```
## Unbind mount points ## Unbind mount points
```
```shell
sudo umount $HOME/live-ubuntu-from-scratch/chroot/dev sudo umount $HOME/live-ubuntu-from-scratch/chroot/dev
sudo umount $HOME/live-ubuntu-from-scratch/chroot/run sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
@ -348,29 +381,34 @@ sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
## Create the CD image directory and populate it ## Create the CD image directory and populate it
1. Access build directory 1. Access build directory
```
```shell
cd $HOME/live-ubuntu-from-scratch cd $HOME/live-ubuntu-from-scratch
``` ```
2. Create directories 2. Create directories
```
```shell
mkdir -p image/{casper,isolinux,install} mkdir -p image/{casper,isolinux,install}
``` ```
2. Copy kernel images 3. Copy kernel images
```
```shell
sudo cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz sudo cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz
sudo cp chroot/boot/initrd.img-**-**-generic image/casper/initrd sudo cp chroot/boot/initrd.img-**-**-generic image/casper/initrd
``` ```
3. Copy memtest86+ binary (BIOS) 4. Copy memtest86+ binary (BIOS)
```
```shell
sudo cp chroot/boot/memtest86+.bin image/install/memtest86+ sudo cp chroot/boot/memtest86+.bin image/install/memtest86+
``` ```
4. Download and extract memtest86 binary (UEFI) 5. Download and extract memtest86 binary (UEFI)
```
```shell
wget --progress=dot https://www.memtest86.com/downloads/memtest86-usb.zip -O image/install/memtest86-usb.zip wget --progress=dot https://www.memtest86.com/downloads/memtest86-usb.zip -O image/install/memtest86-usb.zip
unzip -p image/install/memtest86-usb.zip memtest86-usb.img > image/install/memtest86 unzip -p image/install/memtest86-usb.zip memtest86-usb.img > image/install/memtest86
@ -381,17 +419,20 @@ sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
## Grub configuration ## Grub configuration
1. Access build directory 1. Access build directory
```
```shell
cd $HOME/live-ubuntu-from-scratch cd $HOME/live-ubuntu-from-scratch
``` ```
2. Create base point access file for grub 2. Create base point access file for grub
```
```shell
touch image/ubuntu touch image/ubuntu
``` ```
2. Create image/isolinux/grub.cfg 3. Create image/isolinux/grub.cfg
```
```shell
cat <<EOF > image/isolinux/grub.cfg cat <<EOF > image/isolinux/grub.cfg
search --set=root --file /ubuntu search --set=root --file /ubuntu
@ -431,15 +472,18 @@ sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
``` ```
## Create manifest ## Create manifest
In the next steps the creation of the manifest is important because it tells us which version of each package installed in the Live version and which packages will be removed or maintained in the version that will be installed (persisted in the hard drive). In the next steps the creation of the manifest is important because it tells us which version of each package installed in the Live version and which packages will be removed or maintained in the version that will be installed (persisted in the hard drive).
1. Access build directory 1. Access build directory
```
```shell
cd $HOME/live-ubuntu-from-scratch cd $HOME/live-ubuntu-from-scratch
``` ```
2. Generate manifest 2. Generate manifest
```
```shell
sudo chroot chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee image/casper/filesystem.manifest sudo chroot chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee image/casper/filesystem.manifest
sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop
@ -456,36 +500,43 @@ In the next steps the creation of the manifest is important because it tells us
``` ```
## Compress the chroot ## Compress the chroot
After everything has been installed and preconfigured in the **chrooted** environment, we need to generate an image of everything that was done by following the next steps. After everything has been installed and preconfigured in the **chrooted** environment, we need to generate an image of everything that was done by following the next steps.
1. Access build directory 1. Access build directory
```
```shell
cd $HOME/live-ubuntu-from-scratch cd $HOME/live-ubuntu-from-scratch
``` ```
2. Create squashfs 2. Create squashfs
```
```shell
sudo mksquashfs chroot image/casper/filesystem.squashfs sudo mksquashfs chroot image/casper/filesystem.squashfs
``` ```
> **Squashfs** is a highly compressed read-only filesystem for Linux. It uses zlib compression to compress both files, inodes and directories. Inodes in the system are very small and all blocks are packed to minimize data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
> **Squashfs** is a highly compressed read-only filesystem for Linux. It uses zlib compression to compress both files, inodes and directories. Inodes in the system are very small and all blocks are packed to minimize data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
> **Squashfs** is intended for general read-only filesystem use, for archival use (i.e. in cases where a .tar.gz file may be used), and in constrained block device/memory systems (e.g. **embedded systems**) where low overhead is needed. > **Squashfs** is intended for general read-only filesystem use, for archival use (i.e. in cases where a .tar.gz file may be used), and in constrained block device/memory systems (e.g. **embedded systems**) where low overhead is needed.
3. Write the filesystem.size 3. Write the filesystem.size
```
```shell
printf $(sudo du -sx --block-size=1 chroot | cut -f1) > image/casper/filesystem.size printf $(sudo du -sx --block-size=1 chroot | cut -f1) > image/casper/filesystem.size
``` ```
## Create diskdefines ## Create diskdefines
**README** file often found on Linux LiveCD installer discs, such as an Ubuntu Linux installation CD; typically named “**README.diskdefines**” and may be referenced during installation. **README** file often found on Linux LiveCD installer discs, such as an Ubuntu Linux installation CD; typically named “**README.diskdefines**” and may be referenced during installation.
1. Access build directory 1. Access build directory
```
```shell
cd $HOME/live-ubuntu-from-scratch cd $HOME/live-ubuntu-from-scratch
``` ```
2. Create file image/README.diskdefines 2. Create file image/README.diskdefines
```
```shell
cat <<EOF > image/README.diskdefines cat <<EOF > image/README.diskdefines
#define DISKNAME Ubuntu from scratch #define DISKNAME Ubuntu from scratch
#define TYPE binary #define TYPE binary
@ -502,12 +553,14 @@ After everything has been installed and preconfigured in the **chrooted** enviro
## Create ISO Image for a LiveCD (BIOS + UEFI) ## Create ISO Image for a LiveCD (BIOS + UEFI)
1. Access image directory 1. Access image directory
```
```shell
cd $HOME/live-ubuntu-from-scratch/image cd $HOME/live-ubuntu-from-scratch/image
``` ```
2. Create a grub UEFI image 2. Create a grub UEFI image
```
```shell
grub-mkstandalone \ grub-mkstandalone \
--format=x86_64-efi \ --format=x86_64-efi \
--output=isolinux/bootx64.efi \ --output=isolinux/bootx64.efi \
@ -516,8 +569,9 @@ After everything has been installed and preconfigured in the **chrooted** enviro
"boot/grub/grub.cfg=isolinux/grub.cfg" "boot/grub/grub.cfg=isolinux/grub.cfg"
``` ```
4. Create a FAT16 UEFI boot disk image containing the EFI bootloader 3. Create a FAT16 UEFI boot disk image containing the EFI bootloader
```
```shell
( (
cd isolinux && \ cd isolinux && \
dd if=/dev/zero of=efiboot.img bs=1M count=10 && \ dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
@ -527,8 +581,9 @@ After everything has been installed and preconfigured in the **chrooted** enviro
) )
``` ```
5. Create a grub BIOS image 4. Create a grub BIOS image
```
```shell
grub-mkstandalone \ grub-mkstandalone \
--format=i386-pc \ --format=i386-pc \
--output=isolinux/core.img \ --output=isolinux/core.img \
@ -539,18 +594,21 @@ After everything has been installed and preconfigured in the **chrooted** enviro
"boot/grub/grub.cfg=isolinux/grub.cfg" "boot/grub/grub.cfg=isolinux/grub.cfg"
``` ```
6. Combine a bootable Grub cdboot.img 5. Combine a bootable Grub cdboot.img
```
```shell
cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
``` ```
7. Generate md5sum.txt 6. Generate md5sum.txt
```
```shell
sudo /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)" sudo /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
``` ```
7. Create iso from the image directory using the command-line 7. Create iso from the image directory using the command-line
```
```shell
sudo xorriso \ sudo xorriso \
-as mkisofs \ -as mkisofs \
-iso-level 3 \ -iso-level 3 \
@ -577,6 +635,7 @@ After everything has been installed and preconfigured in the **chrooted** enviro
## Make a bootable USB image ## Make a bootable USB image
It is simple and easy, using "dd" It is simple and easy, using "dd"
```
```shell
sudo dd if=ubuntu-from-scratch.iso of=<device> status=progress oflag=sync sudo dd if=ubuntu-from-scratch.iso of=<device> status=progress oflag=sync
``` ```