From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: adriaan.schmidt@siemens.com, Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 4/6] imager: Move image types to schroot
Date: Sat, 14 May 2022 10:07:34 +0300 [thread overview]
Message-ID: <20220514070736.12997-5-amikan@ilbers.de> (raw)
In-Reply-To: <20220514070736.12997-1-amikan@ilbers.de>
Use schroot inside imager session to prepare images.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
meta/classes/image.bbclass | 3 +-
meta/classes/imagetypes_vm.bbclass | 7 +--
meta/classes/imagetypes_wic.bbclass | 73 +++++++++--------------------
3 files changed, 25 insertions(+), 58 deletions(-)
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 651b252..9b4b67b 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -210,7 +210,7 @@ python() {
localdata.setVar('IMAGE_FILE_HOST', '${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.${type}')
#bb.warn("FULLNAME is %s -> %s" % (localdata.getVar('IMAGE_FULLNAME', False), localdata.getVar('IMAGE_FULLNAME', True)))
localdata.setVar('IMAGE_FILE_CHROOT', '${PP_DEPLOY}/${IMAGE_FULLNAME}.${type}')
- localdata.setVar('SUDO_CHROOT', localdata.expand('sudo chroot ${BUILDCHROOT_DIR}'))
+ localdata.setVar('SUDO_CHROOT', localdata.expand('imager_run -d ${PP_ROOTFS} -u root --'))
# imager install
for dep in (d.getVar('IMAGER_INSTALL_' + bt_clean) or '').split():
@@ -219,7 +219,6 @@ python() {
imager_build_deps.add(dep)
# construct image command
- cmds.append('\timage_do_mounts')
image_cmd = localdata.getVar('IMAGE_CMD_' + bt_clean)
if image_cmd:
localdata.setVar('type', bt)
diff --git a/meta/classes/imagetypes_vm.bbclass b/meta/classes/imagetypes_vm.bbclass
index 8a676ac..a7090e6 100644
--- a/meta/classes/imagetypes_vm.bbclass
+++ b/meta/classes/imagetypes_vm.bbclass
@@ -4,8 +4,6 @@
# This class allows to generate images for VMware and VirtualBox
#
-inherit buildchroot
-
USING_OVA = "${@bb.utils.contains('IMAGE_BASETYPES', 'ova', '1', '0', d)}"
FILESEXTRAPATHS_prepend := "${LAYERDIR_core}/classes/vm-img:"
@@ -38,9 +36,8 @@ CONVERSION_OPTIONS = "${@set_convert_options(d)}"
convert_wic() {
rm -f '${DEPLOY_DIR_IMAGE}/${VIRTUAL_MACHINE_IMAGE_FILE}'
- image_do_mounts
bbnote "Creating ${VIRTUAL_MACHINE_IMAGE_FILE} from ${SOURCE_IMAGE_FILE}"
- sudo -E chroot --userspec=$( id -u ):$( id -g ) ${BUILDCHROOT_DIR} \
+ imager_run -p -d ${PP_WORK} -- \
/usr/bin/qemu-img convert -f raw -O ${VIRTUAL_MACHINE_IMAGE_TYPE} ${CONVERSION_OPTIONS} \
'${PP_DEPLOY}/${SOURCE_IMAGE_FILE}' '${VIRTUAL_MACHINE_DISK}'
}
@@ -83,7 +80,7 @@ IMAGE_CMD_ova() {
export LAST_CHANGE=$(date -u "+%Y-%m-%dT%H:%M:%SZ")
export OVA_FIRMWARE_UPPERCASE=$(echo ${OVA_FIRMWARE} | tr '[a-z]' '[A-Z]')
export OVF_TEMPLATE_STAGE2=$(echo ${OVF_TEMPLATE_FILE} | sed 's/.tmpl$//' )
- sudo -Es chroot --userspec=$( id -u ):$( id -g ) ${BUILDCHROOT_DIR} <<'EOSUDO'
+ imager_run -p -d ${PP_WORK} <<'EOSUDO'
set -e
export DISK_SIZE_BYTES=$(qemu-img info -f vmdk "${VIRTUAL_MACHINE_DISK}" \
| gawk 'match($0, /^virtual size:.*\(([0-9]+) bytes\)/, a) {print a[1]}')
diff --git a/meta/classes/imagetypes_wic.bbclass b/meta/classes/imagetypes_wic.bbclass
index cfcc94c..9c7a5eb 100644
--- a/meta/classes/imagetypes_wic.bbclass
+++ b/meta/classes/imagetypes_wic.bbclass
@@ -82,8 +82,6 @@ python () {
bb.build.addtask('do_transform_template', 'do_image_wic', None, d)
}
-inherit buildchroot
-
IMAGER_INSTALL_wic += "${WIC_IMAGER_INSTALL}"
# wic comes with reasonable defaults, and the proper interface is the wks file
ROOTFS_EXTRA ?= "0"
@@ -94,7 +92,6 @@ STAGING_DIR ?= "${TMPDIR}"
IMAGE_BASENAME ?= "${PN}-${DISTRO}"
FAKEROOTCMD ?= "${SCRIPTSDIR}/wic_fakeroot"
RECIPE_SYSROOT_NATIVE ?= "/"
-BUILDCHROOT_DIR = "${BUILDCHROOT_TARGET_DIR}"
WIC_CREATE_EXTRA_ARGS ?= ""
@@ -142,25 +139,11 @@ check_for_wic_warnings() {
do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}"
IMAGE_CMD_wic() {
- wic_do_mounts
generate_wic_image
check_for_wic_warnings
}
-wic_do_mounts() {
- buildchroot_do_mounts
- sudo -s <<'EOSUDO'
- ( flock 9
- set -e
- for dir in ${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}; do
- mkdir -p ${BUILDCHROOT_DIR}/$dir
- if ! mountpoint ${BUILDCHROOT_DIR}/$dir >/dev/null 2>&1; then
- mount --bind --make-private $dir ${BUILDCHROOT_DIR}/$dir
- fi
- done
- ) 9>${MOUNT_LOCKFILE}
-EOSUDO
-}
+SCHROOT_MOUNTS += "${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}"
generate_wic_image() {
export FAKEROOTCMD=${FAKEROOTCMD}
@@ -169,43 +152,31 @@ generate_wic_image() {
mkdir -p ${IMAGE_ROOTFS}/../pseudo
touch ${IMAGE_ROOTFS}/../pseudo/files.db
- # create the temp dir in the buildchroot to ensure uniqueness
- WICTMP=$(cd ${BUILDCHROOT_DIR}; mktemp -d -p tmp)
-
- sudo -E chroot ${BUILDCHROOT_DIR} \
- sh -c ' \
- BITBAKEDIR="$1"
- SCRIPTSDIR="$2"
- WKS_FULL_PATH="$3"
- STAGING_DIR="$4"
- MACHINE="$5"
- WICTMP="$6"
- IMAGE_FULLNAME="$7"
- IMAGE_BASENAME="$8"
- shift 8
- # The python path is hard-coded as /usr/bin/python3-native/python3 in wic. Handle that.
- mkdir -p /usr/bin/python3-native/
- if [ $(head -1 $(which bmaptool) | grep python3) ];then
+ imager_run -p -d ${PP_WORK} -u root <<'EOSUDO'
+ set -e
+
+ # The python path is hard-coded as /usr/bin/python3-native/python3 in wic. Handle that.
+ mkdir -p /usr/bin/python3-native/
+ if [ $(head -1 $(which bmaptool) | grep python3) ];then
ln -fs /usr/bin/python3 /usr/bin/python3-native/python3
- else
+ else
ln -fs /usr/bin/python2 /usr/bin/python3-native/python3
- fi
- export PATH="$BITBAKEDIR/bin:$PATH"
- "$SCRIPTSDIR"/wic create "$WKS_FULL_PATH" \
- --vars "$STAGING_DIR/$MACHINE/imgdata/" \
- -o "/$WICTMP/${IMAGE_FULLNAME}.wic/" \
+ fi
+
+ export PATH="${BITBAKEDIR}/bin:$PATH"
+
+ "${SCRIPTSDIR}"/wic create "${WKS_FULL_PATH}" \
+ --vars "${STAGING_DIR}/${MACHINE}/imgdata/" \
+ -o "/tmp/${IMAGE_FULLNAME}.wic/" \
--bmap \
- -e "$IMAGE_BASENAME" $@' \
- my_script "${BITBAKEDIR}" "${SCRIPTSDIR}" "${WKS_FULL_PATH}" "${STAGING_DIR}" \
- "${MACHINE}" "${WICTMP}" "${IMAGE_FULLNAME}" "${IMAGE_BASENAME}" \
- ${WIC_CREATE_EXTRA_ARGS}
+ -e "${IMAGE_BASENAME}" ${WIC_CREATE_EXTRA_ARGS}
+ find "/tmp/${IMAGE_FULLNAME}.wic/" -type f -name "*.direct*" | while read f; do
+ suffix=$(basename $f | sed 's/\(.*\)\(\.direct\)\(.*\)/\3/')
+ mv -f ${f} ${PP_DEPLOY}/${IMAGE_FULLNAME}.wic${suffix}
+ done
+EOSUDO
sudo chown -R $(stat -c "%U" ${LAYERDIR_core}) ${LAYERDIR_core} ${LAYERDIR_isar} ${SCRIPTSDIR} || true
- sudo chown -R $(id -u):$(id -g) ${BUILDCHROOT_DIR}/${WICTMP}
- find ${BUILDCHROOT_DIR}/${WICTMP} -type f -name "*.direct*" | while read f; do
- suffix=$(basename $f | sed 's/\(.*\)\(\.direct\)\(.*\)/\3/')
- mv -f ${f} "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic${suffix}"
- done
- rm -rf ${BUILDCHROOT_DIR}/${WICTMP}
+ sudo chown -R $(id -u):$(id -g) ${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic*
rm -rf ${IMAGE_ROOTFS}/../pseudo
}
--
2.17.1
next prev parent reply other threads:[~2022-05-14 7:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-14 7:07 [PATCH 0/6] Imager schroot migration Anton Mikanovich
2022-05-14 7:07 ` [PATCH 1/6] sbuild: Allow setting custom config paths Anton Mikanovich
2022-05-14 7:07 ` [PATCH 2/6] base: Implement bitbake build ID Anton Mikanovich
2022-05-14 7:07 ` [PATCH 3/6] imager: Migrate from buildchroot to schroot Anton Mikanovich
2022-05-14 7:07 ` Anton Mikanovich [this message]
2022-05-14 7:07 ` [PATCH 5/6] events: Cleanup lost schroot sessions if any Anton Mikanovich
2022-05-14 7:07 ` [PATCH 6/6] meta: Remove buildchroot Anton Mikanovich
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=20220514070736.12997-5-amikan@ilbers.de \
--to=amikan@ilbers.de \
--cc=adriaan.schmidt@siemens.com \
--cc=isar-users@googlegroups.com \
/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