First commit in branch
parent
dcb2962fbb
commit
8290ee4b60
|
@ -0,0 +1,148 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
set -x
|
||||
set -e
|
||||
PASSWD_FILE=/home/narenas/passwd
|
||||
DIR=$(pwd)
|
||||
CHROOT_DIR=$DIR/chroot
|
||||
DIST=noble
|
||||
VARIANT=minbase
|
||||
CLEAN=${CLEAN:-1}
|
||||
CLEAN_CHROOT=${CLEAN_CHROOT:-1}
|
||||
OUTPUT_DIR=/media/sf_Downloads/
|
||||
|
||||
|
||||
## FUNCIONES
|
||||
function exec_as_sudo () {
|
||||
cat $PASSWD_FILE | sudo -S $@
|
||||
}
|
||||
|
||||
function exec_as_sudo_in_chroot () {
|
||||
exec_as_sudo chroot $CHROOT_DIR $@
|
||||
}
|
||||
|
||||
function umount_in_chroot() {
|
||||
if grep $CHROOT_DIR$1 /etc/mtab;
|
||||
then
|
||||
echo "Unmounting $1"
|
||||
exec_as_sudo_in_chroot umount $1
|
||||
return $?
|
||||
fi
|
||||
echo "Mount point $1 not found"
|
||||
return 0
|
||||
}
|
||||
|
||||
function umount_in_host() {
|
||||
if findmnt -M $1
|
||||
then
|
||||
echo "Unmounting $1"
|
||||
exec_as_sudo umount $1
|
||||
return $?
|
||||
fi
|
||||
echo "Mount point $1 not found"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
if [ -d $CHROOT_DIR ] && [ $CLEAN -eq 1 ];
|
||||
then
|
||||
SYS_MOUNT_POINT_CHROOT="/proc /sys /dev/pts /dev"
|
||||
SYS_MOUNT_POINT="$CHROOT_DIR/dev $CHROOT_DIR/run"
|
||||
for i in $SYS_MOUNT_POINT_CHROOT;
|
||||
do
|
||||
umount_in_chroot $i
|
||||
done
|
||||
|
||||
for i in $SYS_MOUNT_POINT;
|
||||
do
|
||||
umount_in_host $i
|
||||
done
|
||||
# exec_as_sudo_in_chroot umount /proc
|
||||
# exec_as_sudo_in_chroot umount /sys
|
||||
# exec_as_sudo_in_chroot umount /dev/pts
|
||||
# exec_as_sudo umount $CHROOT_DIR/dev
|
||||
# exec_as_sudo umount $CHROOT_DIR/run
|
||||
if [ $CLEAN_CHROOT -eq 1 ];
|
||||
then
|
||||
exec_as_sudo rm -rf $CHROOT_DIR
|
||||
fi
|
||||
exec_as_sudo rm -rf image
|
||||
exec_as_sudo rm -f $OUTPUT_DIR/ubuntu-from-scratch.iso
|
||||
fi
|
||||
|
||||
mkdir -p $CHROOT_DIR
|
||||
# # Copio el script chroot_setup.sh al directorio chroot
|
||||
cp chroot_setup.sh $CHROOT_DIR
|
||||
chmod +x $CHROOT_DIR/chroot_setup.sh
|
||||
|
||||
# # Deploy boot strap
|
||||
if [ $CLEAN_CHROOT -eq 1 ];
|
||||
then
|
||||
exec_as_sudo debootstrap --arch=amd64 --variant=$VARIANT $DIST $CHROOT_DIR http://us.archive.ubuntu.com/ubuntu/
|
||||
fi
|
||||
exec_as_sudo mkdir -p $CHROOT_DIR/etc/calamares/
|
||||
exec_as_sudo cp -r calamares/* $CHROOT_DIR/etc/calamares/
|
||||
|
||||
# # Create mount points
|
||||
exec_as_sudo mount --bind /dev/ $CHROOT_DIR/dev
|
||||
exec_as_sudo mount --bind /run/ $CHROOT_DIR/run
|
||||
|
||||
|
||||
# Execute chroot_setup.sh
|
||||
exec_as_sudo_in_chroot /chroot_setup.sh
|
||||
|
||||
|
||||
# Clean up the environment
|
||||
umount_in_host $CHROOT_DIR/dev
|
||||
umount_in_host $CHROOT_DIR/run
|
||||
|
||||
# Compress the chroot
|
||||
exec_as_sudo mv chroot/image .
|
||||
|
||||
# Create squashfs imagesudo
|
||||
exec_as_sudo mksquashfs $CHROOT_DIR image/casper/filesystem.squashfs \
|
||||
-noappend -no-duplicates -no-recovery \
|
||||
-wildcards \
|
||||
-comp xz -b 1M -Xdict-size 100% \
|
||||
-e "var/cache/apt/archives/*" -e "root/*" -e "root/.*" -e "tmp/*" -e "tmp/.*" -e "swapfile"
|
||||
|
||||
printf $(exec_as_sudo du -sx --block-size=1 chroot | cut -f1) | sudo tee image/casper/filesystem.size
|
||||
|
||||
# Create ISO image
|
||||
|
||||
cd image && \
|
||||
exec_as_sudo xorriso \
|
||||
-as mkisofs \
|
||||
-iso-level 3 \
|
||||
-full-iso9660-filenames \
|
||||
-J -joliet-long \
|
||||
-volid "Ubuntu_scratch" \
|
||||
-output $OUTPUT_DIR/ubuntu-from-scratch.iso \
|
||||
-eltorito-boot isolinux/bios.img \
|
||||
-no-emul-boot \
|
||||
-boot-load-size 4 \
|
||||
-boot-info-table \
|
||||
--eltorito-catalog boot.catalog \
|
||||
--grub2-boot-info \
|
||||
--grub2-mbr ../chroot/usr/lib/grub/i386-pc/boot_hybrid.img \
|
||||
-partition_offset 16 \
|
||||
--mbr-force-bootable \
|
||||
-eltorito-alt-boot \
|
||||
-no-emul-boot \
|
||||
-e isolinux/efiboot.img \
|
||||
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b isolinux/efiboot.img \
|
||||
-appended_part_as_gpt \
|
||||
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
|
||||
-m "isolinux/efiboot.img" \
|
||||
-m "isolinux/bios.img" \
|
||||
-e '--interval:appended_partition_2:::' \
|
||||
-exclude isolinux \
|
||||
-graft-points \
|
||||
"/EFI/boot/bootx64.efi=isolinux/bootx64.efi" \
|
||||
"/EFI/boot/mmx64.efi=isolinux/mmx64.efi" \
|
||||
"/EFI/boot/grubx64.efi=isolinux/grubx64.efi" \
|
||||
"/EFI/ubuntu/grub.cfg=isolinux/grub.cfg" \
|
||||
"/isolinux/bios.img=isolinux/bios.img" \
|
||||
"/isolinux/efiboot.img=isolinux/efiboot.img" \
|
||||
"."
|
||||
cd ..
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
|
||||
modules-search:
|
||||
- local
|
||||
- /usr/lib/x86_64-linux-gnu/calamares/modules
|
||||
|
||||
sequence:
|
||||
- show:
|
||||
- welcome
|
||||
- locale
|
||||
- keyboard
|
||||
- partition
|
||||
- users
|
||||
- summary
|
||||
- exec:
|
||||
- partition
|
||||
- packagechooser
|
||||
- machineid
|
||||
- locale
|
||||
- keyboard
|
||||
- users
|
||||
- bootloader
|
||||
- show:
|
||||
- finished
|
||||
|
||||
|
||||
branding: default
|
||||
prompt-install: false
|
||||
dont-chroot: false
|
||||
oem-setup: false
|
||||
disable-cancel: false
|
||||
hide-back-and-next-during-exec: false
|
||||
disable-cancel-during-exec: false
|
||||
quit-at-end: false
|
|
@ -0,0 +1,273 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
set -e
|
||||
export HOME=/root
|
||||
export LC_ALL=C
|
||||
|
||||
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]
|
||||
rc-manager=none
|
||||
plugins=ifupdown,keyfile
|
||||
dns=systemd-resolved
|
||||
|
||||
[ifupdown]
|
||||
managed=false
|
||||
EOF
|
||||
|
||||
mkdir -p /etc/NetworkManager/system-connections/
|
||||
cat <<EOL > /etc/NetworkManager/system-connections/dhcp-all.nmconnection
|
||||
[connection]
|
||||
id=Auto DHCP
|
||||
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
|
||||
configure_divert
|
||||
configure_lightdm
|
||||
autostart_calamares
|
||||
remove_unneeded_packages
|
||||
reconfigure_packages
|
||||
create_image
|
||||
configure_grub_menu
|
||||
create_image2
|
||||
clean
|
Loading…
Reference in New Issue