[Motorola Droid 4] devilsclaw:
I unmount the loop245 you have to kill all the processes that are spwaned by ubuntu you can do that like this

for pid in `lsof | grep "\/data\/local\/mnt\/ubun" | awk '{print $2}'`
do
kill $pid
done

or a single line

for pid in `lsof | grep "\/data\/local\/mnt\/ubun" | awk '{print $2}'` ; do kill $pid ; done

---------- Post added at 09:28 AM ---------- Previous post was at 09:00 AM ----------

Here is the script I use

The REZ=1024x768

wont do anything unless you edit your init.sh to not get that info.

##########################################
#Ubuntu boot script V5 for Android #
#Built by Zachary Powell (zacthespack) #
#Thanks to everyone at XDA! #
#Modified to work with the D4 by Zeroktal#
##########################################
perm=$(id|cut -b 5)
if [ "$perm" != "0" ];then echo "This script requires root! Type: su"; exit; fi
/etc/init.d/webtop-shutdown.sh
mount -o remount,rw /dev/block/mmcblk0p5 /system
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext
export kit=/sdcard-ext/ubuntu
export bin=/system/bin
export mnt=/data/local/mnt/ubun
export USER=root
export REZ=1024x768
mkdir $mnt
export PATH=$bin:/usr/bin:/usr/local/bin:/usr/sbin:/bin:/usr/local/sbin:/usr/games:$PATH
export TERM=linux
export HOME=/root
if [ -b /dev/block/loop254 ]; then
echo "Loop device exists"
else
busybox mknod /dev/block/loop254 b 7 254
fi
losetup /dev/block/loop254 $kit/ubuntu.img
mount -t ext2 /dev/block/loop254 $mnt
mount -t devpts devpts $mnt/dev/pts
mount -t proc proc $mnt/proc
mount -t sysfs sysfs $mnt/sys
/system/xbin/busybox mount -o bind /sdcard-ext $mnt/sdcard
/system/xbin/busybox sysctl -w net.ipv4.ip_forward=1
echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
echo "127.0.0.1 localhost" > $mnt/etc/hosts
echo "Ubuntu is configured with SSH and VNC servers that can be accessed from the IP:"
ifconfig lo
echo " "
busybox chroot $mnt /root/init.sh

echo "Shutting down Ubuntu ARM"
/etc/init.d/webtop-restart.sh
for pid in `lsof | grep "\/data\/local\/mnt\/ubun" | awk '{print $2}'`
do
kill $pid
done
export mnt=/data/local/mnt/ubun
umount $mnt/sdcard
umount $mnt/dev/pts
umount $mnt/proc
umount $mnt/sys
umount $mnt
losetup -d /dev/block/loop254

This is my init.sh

#!/bin/bash
#############################################
# Asks User to screen size and saves as REZ #
#############################################
#echo "Now enter the screen size you want in pixels (e.g. 800x480), followed by [ENTER]:"

#read REZ
#REZ=960x540

##############################################
# Pick which desktop environment to use, this#
# is done by having a xstartup file for each #
# desktop, then renaming the one you want to #
# use to 'xstartup' before boot #
##############################################
#echo "Please select which Desktop environment you want to use, type the number to select it then press [ENTER]"
#echo "1 - LXDE"
#echo "2 - Gnome"
#echo "Make your Selection:"
#read DESKTOP
DESKTOP=1
if [ $DESKTOP == 1 ]
then
mv /root/.vnc/lxstartup /root/.vnc/xstartup
fi
if [ $DESKTOP == 2 ]
then
mv /root/.vnc/gxstartup /root/.vnc/xstartup
fi

###########################################
# Tidy up previous LXDE and DBUS sessions #
###########################################
rm /tmp/.X* > /dev/null 2>&1
rm /tmp/.X11-unix/X* > /dev/null 2>&1
rm /root/.vnc/localhost* > /dev/null 2>&1
rm /var/run/dbus/pid > /dev/null 2>&1

############################################################
# enable workaround for upstart dependent installs #
# in chroot'd environment. this allows certain packages #
# that use upstart start/stop to not fail on install. #
# this means they will have to be launched manually though #
############################################################
dpkg-divert --local --rename --add /sbin/initctl > /dev/null 2>&1
ln -s /bin/true /sbin/initctl > /dev/null 2>&1

###############################################
# start vnc server with given resolution and #
# DBUS server, (and optionally an SSH server) #
###############################################
vncserver :0 -geometry $REZ
dbus-daemon --system --fork > /dev/null 2>&1
/etc/init.d/ssh start

echo
echo "If you see the message 'New 'X' Desktop is localhost:0' then you are ready to VNC into your ubuntu OS.."
echo
echo "If VNC'ing from a different machine on the same network as the android device use the 1st address below:"
##########################################
# Output IP address of android device #
##########################################
#ifconfig | grep "inet addr"

echo
echo "If using androidVNC, change the 'Color Format' setting to 24-bit colour, and once you've VNC'd in, change the 'input mode' to touchpad (in settings)"

echo
echo "To shut down the VNC server and exit the ubuntu environment, just enter 'exit' at this terminal - and WAIT for all shutdown routines to finish!"
echo

###############################################################
# Spawn and interactive shell - this effectively halts script #
# execution until the spawning shell is exited (i.e. you want #
# to shut down vncserver and exit the ubuntu environment) #
###############################################################
/bin/bash -i

#########################################
# Disable upstart workaround and #
# kill VNC server (and optionally SSH) #
# Rename used xstartup to its first file#
#########################################
vncserver -kill :0
if [ $DESKTOP == 1 ]
then
mv /root/.vnc/xstartup /root/.vnc/lxstartup
fi
if [ $DESKTOP == 2 ]
then
mv /root/.vnc/xstartup /root/.vnc/gxstartup
fi
/etc/init.d/ssh stop