Bobcares

Custom Bootable Rescue ISO Image for SolusIO

by | Nov 18, 2021

Wondering about Custom Bootable Rescue ISO Image for SolusIO? Let us discuss.

As part of our Server Management Services, we assist our customers with several SolusIO queries.

Today, let us see how we can customize it according to our requirements.

 

Custom Bootable Rescue ISO Image for SolusIO

The instruction in this article is applicable to Ubuntu 20 server. Now, let us see how our Support Techs perform the query.

  • Prepare the environment for rescue image

Initially, we access the server via SSH.

Then using debootstarp we download the rescue system, and prepare mounts:

apt-get install -y binutils debootstrap squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin mtools && mkdir $HOME/rescue-iso && debootstrap –arch=amd64 –variant=minbase focal $HOME/rescue-iso/chroot && mount –bind /dev $HOME/rescue-iso/chroot/dev && mount –bind /run $HOME/rescue-iso/chroot/run
  • Work inside the environment

1. First, we Chroot into the environment:

chroot $HOME/rescue-iso/chroot

2. Once inside, we Mount proc and sysfs:

mount none -t proc /proc && mount none -t sysfs /sys && mount none -t devpts /dev/pts && export HOME=/root && export LC_ALL=C

3. After that, we configure default repositories:

cat <<EOF > /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

EOF

4. Now, we have to install the packages we need:

apt update -y && apt install -y uuid-runtime && uuidgen > /etc/machine-id && dpkg-divert –local –rename –add /sbin/initctl && ln -s /bin/true /sbin/initctl && apt update -y && apt install -y ssh cloud-init netplan.io vim less nano iputils-ping curl qemu-guest-agent ubuntu-standard casper lupin-casper linux-generic && systemctl enable systemd-networkd

We need to make sure to install cloud-init and not to use the network manager. In addition, we should enable systemd-networkd and enable qemu-guest-agent.

SolusIO require them to configure ssh and network during rescue boot.

5. Later, we remove the autologin for the root user and rebuild initramfs:

rm -f /usr/share/initramfs-tools/scripts/casper-bottom/25adduser && rm -f /usr/share/initramfs-tools/scripts/casper-bottom/01integrity_check && update-initramfs -u

6. Make sure that VM can properly reboot without waiting for any actions:

sed -i ‘+s+read x < /dev/console+echo “\\n” | read x+’ /usr/sbin/casper-stop

7. Then we clean up the environment and exit it:

apt upgrade -y && apt-get autoremove -y && truncate -s 0 /etc/machine-id && rm /sbin/initctl && dpkg-divert –rename –remove /sbin/initctl && apt clean && umount /proc && umount /sys && umount /dev/pts && export HISTSIZE=0 && exit
  • Create a bootable ISO image from the rescue environment

Make note that the execution of the steps below are on the server, not the in the rescue environment.

Initially, we remove bash history and unmount previously mounted system directories:

rm -f $HOME/rescue-iso/chroot/root/.bash_history && umount $HOME/rescue-iso/chroot/dev && umount $HOME/rescue-iso/chroot/run

2. Then we create boot layout for ISO:

cd $HOME/rescue-iso && mkdir -p image/{casper,isolinux,install} && cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz && cp chroot/boot/initrd.img-**-**-generic image/casper/initrd && touch image/ubuntu

3. And then create grub.cfg for ISO:

cat <<EOF > image/isolinux/grub.cfg

search –set=root –file /ubuntu

set default=”0″
set timeout=”0″

menuentry “Rescue mode iso” {
linux /casper/vmlinuz boot=casper —
initrd /casper/initrd
}
EOF

4. After that, we create manifests to comply with bootable ISO standards:

cd $HOME/rescue-iso && chroot chroot dpkg-query -W –showformat=’${Package} ${Version}\n’ | sudo tee image/casper/filesystem.manifest && cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-rescue && sed -i ‘/ubiquity/d’ image/casper/filesystem.manifest-rescue && sed -i ‘/casper/d’ image/casper/filesystem.manifest-rescue && sed -i ‘/discover/d’ image/casper/filesystem.manifest-rescue && sed -i ‘/laptop-detect/d’ image/casper/filesystem.manifest-rescue && sed -i ‘/os-prober/d’ image/casper/filesystem.manifest-rescue

5. The next step is to create squashfs layout:

mksquashfs chroot image/casper/filesystem.squashfs && printf $(sudo du -sx –block-size=1 chroot | cut -f1) > image/casper/filesystem.size

6. Later, we create README.diskdefines:

cat <<EOF > image/README.diskdefines
#define DISKNAME Rescue mode iso
#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

7. Now, we have to prepare for grub finalization:

cd $HOME/rescue-iso/image && grub-mkstandalone \
–format=x86_64-efi \
–output=isolinux/bootx64.efi \
–locales=”” \
–fonts=”” \
“boot/grub/grub.cfg=isolinux/grub.cfg”

8. And create .img and vfat on top of that:

(
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/
)

9. Once done, we finalize grub config:

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

/bin/bash -c “(find . -type f -print0 | xargs -0 md5sum | grep -v “\./md5sum.txt” > md5sum.txt)”

10. Finally, we create iso:

sudo xorriso \
-as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid “Rescue mode iso” \
-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 “../rescue-latest.iso” \
-graft-points \
“.” \
/boot/grub/bios.img=isolinux/bios.img \
/EFI/efiboot.img=isolinux/efiboot.img

11. Eventually, we can find it at $HOME/rescue-iso/

  • Add a new custom rescue ISO to SolusIO

After performing the above steps, we upload the new image to any file share.

We log into SolusIO and navigate to Settings > Compute Resources.

Then we replace the Rescue Image URL with a new one.

[Stuck in between? We can help you out]

 

Conclusion

In short, we saw how our Support Techs customize Bootable Rescue ISO Image.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.