Skip to content

Commit

Permalink
Replace kpartx with losetup for loop detection and detach (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Natale committed Jul 29, 2020
1 parent f23d8a3 commit 6f31132
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sdbuild/scripts/check_mounts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ fi

if sudo losetup -a | grep rootfs
then
echo "Loopback device still mounted please use losetup and kpartx to unmount"
echo "Loopback device still mounted please use losetup to unmount"
exit 1
fi
11 changes: 7 additions & 4 deletions sdbuild/scripts/resize_umount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export PATH=/sbin:$PATH

image_dir=$2
image_file=$1
used_loop=$(sudo losetup -j $image_file | grep -o 'loop[0-9]*')

boot_dev=/dev/mapper/$(sudo kpartx -v $image_file | grep -o 'loop[0-9]*p1')
root_dev=/dev/mapper/$(sudo kpartx -v $image_file | grep -o 'loop[0-9]*p2')
root_offset=$(sudo kpartx -v $image_file | grep 'loop[0-9]*p2' | cut -d ' ' -f 6)
boot_dev=/dev/mapper/${used_loop}p1
root_dev=/dev/mapper/${used_loop}p2
root_offset=$(sudo kpartx -v /dev/${used_loop} | grep 'loop[0-9]*p2' | cut -d ' ' -f 6)
sleep 5

sudo umount $image_dir/boot
Expand All @@ -31,7 +32,9 @@ sudo chroot / zerofree $root_dev

sleep 5

sudo kpartx -d $image_file
sudo dmsetup remove /dev/mapper/${used_loop}p1
sudo dmsetup remove /dev/mapper/${used_loop}p2
sudo losetup -d /dev/${used_loop}

sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $1
d # delete partition
Expand Down
5 changes: 4 additions & 1 deletion sdbuild/scripts/unmount_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ set -e

target=$1
image_file=$2
used_loop=$(sudo losetup -j $image_file | grep -o 'loop[0-9]*')

sudo umount $target/boot
sudo umount $target
sleep 5
sudo kpartx -d $image_file
sudo dmsetup remove /dev/mapper/${used_loop}p1
sudo dmsetup remove /dev/mapper/${used_loop}p2
sudo losetup -d /dev/${used_loop}

0 comments on commit 6f31132

Please sign in to comment.