277 lines
8.0 KiB
Bash
277 lines
8.0 KiB
Bash
#!/bin/bash
|
|
|
|
set -x
|
|
set -e
|
|
export HOME=/root
|
|
export LC_ALL=C
|
|
|
|
function set_root_passwd(){
|
|
echo "root:root" | chpasswd
|
|
}
|
|
|
|
function setup_sources_list () {
|
|
echo "Setting up sources.list"
|
|
cat <<EOF > $CHROOT_DIR/etc/apt/sources.list
|
|
deb http://us.archive.ubuntu.com/ubuntu/ noble main restricted universe multiverse
|
|
deb-src http://us.archive.ubuntu.com/ubuntu/ noble main restricted universe multiverse
|
|
|
|
deb http://us.archive.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
|
|
deb-src http://us.archive.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
|
|
|
|
deb http://us.archive.ubuntu.com/ubuntu/ noble-updates main restricted universe multiverse
|
|
deb-src http://us.archive.ubuntu.com/ubuntu/ noble-updates main restricted universe multiverse
|
|
EOF
|
|
apt update -y
|
|
apt-get -y upgrade
|
|
}
|
|
|
|
function configure_divert() {
|
|
echo "Configuring divert"
|
|
dbus-uuidgen > /etc/machine-id
|
|
ln -fs /etc/machine-id /var/lib/dbus/machine-id
|
|
dpkg-divert --local --rename --add /sbin/initctl
|
|
ln -s /bin/true /sbin/initctl
|
|
}
|
|
|
|
function mount_proc_sys_dev() {
|
|
echo "Mounting proc, sys and dev"
|
|
mount -t proc proc /proc
|
|
mount -t sysfs sys /sys
|
|
mount -t devpts devpts /dev/pts
|
|
}
|
|
|
|
function install_packages() {
|
|
echo "Installing packages"
|
|
apt install -y $@
|
|
}
|
|
|
|
|
|
function set_pkg_configuration() {
|
|
echo "keyboard-configuration keyboard-configuration/layout select Spanish" | debconf-set-selections
|
|
echo "keyboard-configuration keyboard-configuration/variant select Spanish" | debconf-set-selections
|
|
echo "keyboard-configuration keyboard-configuration/xkb-keymap select es" | debconf-set-selections
|
|
}
|
|
|
|
function install_non_interactive() {
|
|
echo "Installing packages non interactive"
|
|
apt install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $@
|
|
}
|
|
|
|
function install_no_recommends() {
|
|
echo "Installing packages without recommends"
|
|
apt install -y --no-install-recommends $@
|
|
}
|
|
|
|
function setup_chroot() {
|
|
echo "Setting up chroot"
|
|
dbus-uuidgen > /etc/machine-id
|
|
apt update -y
|
|
ln -fs /etc/machine-id /var/lib/dbus/machine-id
|
|
ln -s /bin/true /sbin/initctl
|
|
}
|
|
|
|
function remove_unneeded_packages() {
|
|
echo "Removing unneeded packages"
|
|
apt remove -y --purge --auto-remove snapd
|
|
}
|
|
|
|
function reconfigure_locales() {
|
|
echo "Configuring locales"
|
|
sed -i 's/# es_ES.UTF-8 UTF-8/es_ES.UTF-8 UTF-8/' /etc/locale.gen
|
|
sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
|
|
locale-gen
|
|
ln -sf /usr/share/zoneinfo/Europe/Madrid /etc/localtime
|
|
echo "Europe/Madrid" > /etc/timezone
|
|
dpkg-reconfigure -f noninteractive tzdata
|
|
}
|
|
|
|
function reconfigure_network_manager() {
|
|
echo "Configuring network manager"
|
|
mkdir -p /etc/NetworkManager
|
|
cat <<EOF > /etc/NetworkManager/NetworkManager.conf
|
|
[main]
|
|
plugins=keyfile
|
|
|
|
[keyfile]
|
|
unmanaged-devices=none
|
|
EOF
|
|
|
|
mkdir -p /etc/NetworkManager/system-connections/
|
|
cat <<EOL > /etc/NetworkManager/system-connections/dhcp-all.nmconnection
|
|
[connection]
|
|
id=Cable
|
|
type=ethernet
|
|
autoconnect=true
|
|
|
|
[ipv4]
|
|
method=auto
|
|
EOL
|
|
|
|
systemctl enable NetworkManager
|
|
}
|
|
|
|
function reconfigure_packages() {
|
|
reconfigure_locales
|
|
reconfigure_network_manager
|
|
}
|
|
|
|
function create_image() {
|
|
mkdir -p /image/{casper,isolinux,install}
|
|
cp /boot/vmlinuz-**-**-generic /image/casper/vmlinuz
|
|
cp /boot/initrd.img-**-**-generic /image/casper/initrd
|
|
wget --progress=dot https://memtest.org/download/v7.00/mt86plus_7.00.binaries.zip -O /image/install/memtest86.zip
|
|
unzip -p /image/install/memtest86.zip memtest64.bin > /image/install/memtest86+.bin
|
|
unzip -p /image/install/memtest86.zip memtest64.efi > /image/install/memtest86+.efi
|
|
rm -f /image/install/memtest86.zip
|
|
}
|
|
|
|
|
|
function configure_grub_menu() {
|
|
touch /image/ubuntu
|
|
cat <<EOF > /image/isolinux/grub.cfg
|
|
|
|
search --set=root --file /ubuntu
|
|
|
|
insmod all_video
|
|
|
|
set default="0"
|
|
set timeout=30
|
|
|
|
menuentry "Install Ubuntu FS" {
|
|
linux /casper/vmlinuz boot=casper quiet splash ---
|
|
initrd /casper/initrd
|
|
}
|
|
|
|
menuentry "Check disc for defects" {
|
|
linux /casper/vmlinuz boot=casper integrity-check quiet splash ---
|
|
initrd /casper/initrd
|
|
}
|
|
|
|
grub_platform
|
|
if [ "\$grub_platform" = "efi" ]; then
|
|
menuentry 'UEFI Firmware Settings' {
|
|
fwsetup
|
|
}
|
|
|
|
menuentry "Test memory Memtest86+ (UEFI)" {
|
|
linux /install/memtest86+.efi
|
|
}
|
|
else
|
|
menuentry "Test memory Memtest86+ (BIOS)" {
|
|
linux16 /install/memtest86+.bin
|
|
}
|
|
fi
|
|
EOF
|
|
# Generate manifest
|
|
dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee /image/casper/filesystem.manifest
|
|
cp -v /image/casper/filesystem.manifest /image/casper/filesystem.manifest-desktop
|
|
sed -i '/ubiquity/d' /image/casper/filesystem.manifest-desktop
|
|
sed -i '/casper/d' /image/casper/filesystem.manifest-desktop
|
|
sed -i '/discover/d' /image/casper/filesystem.manifest-desktop
|
|
sed -i '/laptop-detect/d' /image/casper/filesystem.manifest-desktop
|
|
sed -i '/os-prober/d' /image/casper/filesystem.manifest-desktop
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
function create_image2(){
|
|
cp /usr/lib/shim/shimx64.efi.signed.previous /image/isolinux/bootx64.efi
|
|
cp /usr/lib/shim/mmx64.efi /image/isolinux/mmx64.efi
|
|
cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed /image/isolinux/grubx64.efi
|
|
cd /image/isolinux && \
|
|
dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
|
|
mkfs.vfat -F 16 efiboot.img && \
|
|
LC_CTYPE=C mmd -i efiboot.img efi efi/ubuntu efi/boot && \
|
|
LC_CTYPE=C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/bootx64.efi && \
|
|
LC_CTYPE=C mcopy -i efiboot.img ./mmx64.efi ::efi/boot/mmx64.efi && \
|
|
LC_CTYPE=C mcopy -i efiboot.img ./grubx64.efi ::efi/boot/grubx64.efi && \
|
|
LC_CTYPE=C mcopy -i efiboot.img ./grub.cfg ::efi/ubuntu/grub.cfg && \
|
|
# Create a grub bios images
|
|
cd /image && \
|
|
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
|
|
# find . -type f -print0 | xargs -0 md5sum | grep -v -e 'isolinux' > md5sum.txt
|
|
|
|
}
|
|
|
|
function clean (){
|
|
truncate -s 0 /etc/machine-id
|
|
rm /sbin/initctl
|
|
dpkg-divert --rename --remove /sbin/initctl
|
|
apt-get clean
|
|
rm -rf /tmp/* ~/.bash_history
|
|
umount /proc
|
|
umount /sys
|
|
umount /dev/pts
|
|
export HISTSIZE=0
|
|
}
|
|
|
|
|
|
function autostart_calamares() {
|
|
mkdir -p /etc/xdg/openbox
|
|
echo <<EOF > /etc/xdg/openbox/autostart
|
|
calamares &
|
|
EOF
|
|
}
|
|
|
|
|
|
function configure_lightdm() {
|
|
mkdir -p /etc/lightdm
|
|
cat <<EOF > /etc/lightdm/lightdm.conf
|
|
[Seat:*]
|
|
autologin-user=root
|
|
autologin-user-timeout=0
|
|
user-session=openbox
|
|
greeter-session=lightdm-gtk-greeter
|
|
|
|
EOF
|
|
}
|
|
|
|
function install_mesa_repo() {
|
|
add-apt-repository ppa:kisak/kisak-mesa
|
|
apt -y update
|
|
}
|
|
|
|
|
|
## Main
|
|
echo "ubuntu-fs-live" > /etc/hostname
|
|
mount_proc_sys_dev
|
|
setup_sources_list
|
|
install_packages libterm-readline-gnu-perl systemd-sysv software-properties-common
|
|
setup_chroot
|
|
set_pkg_configuration
|
|
install_mesa_repo
|
|
install_packages sudo ubuntu-standard sudo casper dbus-bin mesa-utils mesa-vulkan-drivers discover isc-dhcp-client laptop-detect unzip os-prober network-manager net-tools wireless-tools wpagui locales grub-common grub-gfxpayload-lists grub-pc grub-pc-bin grub2-common grub-efi-amd64-signed shim-signed mtools binutils virtualbox-guest-utils virtualbox-guest-x11
|
|
install_non_interactive xorg xinit openbox lightdm plymouth calamares
|
|
install_no_recommends linux-image-generic
|
|
set_root_passwd
|
|
configure_divert
|
|
configure_lightdm
|
|
autostart_calamares
|
|
remove_unneeded_packages
|
|
reconfigure_packages
|
|
create_image
|
|
configure_grub_menu
|
|
create_image2
|
|
clean
|