Since I know you're new to Ubuntu, here's a few general comments.
1. Put that partition in your
First off, in your script you use the line
sudo mount -U 80EA3F58EA3F49A4 /media/ubuntu/LENOVO to mount your NTFS partition. I would suggest to add that partition to your
/etc/fstab and map it to the UID of your partition there. Since you're on a single-user system, you may want to have an entry similar to this in your
UUID=80EA3F58EA3F49A4 /media/ubuntu/LENOVO ntfs rw,exec,uid=1000,gid=1000,umask=0002,nls=utf8,noauto 0 0
Most importantly, this tells the system to bind the mount point
/media/ubuntu/LENOVO to the UID
80EA3F58EA3F49A4. That way, in the future (and thus in your script) you can simply use
sudo mount /media/ubuntu/LENOVO instead of
sudo mount -U 80EA3F58EA3F49A4 /media/ubuntu/LENOVO. If the UID changes in the future (because you reformat the partition), it's better to have only one central place,
/etc/fstab, to edit rather than 20 scripts you may have lying around.
This also mounts the filesystem with various common options for NTFS partitions: read-write mode (
rw), permit the execution of binaries (
exec), make all files and directories on the file system belong to the user 1000 and group 1000 (
uid=1000,gid=1000) (that's your normal user), set the permissions bits for all files and directories to 775 (
umask=0002), set the character set for filenames to UTF-8 (
nls=utf8), and do not mount the partition automatically (
noauto). Refer to fstab(5) and mount(8) for more information. I personally find it convenient on my single-user system to be able to access all files on my NTFS partitions without having to use
sudo, but of course your mileage may vary.
You may also want to drop the
noauto option. Then, the partition will be mounted whenever the command
mount -a is run, and in particular, at boot time (and thus, it would typically be mounted the whole time). Then you wouldn't even have to use the
umount commands in your script at all, but I don't know if you want that.
2. Don't use
The recommended use-case for umount -l is to prevent hangs on shutdown due to an unreachable network share where a normal umount will hang due to a downed server or a network partition.
So this option is at least rather unusual to use in your case.
Whether you run
umount with or without
-l, a partition will not be force-unmounted (there's the
-f option for that). Rather, when you don't use
-l and the partition is still busy, the unmount will simply fail and return an error message; when using
-l and the partition is still busy, it will be detached from the filesystem hiearchy now (meaning you cannot access it anymore), but pending I/O operations will be silently completed in the background.
Since there shouldn't be any pending I/O operations after you've run
swapoff, by not using
-l you would at least notice if something is odd, because if the partition is unexpectedly still busy then the unmount command would output an error message.
3. Add error handling
You execute all commands in sequence, but don't check whether the previous command worked. So, e.g., if the mounting fails, then the
swapon command will be nevertheless attempted but fail, and then your game will start even though the swap was not activated.
echo "Mounting partition..."
sudo mount /media/ubuntu/LENOVO
if [ $? -ne 0 ]; then
echo "Could not mount partition, mission aborted." >&2
echo "Opening swapfile..."
sudo swapon /media/ubuntu/LENOVO/swapfile.img
if [ $? -ne 0 ]; then
echo "Could not activate swap, mission aborted." >&2
echo "Closing swapfile..."
sudo swapoff /media/ubuntu/LENOVO/swapfile.img
echo "Unmounting partition..."
sudo umount /media/ubuntu/LENOVO
echo "Mission accomplished!"