Compare commits
No commits in common. "master" and "bionic" have entirely different histories.
92
README.md
92
README.md
|
@ -1,9 +1,5 @@
|
||||||
# How to create a custom Ubuntu live from scratch
|
# How to create a custom Ubuntu live from scratch
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img src="images/live-boot.png">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
This procedure shows how to create a **bootable** and **installable** Ubuntu Live (along with the automatic hardware detection and configuration) from scratch.
|
This procedure shows how to create a **bootable** and **installable** Ubuntu Live (along with the automatic hardware detection and configuration) from scratch.
|
||||||
|
|
||||||
## Prerequisites (GNU/Linux Debian/Ubuntu)
|
## Prerequisites (GNU/Linux Debian/Ubuntu)
|
||||||
|
@ -33,7 +29,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
sudo debootstrap \
|
sudo debootstrap \
|
||||||
--arch=amd64 \
|
--arch=amd64 \
|
||||||
--variant=minbase \
|
--variant=minbase \
|
||||||
focal \
|
bionic \
|
||||||
$HOME/live-ubuntu-from-scratch/chroot \
|
$HOME/live-ubuntu-from-scratch/chroot \
|
||||||
http://us.archive.ubuntu.com/ubuntu/
|
http://us.archive.ubuntu.com/ubuntu/
|
||||||
```
|
```
|
||||||
|
@ -88,14 +84,14 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
cat <<EOF > /etc/apt/sources.list
|
cat <<EOF > /etc/apt/sources.list
|
||||||
deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
|
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
|
||||||
deb-src http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
|
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
|
||||||
|
|
||||||
deb http://us.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
|
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||||
deb-src http://us.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
|
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||||
|
|
||||||
deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
|
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||||
deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
|
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -108,7 +104,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
6. **Install systemd**
|
6. **Install systemd**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y libterm-readline-gnu-perl 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.
|
||||||
|
@ -131,13 +127,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
|
|
||||||
> **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. **Upgrade packages**
|
8. **Install packages needed for Live System**
|
||||||
|
|
||||||
```shell
|
|
||||||
apt-get -y upgrade
|
|
||||||
```
|
|
||||||
|
|
||||||
9. **Install packages needed for Live System**
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
|
@ -173,34 +163,34 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
<img src="images/grub-configure-03.png">
|
<img src="images/grub-configure-03.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
10. **Graphical installer**
|
9. **Graphical installer**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
ubiquity \
|
ubiquity \
|
||||||
ubiquity-casper \
|
ubiquity-casper \
|
||||||
ubiquity-frontend-gtk \
|
ubiquity-frontend-gtk \
|
||||||
ubiquity-slideshow-ubuntu \
|
ubiquity-slideshow-ubuntu \
|
||||||
ubiquity-ubuntu-artwork
|
ubiquity-ubuntu-artwork
|
||||||
```
|
```
|
||||||
|
|
||||||
The next steps will appear, as a result of the packages that will be installed from the previous step, this will happen without anything having to be informed or executed.
|
The next steps will appear, as a result of the packages that will be installed from the previous step, this will happen without anything having to be informed or executed.
|
||||||
|
|
||||||
1. Configure keyboard
|
1. Configure keyboard
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="images/keyboard-configure-01.png">
|
<img src="images/keyboard-configure-01.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="images/keyboard-configure-02.png">
|
<img src="images/keyboard-configure-02.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
2. Console setup
|
2. Console setup
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="images/console-configure-01.png">
|
<img src="images/console-configure-01.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
11. **Install window manager**
|
10. **Install window manager**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
|
@ -209,7 +199,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
ubuntu-gnome-wallpapers
|
ubuntu-gnome-wallpapers
|
||||||
```
|
```
|
||||||
|
|
||||||
12. **Install useful applications**
|
11. **Install useful applications**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
|
@ -222,7 +212,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
less
|
less
|
||||||
```
|
```
|
||||||
|
|
||||||
13. **Install Visual Studio Code (optional)**
|
12. **Install Visual Studio Code (optional)**
|
||||||
|
|
||||||
1. Download and install the key
|
1. Download and install the key
|
||||||
|
|
||||||
|
@ -244,7 +234,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
apt-get install -y code
|
apt-get install -y code
|
||||||
```
|
```
|
||||||
|
|
||||||
14. **Install Google Chrome (optional)**
|
13. **Install Google Chrome (optional)**
|
||||||
|
|
||||||
1. Download and install the key
|
1. Download and install the key
|
||||||
|
|
||||||
|
@ -262,7 +252,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
apt-get install google-chrome-stable
|
apt-get install google-chrome-stable
|
||||||
```
|
```
|
||||||
|
|
||||||
15. **Install Java JDK 8 (optional)**
|
14. **Install Java JDK 8 (optional)**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
|
@ -270,7 +260,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
openjdk-8-jre
|
openjdk-8-jre
|
||||||
```
|
```
|
||||||
|
|
||||||
16. **Remove unused applications (optional)**
|
15. **Remove unused applications (optional)**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get purge -y \
|
apt-get purge -y \
|
||||||
|
@ -283,13 +273,13 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
hitori
|
hitori
|
||||||
```
|
```
|
||||||
|
|
||||||
17. **Remove unused packages**
|
16. **Remove unused packages**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apt-get autoremove -y
|
apt-get autoremove -y
|
||||||
```
|
```
|
||||||
|
|
||||||
18. **Reconfigure packages**
|
17. **Reconfigure packages**
|
||||||
|
|
||||||
1. Generate locales
|
1. Generate locales
|
||||||
|
|
||||||
|
@ -346,7 +336,7 @@ mkdir $HOME/live-ubuntu-from-scratch
|
||||||
dpkg-reconfigure network-manager
|
dpkg-reconfigure network-manager
|
||||||
```
|
```
|
||||||
|
|
||||||
19. **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
|
||||||
|
|
||||||
|
@ -423,7 +413,7 @@ sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
rm -f image/install/memtest86-usb.zip
|
rm image/install/memtest86-usb.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
## Grub configuration
|
## Grub configuration
|
||||||
|
@ -453,7 +443,7 @@ sudo umount $HOME/live-ubuntu-from-scratch/chroot/run
|
||||||
set timeout=30
|
set timeout=30
|
||||||
|
|
||||||
menuentry "Try Ubuntu FS without installing" {
|
menuentry "Try Ubuntu FS without installing" {
|
||||||
linux /casper/vmlinuz boot=casper nopersistent toram quiet splash ---
|
linux /casper/vmlinuz boot=casper quiet splash ---
|
||||||
initrd /casper/initrd
|
initrd /casper/initrd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +603,7 @@ After everything has been installed and preconfigured in the **chrooted** enviro
|
||||||
6. Generate md5sum.txt
|
6. Generate md5sum.txt
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v -e 'md5sum.txt' -e 'bios.img' -e 'efiboot.img' > 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
|
||||||
|
@ -636,12 +626,10 @@ After everything has been installed and preconfigured in the **chrooted** enviro
|
||||||
-no-emul-boot \
|
-no-emul-boot \
|
||||||
-append_partition 2 0xef isolinux/efiboot.img \
|
-append_partition 2 0xef isolinux/efiboot.img \
|
||||||
-output "../ubuntu-from-scratch.iso" \
|
-output "../ubuntu-from-scratch.iso" \
|
||||||
-m "isolinux/efiboot.img" \
|
|
||||||
-m "isolinux/bios.img" \
|
|
||||||
-graft-points \
|
-graft-points \
|
||||||
"/EFI/efiboot.img=isolinux/efiboot.img" \
|
"." \
|
||||||
"/boot/grub/bios.img=isolinux/bios.img" \
|
/boot/grub/bios.img=isolinux/bios.img \
|
||||||
"."
|
/EFI/efiboot.img=isolinux/efiboot.img
|
||||||
```
|
```
|
||||||
|
|
||||||
## Make a bootable USB image
|
## Make a bootable USB image
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
theme: jekyll-theme-cayman
|
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
278
scripts/build.sh
278
scripts/build.sh
|
@ -1,278 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e # exit on error
|
|
||||||
set -o pipefail # exit on pipeline error
|
|
||||||
set -u # treat unset variable as error
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
||||||
|
|
||||||
CMD=(setup_host debootstrap run_chroot build_iso)
|
|
||||||
|
|
||||||
DATE=`TZ="UTC" date +"%y%m%d-%H%M%S"`
|
|
||||||
|
|
||||||
function help() {
|
|
||||||
# if $1 is set, use $1 as headline message in help()
|
|
||||||
if [ -z ${1+x} ]; then
|
|
||||||
echo -e "This script builds bootable ubuntu ISO image"
|
|
||||||
echo -e
|
|
||||||
else
|
|
||||||
echo -e $1
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
echo -e "Supported commands : ${CMD[*]}"
|
|
||||||
echo -e
|
|
||||||
echo -e "Syntax: $0 [start_cmd] [-] [end_cmd]"
|
|
||||||
echo -e "\trun from start_cmd to end_end"
|
|
||||||
echo -e "\tif start_cmd is omitted, start from first command"
|
|
||||||
echo -e "\tif end_cmd is omitted, end with last command"
|
|
||||||
echo -e "\tenter single cmd to run the specific command"
|
|
||||||
echo -e "\tenter '-' as only argument to run all commands"
|
|
||||||
echo -e
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function find_index() {
|
|
||||||
local ret;
|
|
||||||
local i;
|
|
||||||
for ((i=0; i<${#CMD[*]}; i++)); do
|
|
||||||
if [ "${CMD[i]}" == "$1" ]; then
|
|
||||||
index=$i;
|
|
||||||
return;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
help "Command not found : $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function chroot_enter_setup() {
|
|
||||||
sudo mount --bind /dev chroot/dev
|
|
||||||
sudo mount --bind /run chroot/run
|
|
||||||
sudo chroot chroot mount none -t proc /proc
|
|
||||||
sudo chroot chroot mount none -t sysfs /sys
|
|
||||||
sudo chroot chroot mount none -t devpts /dev/pts
|
|
||||||
}
|
|
||||||
|
|
||||||
function chroot_exit_teardown() {
|
|
||||||
sudo chroot chroot umount /proc
|
|
||||||
sudo chroot chroot umount /sys
|
|
||||||
sudo chroot chroot umount /dev/pts
|
|
||||||
sudo umount chroot/dev
|
|
||||||
sudo umount chroot/run
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_host() {
|
|
||||||
local os_ver;
|
|
||||||
os_ver=`lsb_release -d | grep "Ubuntu 20.04"`
|
|
||||||
if [[ $os_ver == "" ]]; then
|
|
||||||
echo "WARNING : OS is not Ubuntu 20.04 and is untested"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $(id -u) -eq 0 ]; then
|
|
||||||
echo "This script should not be run as 'root'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup_host() {
|
|
||||||
echo "=====> running setup_host ..."
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install -y binutils debootstrap squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin mtools
|
|
||||||
sudo mkdir -p chroot
|
|
||||||
}
|
|
||||||
|
|
||||||
function debootstrap() {
|
|
||||||
echo "=====> running debootstrap ... will take a couple of minutes ..."
|
|
||||||
sudo debootstrap --arch=amd64 --variant=minbase focal chroot http://us.archive.ubuntu.com/ubuntu/
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_chroot() {
|
|
||||||
echo "=====> running run_chroot ..."
|
|
||||||
|
|
||||||
chroot_enter_setup
|
|
||||||
|
|
||||||
sudo ln -f $SCRIPT_DIR/chroot_build.sh chroot/root/chroot_build.sh
|
|
||||||
sudo cp -f /etc/apt/sources.list chroot/etc/apt/
|
|
||||||
sudo chroot chroot /root/chroot_build.sh -
|
|
||||||
sudo rm -f chroot/root/chroot_build.sh
|
|
||||||
|
|
||||||
chroot_exit_teardown
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function build_iso() {
|
|
||||||
echo "=====> running build_iso ..."
|
|
||||||
|
|
||||||
rm -rf image
|
|
||||||
mkdir -p image/{casper,isolinux,install}
|
|
||||||
|
|
||||||
# copy kernel files
|
|
||||||
sudo cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz
|
|
||||||
sudo cp chroot/boot/initrd.img-**-**-generic image/casper/initrd
|
|
||||||
|
|
||||||
# memtest86
|
|
||||||
sudo cp chroot/boot/memtest86+.bin image/install/memtest86+
|
|
||||||
|
|
||||||
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
|
|
||||||
rm -f image/install/memtest86-usb.zip
|
|
||||||
|
|
||||||
# grub
|
|
||||||
touch image/ubuntu
|
|
||||||
cat <<EOF > image/isolinux/grub.cfg
|
|
||||||
|
|
||||||
search --set=root --file /ubuntu
|
|
||||||
|
|
||||||
insmod all_video
|
|
||||||
|
|
||||||
set default="0"
|
|
||||||
set timeout=30
|
|
||||||
|
|
||||||
menuentry "Try Ubuntu FS without installing" {
|
|
||||||
linux /casper/vmlinuz boot=casper nopersistent toram quiet splash ---
|
|
||||||
initrd /casper/initrd
|
|
||||||
}
|
|
||||||
|
|
||||||
menuentry "Install Ubuntu FS" {
|
|
||||||
linux /casper/vmlinuz boot=casper only-ubiquity quiet splash ---
|
|
||||||
initrd /casper/initrd
|
|
||||||
}
|
|
||||||
|
|
||||||
menuentry "Check disc for defects" {
|
|
||||||
linux /casper/vmlinuz boot=casper integrity-check quiet splash ---
|
|
||||||
initrd /casper/initrd
|
|
||||||
}
|
|
||||||
|
|
||||||
menuentry "Test memory Memtest86+ (BIOS)" {
|
|
||||||
linux16 /install/memtest86+
|
|
||||||
}
|
|
||||||
|
|
||||||
menuentry "Test memory Memtest86 (UEFI, long load time)" {
|
|
||||||
insmod part_gpt
|
|
||||||
insmod search_fs_uuid
|
|
||||||
insmod chain
|
|
||||||
loopback loop /install/memtest86
|
|
||||||
chainloader (loop,gpt1)/efi/boot/BOOTX64.efi
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# generate 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 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
|
|
||||||
|
|
||||||
# compress rootfs
|
|
||||||
sudo mksquashfs chroot image/casper/filesystem.squashfs
|
|
||||||
printf $(sudo du -sx --block-size=1 chroot | cut -f1) > image/casper/filesystem.size
|
|
||||||
|
|
||||||
# create 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
|
|
||||||
|
|
||||||
# create iso image
|
|
||||||
pushd $SCRIPT_DIR/image
|
|
||||||
grub-mkstandalone \
|
|
||||||
--format=x86_64-efi \
|
|
||||||
--output=isolinux/bootx64.efi \
|
|
||||||
--locales="" \
|
|
||||||
--fonts="" \
|
|
||||||
"boot/grub/grub.cfg=isolinux/grub.cfg"
|
|
||||||
|
|
||||||
(
|
|
||||||
cd isolinux && \
|
|
||||||
dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
|
|
||||||
sudo mkfs.vfat efiboot.img && \
|
|
||||||
LC_CTYPE=C mmd -i efiboot.img efi efi/boot && \
|
|
||||||
LC_CTYPE=C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/
|
|
||||||
)
|
|
||||||
|
|
||||||
grub-mkstandalone \
|
|
||||||
--format=i386-pc \
|
|
||||||
--output=isolinux/core.img \
|
|
||||||
--install-modules="linux16 linux normal iso9660 biosdisk memdisk search tar ls" \
|
|
||||||
--modules="linux16 linux normal iso9660 biosdisk search" \
|
|
||||||
--locales="" \
|
|
||||||
--fonts="" \
|
|
||||||
"boot/grub/grub.cfg=isolinux/grub.cfg"
|
|
||||||
|
|
||||||
cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
|
|
||||||
|
|
||||||
sudo /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v -e 'md5sum.txt' -e 'bios.img' -e 'efiboot.img' > md5sum.txt)"
|
|
||||||
|
|
||||||
sudo xorriso \
|
|
||||||
-as mkisofs \
|
|
||||||
-iso-level 3 \
|
|
||||||
-full-iso9660-filenames \
|
|
||||||
-volid "Ubuntu from scratch" \
|
|
||||||
-eltorito-boot boot/grub/bios.img \
|
|
||||||
-no-emul-boot \
|
|
||||||
-boot-load-size 4 \
|
|
||||||
-boot-info-table \
|
|
||||||
--eltorito-catalog boot/grub/boot.cat \
|
|
||||||
--grub2-boot-info \
|
|
||||||
--grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \
|
|
||||||
-eltorito-alt-boot \
|
|
||||||
-e EFI/efiboot.img \
|
|
||||||
-no-emul-boot \
|
|
||||||
-append_partition 2 0xef isolinux/efiboot.img \
|
|
||||||
-output "../ubuntu-from-scratch.iso" \
|
|
||||||
-m "isolinux/efiboot.img" \
|
|
||||||
-m "isolinux/bios.img" \
|
|
||||||
-graft-points \
|
|
||||||
"/EFI/efiboot.img=isolinux/efiboot.img" \
|
|
||||||
"/boot/grub/bios.img=isolinux/bios.img" \
|
|
||||||
"."
|
|
||||||
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============= main ================
|
|
||||||
|
|
||||||
# we always stay in $SCRIPT_DIR
|
|
||||||
cd $SCRIPT_DIR
|
|
||||||
|
|
||||||
check_host
|
|
||||||
|
|
||||||
# check number of args
|
|
||||||
if [[ $# == 0 || $# > 3 ]]; then help; fi
|
|
||||||
|
|
||||||
# loop through args
|
|
||||||
dash_flag=false
|
|
||||||
start_index=0
|
|
||||||
end_index=${#CMD[*]}
|
|
||||||
for ii in "$@";
|
|
||||||
do
|
|
||||||
if [[ $ii == "-" ]]; then
|
|
||||||
dash_flag=true
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
find_index $ii
|
|
||||||
if [[ $dash_flag == false ]]; then
|
|
||||||
start_index=$index
|
|
||||||
else
|
|
||||||
end_index=$(($index+1))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [[ $dash_flag == false ]]; then
|
|
||||||
end_index=$(($start_index + 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
#loop through the commands
|
|
||||||
for ((ii=$start_index; ii<$end_index; ii++)); do
|
|
||||||
${CMD[ii]}
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$0 - Initial build is done!"
|
|
||||||
|
|
|
@ -1,196 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e # exit on error
|
|
||||||
set -o pipefail # exit on pipeline error
|
|
||||||
set -u # treat unset variable as error
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
||||||
|
|
||||||
CMD=(setup_host install_pkg finish_up)
|
|
||||||
|
|
||||||
function help() {
|
|
||||||
# if $1 is set, use $1 as headline message in help()
|
|
||||||
if [ -z ${1+x} ]; then
|
|
||||||
echo -e "This script builds Ubuntu from scratch"
|
|
||||||
echo -e
|
|
||||||
else
|
|
||||||
echo -e $1
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
echo -e "Supported commands : ${CMD[*]}"
|
|
||||||
echo -e
|
|
||||||
echo -e "Syntax: $0 [start_cmd] [-] [end_cmd]"
|
|
||||||
echo -e "\trun from start_cmd to end_end"
|
|
||||||
echo -e "\tif start_cmd is omitted, start from first command"
|
|
||||||
echo -e "\tif end_cmd is omitted, end with last command"
|
|
||||||
echo -e "\tenter single cmd to run the specific command"
|
|
||||||
echo -e "\tenter '-' as only argument to run all commands"
|
|
||||||
echo -e
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function find_index() {
|
|
||||||
local ret;
|
|
||||||
local i;
|
|
||||||
for ((i=0; i<${#CMD[*]}; i++)); do
|
|
||||||
if [ "${CMD[i]}" == "$1" ]; then
|
|
||||||
index=$i;
|
|
||||||
return;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
help "Command not found : $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_host() {
|
|
||||||
if [ $(id -u) -ne 0 ]; then
|
|
||||||
echo "This script should be run as 'root'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
export HOME=/root
|
|
||||||
export LC_ALL=C
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup_host() {
|
|
||||||
echo "=====> running setup_host ..."
|
|
||||||
|
|
||||||
echo "ubuntu-fs-live" > /etc/hostname
|
|
||||||
|
|
||||||
# we need to install systemd first, to configure machine id
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y libterm-readline-gnu-perl systemd-sysv
|
|
||||||
|
|
||||||
#configure machine id
|
|
||||||
dbus-uuidgen > /etc/machine-id
|
|
||||||
ln -fs /etc/machine-id /var/lib/dbus/machine-id
|
|
||||||
|
|
||||||
# don't understand why, but multiple sources indicate this
|
|
||||||
dpkg-divert --local --rename --add /sbin/initctl
|
|
||||||
ln -s /bin/true /sbin/initctl
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_pkg() {
|
|
||||||
echo "=====> running install_pkg ... will take a long time ..."
|
|
||||||
apt-get -y upgrade
|
|
||||||
|
|
||||||
# install live linux packages
|
|
||||||
apt-get install -y \
|
|
||||||
ubuntu-standard \
|
|
||||||
casper \
|
|
||||||
lupin-casper \
|
|
||||||
discover \
|
|
||||||
laptop-detect \
|
|
||||||
os-prober \
|
|
||||||
network-manager \
|
|
||||||
resolvconf \
|
|
||||||
net-tools \
|
|
||||||
wireless-tools \
|
|
||||||
wpagui \
|
|
||||||
locales \
|
|
||||||
linux-generic
|
|
||||||
|
|
||||||
# graphic installer - ubiquity
|
|
||||||
apt-get install -y \
|
|
||||||
ubiquity \
|
|
||||||
ubiquity-casper \
|
|
||||||
ubiquity-frontend-gtk \
|
|
||||||
ubiquity-slideshow-ubuntu \
|
|
||||||
ubiquity-ubuntu-artwork
|
|
||||||
|
|
||||||
# install graphics and desktop
|
|
||||||
apt-get install -y \
|
|
||||||
plymouth-theme-ubuntu-logo \
|
|
||||||
ubuntu-gnome-desktop \
|
|
||||||
ubuntu-gnome-wallpapers
|
|
||||||
|
|
||||||
# useful tools
|
|
||||||
apt-get install -y \
|
|
||||||
clamav-daemon \
|
|
||||||
terminator \
|
|
||||||
apt-transport-https \
|
|
||||||
curl \
|
|
||||||
vim \
|
|
||||||
nano \
|
|
||||||
less
|
|
||||||
|
|
||||||
# purge
|
|
||||||
apt-get purge -y \
|
|
||||||
transmission-gtk \
|
|
||||||
transmission-common \
|
|
||||||
gnome-mahjongg \
|
|
||||||
gnome-mines \
|
|
||||||
gnome-sudoku \
|
|
||||||
aisleriot \
|
|
||||||
hitori
|
|
||||||
|
|
||||||
# remove unused and clean up apt cache
|
|
||||||
apt-get autoremove -y
|
|
||||||
|
|
||||||
# final touch
|
|
||||||
dpkg-reconfigure locales
|
|
||||||
dpkg-reconfigure resolvconf
|
|
||||||
|
|
||||||
# network manager
|
|
||||||
cat <<EOF > /etc/NetworkManager/NetworkManager.conf
|
|
||||||
[main]
|
|
||||||
rc-manager=resolvconf
|
|
||||||
plugins=ifupdown,keyfile
|
|
||||||
dns=dnsmasq
|
|
||||||
|
|
||||||
[ifupdown]
|
|
||||||
managed=false
|
|
||||||
EOF
|
|
||||||
dpkg-reconfigure network-manager
|
|
||||||
|
|
||||||
apt-get clean -y
|
|
||||||
}
|
|
||||||
|
|
||||||
function finish_up() {
|
|
||||||
echo "=====> finish_up"
|
|
||||||
|
|
||||||
# truncate machine id (why??)
|
|
||||||
truncate -s 0 /etc/machine-id
|
|
||||||
|
|
||||||
# remove diversion (why??)
|
|
||||||
rm /sbin/initctl
|
|
||||||
dpkg-divert --rename --remove /sbin/initctl
|
|
||||||
|
|
||||||
rm -rf /tmp/* ~/.bash_history
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============= main ================
|
|
||||||
|
|
||||||
check_host
|
|
||||||
|
|
||||||
# check number of args
|
|
||||||
if [[ $# == 0 || $# > 3 ]]; then help; fi
|
|
||||||
|
|
||||||
# loop through args
|
|
||||||
dash_flag=false
|
|
||||||
start_index=0
|
|
||||||
end_index=${#CMD[*]}
|
|
||||||
for ii in "$@";
|
|
||||||
do
|
|
||||||
if [[ $ii == "-" ]]; then
|
|
||||||
dash_flag=true
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
find_index $ii
|
|
||||||
if [[ $dash_flag == false ]]; then
|
|
||||||
start_index=$index
|
|
||||||
else
|
|
||||||
end_index=$(($index+1))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [[ $dash_flag == false ]]; then
|
|
||||||
end_index=$(($start_index + 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# loop through the commands
|
|
||||||
for ((ii=$start_index; ii<$end_index; ii++)); do
|
|
||||||
${CMD[ii]}
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$0 - Initial build is done!"
|
|
||||||
|
|
Loading…
Reference in New Issue