Skip to content

Commit

Permalink
1. Fix serial console no display
Browse files Browse the repository at this point in the history
2. Change boot disk mount point

3. Stop journaling before packing rootfs

4. Change tab size

5. Remove --root-directory for legacy BIOS
  • Loading branch information
danchouzhou committed Jan 9, 2024
1 parent 582b75c commit c5f0388
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sudo cp -r /bootfiles/* /mnt/EFI
# Install GRUB
sudo grub-install --target=x86_64-efi --removable --efi-directory=/mnt --boot-directory=/mnt/EFI
sudo grub-install --target=i386-pc --root-directory=/mnt/EFI --boot-directory=/mnt/EFI /dev/sdb
sudo grub-install --target=i386-pc --boot-directory=/mnt/EFI /dev/sdb
# Unmount and your disk is ready to boot!
sudo umount /mnt
Expand Down
23 changes: 10 additions & 13 deletions local.ramfs
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,21 @@ local_mount_root()
# panic "Failed to mount ${ROOT} as root file system."
# fi
echo "Mounting filesystem ..."
mkdir /mount
mount -t ${FSTYPE} ${ROOT} /mount
mkdir /mnt
mount -t ${FSTYPE} ${ROOT} /mnt
mount -t tmpfs -o size=95% none ${rootmnt}
cd ${rootmnt}
echo "Find and execute init.sh ..."
if test -f /mount/init.sh; then
cp /mount/init.sh .
chmod +x init.sh
./init.sh
rm init.sh
elif test -f /mount/EFI/init.sh; then
cp /mount/EFI/init.sh .
chmod +x init.sh
./init.sh
rm init.sh
if test -f /mnt/init.sh; then
cp /mnt/init.sh .
elif test -f /mnt/EFI/init.sh; then
cp /mnt/EFI/init.sh .
else
find /mount -name _init.sh -exec {} \;
find /mnt -name init.sh -exec cp {} . \;
fi
chmod +x init.sh
./init.sh
rm init.sh
}

local_mount_fs()
Expand Down
40 changes: 21 additions & 19 deletions ramfs_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e

echo "Install additional software ..."
apt update
# basic system utilities
# system utilities
apt install htop screen nano wget bash-completion eject dosfstools ntfs-3g exfat-fuse grub-pc-bin mdadm lvm2 iptables net-tools network-manager -y
# driver
apt install firmware-linux-nonfree firmware-iwlwifi firmware-realtek firmware-atheros -y
Expand All @@ -18,19 +18,19 @@ apt clean

echo "Customizing initramfs script ..."
if ! test -f /usr/share/initramfs-tools/scripts/local.original; then
cp /usr/share/initramfs-tools/scripts/local /usr/share/initramfs-tools/scripts/local.original
cp /usr/share/initramfs-tools/scripts/local /usr/share/initramfs-tools/scripts/local.original
fi
cp local.ramfs /usr/share/initramfs-tools/scripts/local.ramfs

echo "Adding additional kernel module for FAT and exFAT ..."
if ! test -f /etc/initramfs-tools/modules.original; then
cp /etc/initramfs-tools/modules /etc/initramfs-tools/modules.original
cp /etc/initramfs-tools/modules /etc/initramfs-tools/modules.original
fi
if ! test -f /etc/initramfs-tools/modules.ramfs; then
cp /etc/initramfs-tools/modules /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/fat/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/exfat/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/nls/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
cp /etc/initramfs-tools/modules /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/fat/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/exfat/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
ls /lib/modules/`uname -r`/kernel/fs/nls/ | cut -f1 -d '.' | tee -a /etc/initramfs-tools/modules.ramfs
fi

echo "Adding tar binary to initramfs"
Expand All @@ -39,13 +39,13 @@ cat << EOF > /usr/share/initramfs-tools/hooks/tar
PREREQ=""
prereqs()
{
echo "\$PREREQ"
echo "\$PREREQ"
}
case \$1 in
prereqs)
prereqs
exit 0
;;
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
rm -f \${DESTDIR}/bin/tar
Expand All @@ -57,7 +57,7 @@ echo "Customizing fstab ..."
if ! test -f /etc/fstab.original; then
cp /etc/fstab /etc/fstab.original
fi
echo 'none / tmpfs size=95% 0 0' | tee /etc/fstab.ramfs
echo 'none / tmpfs size=95% 0 0' | tee /etc/fstab.ramfs

echo "Setup startup.service ..."
cat << EOF > /etc/systemd/system/startup.service
Expand All @@ -82,7 +82,9 @@ cp /etc/fstab.ramfs /etc/fstab
echo "Preparing boot files ..."
echo "Packing rootfs ..."
mkdir -p /bootfiles/grub
tar zcf /bootfiles/rootfs.tar.gz --exclude='ramfs_setup.sh' --exclude='local.ramfs' --exclude='boot_dvd.sh' --exclude='README.md' --exclude='/bootfiles' --one-file-system / --checkpoint=.5000
systemctl stop systemd-journald.service
tar zcf /bootfiles/rootfs.tar.gz --exclude='/home/*/ramfs' --exclude='/bootfiles' --one-file-system / --checkpoint=.5000
systemctl start systemd-journald.service

echo "Copying Linux kernel ..."
cp /boot/vmlinuz-`uname -r` /bootfiles/vmlinuz-`uname -r`
Expand All @@ -95,14 +97,15 @@ cat << EOF > /bootfiles/init.sh
#!/bin/sh
echo "Copying rootfs.tar.gz ..."
cp /mount/EFI/rootfs.tar.gz .
cp /mnt/EFI/rootfs.tar.gz .
echo "Copying start.sh ..."
cp /mount/EFI/start.sh .
cp /mnt/EFI/start.sh .
chmod +x start.sh
echo "Unmount boot device ..."
umount /mount
umount /mnt
echo -n "Extracting from rootfs.tar.gz ..."
tar zxf rootfs.tar.gz --checkpoint=.5000
echo
rm rootfs.tar.gz
EOF

Expand Down Expand Up @@ -149,16 +152,15 @@ EOF

echo "Create GRUB boot menu ..."
cat << EOF > /bootfiles/grub/grub.cfg
serial --speed=115200 --unit=0 --word=8 --parity=no --stop
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input console serial
terminal_output console serial
set timeout=5
probe -u \$root --set=boot_uuid
menuentry "Debian" {
linux /EFI/vmlinuz-`uname -r` root=UUID=\$boot_uuid ro console=tty0
linux /EFI/vmlinuz-`uname -r` root=UUID=\$boot_uuid ro console=ttyS0,115200 console=tty0
initrd /EFI/initrd.img-`uname -r`
}
grub_platform
if [ "\$grub_platform" = "efi" ]; then
menuentry 'UEFI Firmware Settings' {
fwsetup
Expand Down

0 comments on commit c5f0388

Please sign in to comment.