From: "Andreas K. Hüttel" <dilfridge@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:dilfridge/qcow2 commit in: targets/support/
Date: Sun, 6 Oct 2024 19:33:03 +0000 (UTC) [thread overview]
Message-ID: <1728243110.6292209ad2ed7e1f98c49d6470e921b3ecb8b753.dilfridge@gentoo> (raw)
commit: 6292209ad2ed7e1f98c49d6470e921b3ecb8b753
Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 6 19:31:50 2024 +0000
Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sun Oct 6 19:31:50 2024 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=6292209a
Replace fixed with default values, insert variables, stream compression
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
targets/support/create-qcow2.sh | 43 +++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/targets/support/create-qcow2.sh b/targets/support/create-qcow2.sh
index 32486f15..d54691a8 100755
--- a/targets/support/create-qcow2.sh
+++ b/targets/support/create-qcow2.sh
@@ -15,9 +15,9 @@ source ${clst_shdir}/support/functions.sh
# - clst_qcow2_efisize size of the EFI boot partition (default 512MiB)
# - clst_qcow2_roottype type of the root partition (default xfs)
#
-export clst_qcow2_size=20GiB
-export clst_qcow2_efisize=512MiB
-export clst_qcow2_roottype=xfs
+: "${clst_qcow2_size:=20GiB}"
+: "${clst_qcow2_efisize:=512MiB}"
+: "${clst_qcow2_roottype:=xfs}"
#
# We only support one set of tools, based on
@@ -31,32 +31,33 @@ export clst_qcow2_roottype=xfs
#
# create a new qcow2 disk image file
-qemu-img create -f qcow2 ${1} ${clst_qcow2_size}G || die "Cannot create qcow2 file"
+qemu-img create -f qcow2 "${1}.tmp.qcow2" ${clst_qcow2_size} || die "Cannot create qcow2 file"
# connect the qcow2 file to a network block device
# TODO: find next free device
modprobe -q nbd
-qemu-nbd -c /dev/nbd0 -f qcow2 ${1} || die "Cannot connect qcow2 file to nbd0"
+mydevice=/dev/nbd0
+qemu-nbd -c ${mydevice} -f qcow2 "${1}.tmp.qcow2" || die "Cannot connect qcow2 file to nbd0"
# create a GPT disklabel
-parted -s /dev/nbd0 mklabel gpt || die "Cannot create disklabel"
+parted -s ${mydevice} mklabel gpt || die "Cannot create disklabel"
# create an EFI boot partition
-parted -s /dev/nbd0 -- mkpart efi fat32 1M {clst_qcow2_efisize}GiB || die "Cannot create EFI partition"
+parted -s ${mydevice} -- mkpart efi fat32 1M ${clst_qcow2_efisize} || die "Cannot create EFI partition"
# mark it as EFI boot partition
-parted -s /dev/nbd0 -- type 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B || die "Cannot set EFI partition UUID"
+parted -s ${mydevice} -- type 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B || die "Cannot set EFI partition UUID"
# note down name
-mypartefi=/dev/nbd0p1
+mypartefi=${mydevice}p1
# create the root partition
-parted -s /dev/nbd0 -- mkpart root ${clst_qcow2_roottype} ${clst_qcow2_efisize}GiB -1M || die "Cannot create root partition"
+parted -s ${mydevice} -- mkpart root ${clst_qcow2_roottype} ${clst_qcow2_efisize}GiB -1M || die "Cannot create root partition"
# mark it as generic linux filesystem partition
-parted -s /dev/nbd0 -- type 2 0FC63DAF-8483-4772-8E79-3D69D8477DE4 || die "Cannot set root partition UUID"
+parted -s ${mydevice} -- type 2 0FC63DAF-8483-4772-8E79-3D69D8477DE4 || die "Cannot set root partition UUID"
# note down name
-mypartroot=/dev/nbd0p2
+mypartroot=${mydevice}p2
# re-read the partition table
-partprobe /dev/nbd0 || die "Probing partition table failed"
+partprobe ${mydevice} || die "Probing partition table failed"
# make a vfat filesystem in p1
mkfs.fat -F 32 ${mypartefi} || die "Formatting EFI partition failed"
@@ -66,11 +67,11 @@ mkfs.xfs ${mypartroot} || die "Formatting root partition failed"
# mount things
# we need a mount point- how do we get one?
-mymountpoint=/tmp/bla
+mymountpoint="${1}.tmp.mnt"
mkdir -p "${mymountpoint}" || die "Could not create root mount point"
-mount /dev/nbd0p2 "${mymountpoint}" || die "Could not mount root partition"
+mount ${mypartroot} "${mymountpoint}" || die "Could not mount root partition"
mkdir -p "${mymountpoint}"/boot || die "Could not create boot mount point"
-mount /dev/nbd0p1 "${mymountpoint}/boot" || die "Could not mount boot partition"
+mount ${mypartefi} "${mymountpoint}/boot" || die "Could not mount boot partition"
# copy contents in
cp -a "${clst_target_path}"/* "${my_mountpoint}/"
@@ -89,6 +90,14 @@ umount "${mymountpoint}/boot" || die "Could not unmount boot partition"
umount "${mymountpoint}" || die "Could not unmount root partition"
# disconnect the nbd
-qemu-nbd -d /dev/nbd0 || die "Could not disconnect nbd0"
+qemu-nbd -d ${mydevice} || die "Could not disconnect nbd0"
+
+# rewrite with stream compression
+qemu-img convert -c -O qcow2 "${1}.tmp.qcow2" "${1}" || die "Could not compress QCOW2 file"
+
+# clean up
+rm "${1}.tmp.qcow2" || die "Could not delete uncompressed QCOW2 file"
+rmdir "${mymountpoint}/boot" || die "Could not remove boot mountpoint"
+rmdir "${mymountpoint}" || die "Could not remove root mountpoint"
# Finished...
next reply other threads:[~2024-10-06 19:33 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-06 19:33 Andreas K. Hüttel [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-10-13 13:35 [gentoo-commits] proj/catalyst:dilfridge/qcow2 commit in: targets/support/ Andreas K. Hüttel
2024-10-13 13:35 Andreas K. Hüttel
2024-10-13 13:02 Andreas K. Hüttel
2024-10-13 12:43 Andreas K. Hüttel
2024-10-12 22:56 Andreas K. Hüttel
2024-10-12 22:18 Andreas K. Hüttel
2024-10-12 22:06 Andreas K. Hüttel
2024-10-12 22:06 Andreas K. Hüttel
2024-10-12 21:58 Andreas K. Hüttel
2024-10-12 21:39 Andreas K. Hüttel
2024-10-12 21:39 Andreas K. Hüttel
2024-10-12 21:15 Andreas K. Hüttel
2024-10-12 20:48 Andreas K. Hüttel
2024-10-12 19:01 Andreas K. Hüttel
2024-10-12 17:58 Andreas K. Hüttel
2024-10-12 17:52 Andreas K. Hüttel
2024-10-12 16:43 Andreas K. Hüttel
2024-10-12 16:29 Andreas K. Hüttel
2024-10-12 15:18 Andreas K. Hüttel
2024-10-12 14:54 Andreas K. Hüttel
2024-10-12 14:29 Andreas K. Hüttel
2024-10-11 23:09 Andreas K. Hüttel
2024-10-11 23:01 Andreas K. Hüttel
2024-10-11 22:51 Andreas K. Hüttel
2024-10-11 22:28 Andreas K. Hüttel
2024-10-11 22:28 Andreas K. Hüttel
2024-10-11 22:07 Andreas K. Hüttel
2024-10-11 22:07 Andreas K. Hüttel
2024-10-11 20:14 Andreas K. Hüttel
2024-10-06 21:57 Andreas K. Hüttel
2024-10-06 20:41 Andreas K. Hüttel
2024-10-05 19:15 Andreas K. Hüttel
2024-10-05 15:48 Andreas K. Hüttel
2024-10-02 21:47 Andreas K. Hüttel
2024-09-27 23:45 Andreas K. Hüttel
2024-09-27 23:04 Andreas K. Hüttel
2024-08-09 19:34 Andreas K. Hüttel
2024-08-09 19:34 Andreas K. Hüttel
2024-08-09 19:34 Andreas K. Hüttel
2024-08-09 19:34 Andreas K. Hüttel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1728243110.6292209ad2ed7e1f98c49d6470e921b3ecb8b753.dilfridge@gentoo \
--to=dilfridge@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox