duane Apprentice

Joined: 03 Jun 2002 Posts: 172 Location: Oklahoma City
|
Posted: Sat Aug 06, 2022 2:24 am Post subject: Simple(?) Rescuecd With grub-mkrescue |
|
|
I decided to drop my archlinux-based rescue iso and revive my old gentoo-based iso recently, but it had been two years since I last updated the latter, so I recreated it from scratch rather than deal with upgrading. It reminded me of the details of the process, and I wrote everything down for posterity.
I do my rescue work in my livecd directory, with a slightly modified installation in a subdirectory, amd64. To install gentoo, I untarred the stage3 per the amd64 manual. My make.conf includes the following changes.
Code: |
COMMON_FLAGS="-O2 -march=x86-64 -mtune=native -pipe"
...
# I don't want these.
USE="-bluetooth -consolekit -cups -dbus -elogind -fdk -gnome -gstreamer -kde -pcmcia -pulseaudio -systemd"
# I want these.
USE="$USE abi_x86_32 acpi alsa cdr d3d9 dri dvd flac gif jpeg lua mp3 ogg png svg tiff truetype unicode vaapi vdpau vorbis x264 X"
# cpu flags
CPU_FLAGS_X86="mmx mmxext sse sse2"
USE="$USE livecd"
...
FEATURES="buildpkg"
GRUB_PLATFORMS="efi-64 efi-32 pc qemu"
INPUT_DEVICES="libinput synaptics"
QEMU_SOFTMMU_TARGETS="i386 x86_64"
QEMU_USER_TARGETS="i386 x86_64"
VIDEO_CARDS="intel i965 nouveau amdgpu radeonsi vesa virgl"
|
To chroot into the iso system, I use a script. I've got another subdirectory, portage, for my gentoo repo, but that's not really necessary.
Code: |
#!/bin/bash
LOC=/.../livecd
mkdir 2>/dev/null /mnt/gentoo
mount --bind $LOC/amd64 /mnt/gentoo
[ -e /var/cache/distfiles ] && mount --bind /var/cache/distfiles /mnt/gentoo/var/cache/distfiles
mount --bind $LOC/portage /mnt/gentoo/var/db/repos/gentoo
mount --bind /tmp /mnt/gentoo/tmp
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
|
I followed the handbook in Installing the Gentoo base system. Note that I didn't use a boot partition, just the /boot directory. To create the kernel, I installed genkernel and typed, "genkernel --nconfig all".
Code: |
File systems --->
<*> The Extended 4 (ext4) filesystem
<*> Overlay filesystem support
CD-ROM/DVD Filesystems ---
<*> ISO 9660 CDROM file system support
<*> UDF file system support
DOS/FAT/EXFAT/NT Filesystems --->
<*> MSDOS fs support
<*> VFAT (Windows-95) fs support
-*- Miscellaneous filesystems --->
<*> Apple Extended HFS file system support
<*> SquashFS 4.0 - Squashed file system support
Device Drivers --->
HID support --->
I2C HID support --->
<M> HID over I2C transport layer ACPI driver
[*] Block devices --->
<*> Loopback device support
-*- Network device support --->
[*] Wireless LAN --->
<M> Realtek 802.11ac wireless chips support --->
<M> Realtek 8821CE PCI wireless network adapter
|
The important part here is building in the file systems and loopback device, since loading modules during the initramfs stage is problematic.
I followed the instructions in Configuring the system and Installing system tools, but left the fstab file empty. Instead of rebooting at the end of the installation manual, I installed all of the software I use as one, giant emerge -- based on the /var/lib/portage/world files of my working systems.
I added a few unprivileged user accounts for times when I'm using the iso for a long period -- installing gentoo on a new machine, for example.
I also copied my favorite game software (in /usr/local), lots of scripts that I use on a regular basis, and the most important parts of my user directory. I made a tarball of my personal information (.ssh, .gnupg, .when, .mozilla, etc.), and encrypted it for a bit more security.
To build the iso file structure, I made a cd-root subdirectory like this. "livecd" is an empty file.
Code: |
cd-root/
├── boot
│ └── grub
│ └── grub.cfg
├── images
│ ├── aucode
│ ├── init64
│ ├── squashed
│ └── ucode
├── kernel
│ └── kernel64
└── livecd
|
I copied the following files. The ucode (intel microcode) and aucode (amd microcode) were put together using the wiki instructions.
Code: |
cp -av amd64/boot/amd-uc.img cd-root/images/aucode
cp -av amd64/boot/early_ucode.cpio cd-root/images/ucode
cp -av amd64/boot/vmlinuz-5.15.52-gentoo-x86_64 cd-root/kernel/kernel64
cp -av amd64/boot/initramfs-5.15.52-gentoo-x86_64.img cd-root/images/init64
|
My grub.cfg looks like this.
Code: |
#
#set timeout=1
insmod efi_gop
insmod efi_uga
menuentry 'Duane 64' {
linux /kernel/kernel64 overlayfs cdroot loop=/images/squashed looptype=squashfs keymap=colemak scandelay=5 net.ifnames=0 nvme_core.default_ps_max_latency_us=5500
initrd /images/aucode
initrd /images/ucode
initrd /images/init64
}
menuentry 'Duane 64 docache' {
linux /kernel/kernel64 overlayfs cdroot loop=/images/squashed looptype=squashfs keymap=colemak scandelay=5 docache net.ifnames=0 nvme_core.default_ps_max_latency_us=5500
initrd /images/aucode
initrd /images/ucode
initrd /images/init64
}
EOF
|
To make the squashfs image, I used a small script.
Code: |
#!/bin/bash
/bin/rm cd-root/images/squashed
/bin/rm -r amd64/tmp/*
/bin/rm -r amd64/var/tmp/*
mksquashfs amd64 cd-root/images/squashed -comp xz -wildcards -ef excludes.txt
|
Code: |
# excludes.txt
var/cache/binpkgs
var/tmp/*
tmp/*
proc/*
sys/*
media/*
mount/*
|
To make the iso file, I used another script.
Code: |
#!/bin/bash
na=`date +gentoo-livecd-%Y%m%d.iso`
/usr/bin/grub-mkrescue -o $na cd-root --iso-level 3 && \
/usr/bin/sha512sum $na > $na.sum
|
Note the iso-level 3 argument, since the iso is bigger than 4GB.
Then I just copied the iso to a usb thumb drive with a physical write-protect switch (~$10 on amazon).
Code: |
dd if=gentoo-livecd-*.iso of=/dev/___ bs=1M ; sync
|
I now have (again) a custom rescue iso that gives me a comfortable work environment in my favorite linux distribution. It's worked on all of my hardware so far, and it's relatively easy to update. I can't swear that I didn't miss a step here, but hopefully this will help anyone who's interested in the subject. |
|