live-custom-ubuntu-from-scr.../README.md

499 lines
11 KiB
Markdown
Raw Normal View History

2019-06-26 17:26:09 +00:00
# Live custom Ubuntu from scratch
## Prerequisites (GNU/Linux Debian/Ubuntu)
Install applications we need to build the environment.
```
sudo apt-get install \
debootstrap \
squashfs-tools \
genisoimage \
syslinux \
isolinux
```
```
mkdir $HOME/live-ubuntu-from-scratch
```
## Bootstrap and Configure Ubuntu
```
sudo debootstrap \
--arch=amd64 \
--variant=minbase \
bionic \
$HOME/live-ubuntu-from-scratch/chroot \
http://us.archive.ubuntu.com/ubuntu/
```
```
sudo mount --bind /dev $HOME/live-ubuntu-from-scratch/chroot/dev
sudo mount --bind /run $HOME/live-ubuntu-from-scratch/chroot/run
```
2019-06-26 19:45:45 +00:00
## Access chroot environment
2019-06-26 17:26:09 +00:00
```
sudo chroot $HOME/live-ubuntu-from-scratch/chroot
```
2019-06-26 19:45:45 +00:00
1. **Configure mount points**
2019-06-27 04:42:44 +00:00
```
mount none -t proc /proc
2019-06-26 19:12:53 +00:00
2019-06-27 04:42:44 +00:00
mount none -t sysfs /sys
2019-06-26 19:12:53 +00:00
2019-06-27 04:42:44 +00:00
mount none -t devpts /dev/pts
2019-06-26 19:12:53 +00:00
2019-06-27 04:42:44 +00:00
export HOME=/root
2019-06-26 19:12:53 +00:00
2019-06-27 04:42:44 +00:00
export LC_ALL=C
```
2019-06-26 19:12:53 +00:00
2019-06-26 19:45:45 +00:00
2. **Set a custom hostname**
2019-06-27 04:42:44 +00:00
```
echo "ubuntu-live" > /etc/hostname
```
2019-06-26 19:12:53 +00:00
2019-06-26 19:45:45 +00:00
3. **Configure apt sources.list**
2019-06-27 04:42:44 +00:00
```
cat <<EOF > /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
2019-06-27 19:43:34 +00:00
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
2019-06-26 19:12:53 +00:00
2019-06-27 04:42:44 +00:00
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
2019-06-27 19:43:34 +00:00
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
2019-06-27 19:43:34 +00:00
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
2019-06-27 04:42:44 +00:00
EOF
```
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
4. **Update indexes packages**
```
apt-get update
```
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
5. **Install systemd**
```
apt-get install -y systemd-sysv
```
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
5. **Configure machine-id and divert**
```
dbus-uuidgen > /var/lib/dbus/machine-id
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
```
2019-06-26 19:45:45 +00:00
6. **Install packages needed for Live System**
2019-06-27 04:42:44 +00:00
```
apt-get install -y \
ubuntu-standard \
casper \
lupin-casper \
discover \
laptop-detect \
os-prober \
network-manager \
2019-06-27 19:56:19 +00:00
resolvconf \
2019-06-27 04:42:44 +00:00
net-tools \
wireless-tools \
wpagui \
locales \
linux-generic
```
2019-06-27 19:54:51 +00:00
7. **Graphical installer**
2019-06-27 04:42:44 +00:00
```
apt-get install -y \
ubiquity \
ubiquity-casper \
ubiquity-frontend-gtk \
ubiquity-slideshow-ubuntu \
ubiquity-ubuntu-artwork
```
2019-06-26 19:45:45 +00:00
2019-06-27 19:54:51 +00:00
8. **Install window manager**
2019-06-27 04:42:44 +00:00
```
apt-get install -y \
2019-06-27 14:02:56 +00:00
plymouth-theme-ubuntu-logo \
2019-06-27 04:42:44 +00:00
ubuntu-gnome-desktop \
ubuntu-gnome-wallpapers
```
2019-06-26 19:45:45 +00:00
2019-06-27 19:54:51 +00:00
9. **Install usefull applications**
2019-06-27 04:42:44 +00:00
```
apt-get install -y \
clamav-daemon \
terminator \
apt-transport-https \
curl \
vim \
nano
```
2019-06-26 19:45:45 +00:00
2019-06-27 19:54:51 +00:00
10. **Install Visual Studio Code**
2019-06-26 19:45:45 +00:00
1. Download and install the key
2019-06-27 04:42:44 +00:00
```
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
rm microsoft.gpg
```
2019-06-26 19:45:45 +00:00
2. Then update the package cache and install the package using:
2019-06-27 04:42:44 +00:00
```
apt-get update
apt-get install -y code
```
2019-06-26 19:45:45 +00:00
2019-06-27 19:54:51 +00:00
11. **Install Google Chrome**
2019-06-26 19:45:45 +00:00
1. Download and install the key
2019-06-27 04:42:44 +00:00
```
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
```
2019-06-26 19:45:45 +00:00
2. Add the key to the repository
2019-06-27 04:42:44 +00:00
```
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
```
2019-06-26 19:45:45 +00:00
3. Finally, Update repository and install Google Chrome.
2019-06-27 04:42:44 +00:00
```
apt-get update
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
apt-get install google-chrome-stable
```
2019-06-26 19:45:45 +00:00
2019-06-27 19:54:51 +00:00
12. **Install Java JDK 8**
2019-06-26 19:45:45 +00:00
```
apt-get install -y \
openjdk-8-jdk \
openjdk-8-jre
```
2019-06-27 19:54:51 +00:00
13. **Remove unused applications**
2019-06-26 19:45:45 +00:00
```
apt-get purge -y \
transmission-gtk \
transmission-common \
gnome-mahjongg \
gnome-mines \
gnome-sudoku \
aisleriot \
hitori
```
2019-06-27 19:54:51 +00:00
14. **Remove unused packages**
2019-06-26 19:45:45 +00:00
```
apt-get autoremove -y
```
2019-06-27 19:54:51 +00:00
15. **Reconfigure packages**
1. **Generate locales**
```
dpkg-reconfigure locales
```
2. **Reconfigure resolvconf**
```
2019-06-27 21:02:56 +00:00
dpkg-reconfigure resolvconf
2019-06-27 19:54:51 +00:00
```
3. **Configure network-manager**
```
cat <<EOF > /etc/NetworkManager/NetworkManager.conf
[main]
rc-manager=resolvconf
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
EOF
```
4. **Reconfigure network-manager**
```
dpkg-reconfigure network-manager
```
15. **Cleanup the chroot environment**
2019-06-26 19:45:45 +00:00
1. If you installed software, be sure to run
2019-06-27 04:42:44 +00:00
```
rm /var/lib/dbus/machine-id
```
2019-06-26 19:45:45 +00:00
2. Remove the diversion
2019-06-27 04:42:44 +00:00
```
rm /sbin/initctl
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
dpkg-divert --rename --remove /sbin/initctl
```
2019-06-26 19:45:45 +00:00
3. Clean up
2019-06-27 04:42:44 +00:00
```
apt-get clean
rm -rf /tmp/* ~/.bash_history
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
umount /proc
umount /sys
umount /dev/pts
2019-06-26 19:45:45 +00:00
2019-06-27 04:42:44 +00:00
export HISTSIZE=0
exit
```
2019-06-26 19:45:45 +00:00
## Unbind mount points
```
sudo umount $HOME/live-ubuntu-from-scratch/chroot/dev
2019-06-26 19:12:53 +00:00
2019-06-26 19:45:45 +00:00
sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
2019-06-26 19:12:53 +00:00
```
2019-06-26 19:27:43 +00:00
## Create the CD image directory and populate it
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2. Create directories
```
mkdir -p image/{casper,isolinux,install}
```
2. Copy kernel images
```
2019-06-26 19:36:21 +00:00
sudo cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz
2019-06-26 19:27:43 +00:00
2019-06-27 02:27:28 +00:00
sudo cp chroot/boot/initrd.img-**-**-generic image/casper/initrd
2019-06-26 19:27:43 +00:00
```
3. Copy isolinux and memtest binaries
```
2019-06-26 19:36:21 +00:00
sudo cp /usr/lib/ISOLINUX/isolinux.bin image/isolinux/
2019-06-26 19:27:43 +00:00
2019-06-26 22:13:38 +00:00
sudo cp /usr/lib/syslinux/modules/bios/{chain,gfxboot,ldlinux,libutil,libcom32,vesamenu}.c32 image/isolinux/
2019-06-26 19:27:43 +00:00
2019-06-26 19:36:21 +00:00
sudo cp chroot/boot/memtest86+.bin image/install/memtest
2019-06-26 19:27:43 +00:00
```
2019-06-27 02:27:28 +00:00
2019-06-26 22:13:38 +00:00
## Boot Instructions
2019-06-27 02:27:28 +00:00
1. **Splash screen**
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2. Create image 640x480 in png format (splash.png)
<p align="center">
<img src="image/splash.png"><br>
</p>
3. Move image
```
2019-06-27 04:42:44 +00:00
sudo mv splash.png image/isolinux/
2019-06-27 02:27:28 +00:00
```
2. **Boot-loader configuration**
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2. Create image/isolinux/isolinux.cfg
```
cat <<EOF > image/isolinux/isolinux.cfg
path
include menu.cfg
default vesamenu.c32
prompt 0
timeout 50
EOF
```
3. Create image/isolinux/menu.cfg
```
cat <<EOF > image/isolinux/menu.cfg
menu hshift 13
menu width 49
menu margin 8
2019-06-27 19:57:53 +00:00
menu title Installer boot menu
2019-06-27 02:27:28 +00:00
include stdmenu.cfg
include txt.cfg
EOF
```
4. Create image/isolinux/stdmenu.cfg
```
cat <<EOF > image/isolinux/stdmenu.cfg
menu background splash.png
menu color title * #FFFFFFFF *
menu color border * #00000000 #00000000 none
menu color sel * #ffffffff #76a1d0ff *
menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *
menu color tabmsg * #ffffffff #00000000 *
menu color help 37;40 #ffdddd00 #00000000 none
menu vshift 12
menu rows 10
menu helpmsgrow 15
# The command line must be at least one line from the bottom.
menu cmdlinerow 16
menu timeoutrow 16
menu tabmsgrow 18
menu tabmsg Press ENTER to boot or TAB to edit a menu entry
EOF
```
5. Create image/isolinux/txt.cfg
```
cat <<EOF > image/isolinux/txt.cfg
default live
label live
menu label ^Try Ubuntu without installing
kernel /casper/vmlinuz
append file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd quiet splash ---
label live-install
menu label ^Install Ubuntu
kernel /casper/vmlinuz
append file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd quiet splash ---
label check
menu label ^Check disc for defects
kernel /casper/vmlinuz
append boot=casper integrity-check initrd=/casper/initrd quiet splash ---
label memtest
menu label Test ^memory
kernel /install/memtest
EOF
```
## Create manifest
2019-06-26 22:13:38 +00:00
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2019-06-27 02:27:28 +00:00
2. Generate manifest
```
sudo chroot chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee image/casper/filesystem.manifest
2019-06-26 22:13:38 +00:00
2019-06-27 02:27:28 +00:00
sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop
2019-06-26 22:13:38 +00:00
2019-06-27 14:49:19 +00:00
sudo sed -i '/ubiquity/d' image/casper/filesystem.manifest-desktop
sudo sed -i '/casper/d' image/casper/filesystem.manifest-desktop
sudo sed -i '/discover/d' image/casper/filesystem.manifest-desktop
sudo sed -i '/laptop-detect/d' image/casper/filesystem.manifest-desktop
sudo sed -i '/os-prober/d' image/casper/filesystem.manifest-desktop
2019-06-27 02:27:28 +00:00
```
2019-06-26 22:13:38 +00:00
2019-06-27 02:27:28 +00:00
## Compress the chroot
2019-06-26 22:13:38 +00:00
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2019-06-27 02:27:28 +00:00
2. Create squashfs
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
sudo mksquashfs chroot image/casper/filesystem.squashfs
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
3. Write the filesystem.size
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
printf $(sudo du -sx --block-size=1 chroot | cut -f1) > image/casper/filesystem.size
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
## Create diskdefines
2019-06-26 22:13:38 +00:00
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2019-06-27 02:27:28 +00:00
2. Create file image/README.diskdefines
```
cat <<EOF > image/README.diskdefines
#define DISKNAME Ubuntu from scratch
#define TYPE binary
#define TYPEbinary 1
#define ARCH amd64
#define ARCHamd64 1
#define DISKNUM 1
#define DISKNUM1 1
#define TOTALNUM 0
#define TOTALNUM0 1
EOF
```
2019-06-26 22:13:38 +00:00
2019-06-27 02:27:28 +00:00
## Recognition as an Ubuntu from scratch
2019-06-26 22:13:38 +00:00
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2019-06-27 02:27:28 +00:00
2. Create an empty file named "ubuntu" and a hidden ".disk" folder.
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
touch image/ubuntu
mkdir image/.disk
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
## Calculate MD5
2019-06-26 22:13:38 +00:00
1. Access build directory
```
cd $HOME/live-ubuntu-from-scratch
```
2019-06-27 02:27:28 +00:00
2. Generate md5sum.txt
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
sudo /bin/bash -c "(cd image && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
## Create ISO Image for a LiveCD
1. Access image directory
2019-06-26 22:13:38 +00:00
```
2019-06-27 02:27:28 +00:00
cd $HOME/live-ubuntu-from-scratch/image
```
2. Create iso from the image directory using the command-line
```
sudo genisoimage -D -r \
-V "Ubuntu from scratch" \
-cache-inodes -J -l \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table -o ../ubuntu-from-scratch.iso .
2019-06-27 14:02:56 +00:00
```