On Wed, Dec 13, 2023 at 04:33:00PM +0100, lacsaP Patatetom wrote:
> having said that, and if you respect the constraints ("what you
> should never do..."), vvfat is a really nice way of performing and
> repeating quick tests without having to go through the process of
> building/creating/updating disk images.
While I agree with what you say here and I also think that it would be
nice if that driver was maintained and had more features... really,
creating a temporary FAT image of a few hundred MBs with some files
inside takes less than a second in a modern computer, you can boot
QEMU like this and you won't probably even notice the difference:
$QEMU -drive if=ide,file=$(create-image.sh),driver=raw
Berto
here's a little script following the exchanges above.
perhaps it will be useful to others...
don't hesitate to send your comments and feedback.
regards, lacsaP
```
#!/usr/bin/bash
# this script generates a 64MB GPT disk with a single 60MB EFI System
# partition formatted in FAT32
# the disk produced is "invalid", as it lacks the backup/spare GPT
# (qemu doesn't seem to work with disks smaller than 64MB)
prefix=/tmp/.$$
trap "rm -f $prefix.{gpt,fat,disk}" EXIT HUP INT TERM
# ********************* GPT *********************
#
# $ gdisk -l tmpdisk
# …
# Found valid GPT with protective MBR; using GPT.
# Disk disk: 131072 sectors, 64.0 MiB
# Sector size (logical): 512 bytes
# Disk identifier (GUID): BEE772C8-89D8-49FC-8F5C-D4964108B9C5
# Partition table holds up to 128 entries
# Total free space is 8125 sectors (4.0 MiB)
# Number Start (sector) End (sector) Size Code Name
# 1 2048 124927 60.0 MiB EF00 EFI system partition
#
# # size = (sector_size * start_sector )
#
# $ head -c $((512 * 2048)) tmpdisk | zstd | base64
# KLUv/QRYpAUAlAgAAAIA7iggCAEAAAD//wEAVapFRkkgUEFSVAAAAQBcAAAAlJu5YgAAAAAi3shy
# 577YifxJj1zUlkEIucUCgHgdyq4ocyrBH/jSEbpLAKDJPsk7gV161JMdDUK+yxC+tnwJhQAI/+cB
# RQBGAEkAIABzAHkAcwB0AGUAbQAgAHAAYQByAHQAaW8Abg8AkvsgB1bxeNc6OEOaa3g5UAEQE2mX
# b8ibhnyQOQtifQIxBiK1qwIsAgAQAAIAEAACABAAAgAQAAIAEAACABAAAwAQAMDAzBw=
#
( base64 -d | zstd -d > $prefix.gpt ) \
<<~~~
KLUv/aQAABAApAUAlAgAAAIA7iggCAEAAAD//wEAVapFRkkgUEFSVAAAAQBcAAAAlJu5YgAAAAAi
3shy577YifxJj1zUlkEIucUCgHgdyq4ocyrBH/jSEbpLAKDJPsk7gV161JMdDUK+yxC+tnwJhQAI
/+cBRQBGAEkAIABzAHkAcwB0AGUAbQAgAHAAYQByAHQAaW8Abg8AkvsgB1bxeNc6OEOaa3g5UAEQ
E2mXb8ibhnyQOQtifQIxBiK1qwIsAgAQAAIAEAACABAAAgAQAAIAEAACABAAAwAQAMDAzBw=
~~~
# ********************* FAT *********************
#
# # size = (end_sector - start_sector + 1) / 2 (KB)
#
rm -f $prefix.fat
mkfs.fat -C -F 32 -n 'ESP' -m '' -i 00000000 $prefix.fat $(((124927 - 2048 + 1) / 2))
mcopy -i $prefix.fat -Do -s ./esp/EFI ::
mdir -i $prefix.fat -/ -b ::
# ********************* DISK ********************
#
cat $prefix.{gpt,fat} > $prefix.disk
rm -f $prefix.{gpt,fat}
sync
# ********************* QEMU ********************
#
qemu-system-x86_64 \
-accel kvm \
-machine q35 \
-m 512 \
-bios /usr/share/ovmf/x64/OVMF.fd \
-drive file=$prefix.disk,format=raw
```