Recover Fedora after EFI partition is deleted by shaking hand

Make a Fedora live USB stick, plug it in the pc and power up, when grub menu appears, type ctrl + e, using tab key find the real path when editing,

linux (hd2,gpt3)/boot/vmlinuz-5.16.12-200.fc35.x86_64 root=/dev/sda3 ro rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1
initrd (hd2,gpt3)/boot/initramfs-5.16.12-200.fc35.x86_64.img

press ctrl + x to boot.

If encounter

Cannot open access to console, the root account is locked.

It means the password of root is not set so far,

Reboot to Fedora live environment,

# /dev/sda3 is the root partition.
mkdir /tmp/sda3
mount /dev/sda3 /tmp/sda3
cd /tmp/sda3
mount -o bind /dev ./dev
mount -t proc proc ./proc
mount -t sysfs sys ./sys
chroot .
passwd root

Now we have set up root password, then retry previous step to boot in local Fedora.

sudo su

# For security, Fedora coder disables directly building loader files in EFI partition.
# we can not invoke like this: grub2-install /dev/sda

dnf reinstall grub2-efi-x64 shim-x64
dnf install grub2-efi-x64-modules

# for how to register startup item in EFI NVRAM, get it from
#grep efibootmgr /var/log/anaconda/storage.log

# we make /dev/sda1 as EFI partition.
# -c = create
# -d = disk
# -p = EFI partition number, start from 1
# -l = loader path
efibootmgr -c -w -L Fedora -d /dev/sda -p 1 -l \EFI\fedora\shimx64.efi

refer to:
https://bugzilla.redhat.com/show_bug.cgi?id=1917213

Change grub2 default startup item in Fedora

Confirm our OS is in BIOS or EFI,

1
2
3
4
# in BIOS system
GRUB_CFG=/boot/grub2/grub.cfg
# in EFI system
GRUB_CFG=/boot/efi/EFI/fedora/grub.cfg

Then lookup the booting item id we want to set as default.

If we only want to switch default between Linux kernels,

1
grubby --info ALL

Else if we want to change default booting item to Windows,

1
cat $GRUB_CFG | grep Windows

Read the output, we will find the item, e.g. corresponding to the name, the id is "e528434f2b3e4d7c97d97aa4aabb976e-5.16.7", write it in /etc/default/grub

1
2
#GRUB_DEFAULT=saved
GRUB_DEFAULT=e528434f2b3e4d7c97d97aa4aabb976e-5.16.7

Finally update grub,

1
2
grub2-mkconfig -o $GRUB_CFG
#.

Reboot to see the change.

And in Ubuntu, how to make grub2 remember last choice?

sudo vi /etc/default/grub
	GRUB_DEFAULT=saved
	GRUB_SAVEDEFAULT=true
sudo update-grub

refer to:
https://docs.fedoraproject.org/en-US/fedora/f35/system-administrators-guide/kernel-module-driver-configuration/Working_with_the_GRUB_2_Boot_Loader/

Fedora 21 改变启动顺序以及grub2 配置技巧


https://askubuntu.com/questions/148662/how-to-get-grub2-to-remember-last-choice

Build qemu in Fedora35

Build,

sudo dnf install ninja-build pixman-devel

cd qemu-6.2.0
mkdir bld
cd bld
../configure --enable-kvm --target-list=x86_64-softmmu --prefix=`pwd`/installed
make

Inspect through vnc,

dnf install vinagre

cd x86_64-softmmu
./qemu-system-x86_64 -m 3500 -smp 4 --enable-kvm -boot d -hda /mnt/DATA/vmimg/win7/win7.vmdk

Open vinagre, input "127.0.0.1:5900" in VNC host box, then connect, after a while we will see win7 running up.

Run in local gui,

sudo dnf install libepoxy-devel gtk3-devel

cd bld
../configure --enable-kvm --enable-gtk --enable-opengl --target-list=x86_64-softmmu --prefix=`pwd`/installed

cd x86_64-softmmu
./qemu-system-x86_64 -m 3500 -smp 4 --enable-kvm -display gtk,gl=on -vga vmware -usb -device usb-kbd -device usb-audio -boot c -netdev user,id=mynet0 -device e1000-82545em,netdev=mynet0 -boot d -hda /mnt/DATA/vmimg/win7/win7.vmdk

Frankly, qemu gui is not user friendly, and I have not found the way to setup 3d presentation in guest win7 yet.

refer to:
https://blog.csdn.net/haifeng_gu/article/details/108055083
https://blog.csdn.net/wanghuiyao/article/details/65627198

Fedora kernel: bad shim signature

One easy method is disabling Secure Boot option in machine EFI BIOS.

In other way, we can't sign vmlinuz using MOK, because MOK is only a gate keeper for kernel after vmlinuz booting up, and if we want EFI firmware to admit vmlinuz as descendant, we must require the machine manufacturer to sign the vmlinuz we built.

MOK: Machine Owner Key
UEFI: Unified Extensible Firmware Interface

refer to:
https://www.rodsbooks.com/efi-bootloaders/secureboot.html

Play mame in Linux handily

1
dnf install mame

in ~/.bashrc

1
2
MAME_DATABASE=/to/path/of/mame
alias mame_go="mame -window -rompath ${MAME_DATABASE}/roms -snapshot_directory ${MAME_DATABASE}/snap "

how to play,

1
2
3
4
# open game list.
mame_go
# or quickly into play.
mame_go sf2ce

Other emulators,

1
2
3
4
# fc nes
dnf install fceux
# ps2
dnf install pcsx2