Img file
ubuntu-21.04-preinstalled-server-armhf+raspi.img
Prepare
Edit /boot/cmdline.txt and /etc/fstab of this img
/boot/cmdline.txt
to use HDMI console,consider to remove fbcon=rotate:1 in /boot/cmdline.txt
/etc/fstab
Enter chroot
Inside chroot
sudo apt-get install tasksel
sudo cp -f /lib/firmware/brcm/brcmfmac43456-sdio.raspberrypi,400.txt /lib/firmware/brcm/brcmfmac43456-sdio.txt
sudo apt install wiringpi
sudo ln -s /lib/arm-linux-gnueabihf/libwiringPi.so.2 /lib/arm-linux-gnueabihf/libwiringPi.so
Outside chroot
dd img to sd card
power on CM3
config the network
sudo tasksel to select desktop env to install