Creating VM image is working

This commit is contained in:
Artur Gurgul1 2025-08-10 09:06:58 +02:00
parent 82c27b7221
commit 6ad86cf1d4

View file

@ -1,6 +1,8 @@
#!/usr/bin/env zsh
export LINUX_DISK_IMG=/home/artur/winux/VM/linux/linux.img
#export LINUX_DISK_IMG=/home/artur/winux/VM/linux/linux.img
export LINUX_DISK_IMG=/home/artur/winux/VM/deb-orig/debian.img
export WINUX_DISK_IMG=./winux.img
# Mount the image of oryginal
@ -9,18 +11,26 @@ export WINUX_DISK_IMG=./winux.img
# Mounting the image
function wxumount {
echo "unmounting :$1"
mkdir -p $1
if mountpoint -q $1; then
echo "Unmounting $1..."
umount $1
if [ $? -eq 0 ]; then
echo "Successfully unmounted $1."
else
echo "Failed to unmount $1."
fi
while lsof +D $1 >/dev/null 2>&1 || fuser $1 >/dev/null 2>&1
do
fuser -a $1
echo "Waiting for $1 to be free..."
sleep 1
done
mkdir -p $1
if mountpoint -q $1; then
echo "Unmounting $1..."
umount $1
if [ $? -eq 0 ]; then
echo "Successfully unmounted $1."
else
echo "$1 is not mounted."
echo "Failed to unmount $1."
fi
else
echo "$1 is not mounted."
fi
}
wxumount /mnt/winux
@ -74,7 +84,7 @@ export LINUX_LOOP_DEV="$(losetup --find --show --partscan $LINUX_DISK_IMG)"
mount ${LINUX_LOOP_DEV}p1 /mnt/linux
# copying files
SAVED_PWD=`pwd`
cd /mnt/linux
tar --numeric-owner --xattrs --acls -cpf - \
--exclude='lost+found' \
@ -89,13 +99,16 @@ tar --numeric-owner --xattrs --acls -cpf - \
--exclude='run/*' \
. | tar --numeric-owner --xattrs --acls -xpf - -C /mnt/winux
cd "$SAVED_PWD"
#### TESTTING CODE
# losetup -j $WINUX_DISK_IMG
# Clean up after building
sync
sleep 1
wxumount /mnt/winux
wxumount /mnt/linux