Slax Linux - Executing the script file on USB drive

As per the instructions on Slax Linux website, after copying the contents from ISO file to the usb thumb drive, the script file (bootinst.sh) needs to be executed (on linux systems) to make the drive bootable.

On the drive formatted as FAT32, I am not able to give execute permission to the script file at all.
While as with drive formatted as ext4, though I am able to give execute permission, the file throws an error when tried to execute.

Could anyone please let me know if I seem to miss anything or suggest any workaround.
I am trying this on Linux Mint 20.1 OS.

Can you post the error and the entire script’s content?

Yes, it does not support Linux permissions. To Linux everything seems, as if it had permissions of 777. Which means, you can always execute anything.

Error received while executing:  ./bootinst.sh
* attempting to install bootloader to /media/abhishek/USB STICK/slax/boot...
Error installing boot loader.
Read the errors above and press enter to exit...

Below is the Script Content:

#!/bin/sh
#
#     This script will setup booting from disk (USB or harddrive)
#
#     If you see this file in a text editor instead of getting it executed,
#     then it is missing executable permissions (chmod). You can try to set
#     exec permissions for this file by using:  chmod a+x bootinst.sh
#     Alternatively, you may try to run bootinst.bat file instead
#
#     Scrolling down will reveal the actual code of this script.
#




















































# if we're running this from X, re-run the script in konsole or xterm
if [ "$DISPLAY" != "" ]; then
   if [ "$1" != "--rex" -a "$2" != "--rex" ]; then
      konsole --nofork -e /bin/sh $0 --rex 2>/dev/null || xterm -e /bin/sh $0 --rex 2>/dev/null || /bin/sh $0 --rex 2>/dev/null
      exit
   fi
fi

# make sure I am root
if [ "$UID" != "0" -a "$UID" != "" ]; then
   echo ""
   echo "You are not root. You must run bootinst script as root."
   echo "The bootinst script needs direct access to your boot device."
   echo "Use sudo or kdesudo or similar wrapper to execute this."
   read junk
   exit 1
fi

# change working directory to dir from which we are started
CWD="$(pwd)"
BOOT="$(dirname "$0")"
BOOT="$(realpath "$BOOT" 2>/dev/null || echo $BOOT)"
cd "$BOOT"

# find out device and mountpoint
PART="$(df . | tail -n 1 | tr -s " " | cut -d " " -f 1)"
DEV="$(echo "$PART" | sed -r "s:[0-9]+\$::" | sed -r "s:([0-9])[a-z]+\$:\\1:i")"   #"

# check if disk is already bootable. Mostly for Windows discovery
if [ "$(fdisk -l "$DEV" | fgrep "$DEV" | fgrep "*")" != "" ]; then
   echo ""
   echo "Partition $PART seems to be located on a physical disk,"
   echo "which is already bootable. If you continue, your drive $DEV"
   echo "will boot only Slax by default."
   echo "Press [Enter] to continue, or [Ctrl+C] to abort..."
   read junk
fi

ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then ARCH=64; else ARCH=32; fi
EXTLINUX=extlinux.x$ARCH

if [ ! -x ./$EXTLINUX ]; then
   # extlinux is not executable. There are two possible reasons:
   # either the fs is mounted with noexec, or file perms are wrong.
   # Try to fix both, no fail on error yet
   mount -o remount,exec $DEV
   chmod a+x ./$EXTLINUX
fi

if [ ! -x ./$EXTLINUX ]; then
   # extlinux is still not executable. As a last try, copy it to .exe
   # because the partition may be mounted with showexec option, from which
   # we probably can't escape by remount
   cp -f ./$EXTLINUX ./extlinux.exe
   EXTLINUX=extlinux.exe
fi

# install syslinux bootloader
echo "* attempting to install bootloader to $BOOT..."

./"$EXTLINUX" --install "$BOOT"

if [ $? -ne 0 ]; then
   echo "Error installing boot loader."
   echo "Read the errors above and press enter to exit..."
   read junk
   exit 1
fi

if [ "$DEV" != "$PART" ]; then
   # Setup MBR on the first block
   echo "* setup MBR on $DEV"
   dd bs=440 count=1 conv=notrunc if="$BOOT/mbr.bin" of="$DEV" 2>/dev/null

   # Toggle bootable flags
   echo "* set bootable flag for $PART"
   PART="$(echo "$PART" | sed -r "s:.*[^0-9]::")"
   (
      fdisk -l "$DEV" | fgrep "*" | fgrep "$DEV" | cut -d " " -f 1 \
        | sed -r "s:.*[^0-9]::" | xargs -I '{}' echo -ne "a\n{}\n"
      echo a
      echo $PART
      echo w
   ) | fdisk $DEV >/dev/null 2>&1
fi

echo "Boot installation finished."
echo "Press Enter..."
read junk
cd "$CWD"

Run the following comamnds and then post the output of the last command:

# Change to the location of `bootinst.sh`.
sudo apt update
sudo apt install -y fd-find
for f in $(fdfind extlinux.x); do file "$f"; done

Below is the output of command:

extlinux.x32: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=caeec5b5580ca0bd12870f7a44972077dd5c74e2, stripped
extlinux.x64: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a690d10d26aa199af183f2f194ec0ade9bf4944c, stripped

Ist the drive still formatted as FAT32?

Look here:

At the time of executing fdfind command as in previous reply, the drive was ext4 formatted.

If I try with a FAT32 formatted drive, I am not able to give execute permission to script (as is also mentioned in the above link you posted).

I get below error, trying to execute on FAT32 drive:

bash: ./bootinst.sh: Permission denied

I tried executing the script as root and it worked. I am able to boot from the USB drive.
It seems that only issue was not trying with the root privileges.

Thanks for your time. :slight_smile:

Okay, that’s very weird, because the script is checking if you are running itself as root:

# make sure I am root

if [ "$UID" != "0" -a "$UID" != "" ]; then

   echo ""

   echo "You are not root. You must run bootinst script as root."

   echo "The bootinst script needs direct access to your boot device."

   echo "Use sudo or kdesudo or similar wrapper to execute this."

   read junk

   exit 1

fi

Yes, It seems to check that.
But I am not sure why it didn’t display the alert before.

I tried a couple of changes which would make executing the script display the alert

  1. Using ‘or’ instead of ‘and’ in the condition, as below:
    if [ “$UID” != “0” -o “$UID” != “” ];

  2. Removing the parameter ( “$UID” != “” ) altogether and the condition kept as :
    if [ “$UID” != “0” ];

Executing the script without root and with these changes displays the intended alert.

I am not aware of how the scripts work, so I am not sure why this should work.

Semi-related - and sorry I don’t have an answer to OP’s original question, and apology in advance for hijacking your thread - but :

I recently encountered a bizarre issue on some RHEL 8 servers - an Oracle DBA was wanting to install some software with installer binaries copied to /tmp… He couldn’t execute them… they were owned by that user, with 770 (-rwxrwx— ) and the folder “/tmp” was execute for everyone (-rwxrwxr-xt [ note sticky bit is on “t”] - note “any” needs “x” to change to that folder)…

I repeated this symptom as root…

Created a shell script in /tmp… set execute on (chmod +x /tmp/shellscript.bash)…

tried to run it ./shellscript.bash - and it won’t run “permission denied” - HEY CURSE YOU! I AM ROOT!

So I created a subdirectory in /tmp - /testdir, made sure it was 0770 (-rwxrwx—), with no sticky bit on the end, I copied my script there, tried to run it - “permission denied” cd to my $HOME (/root) explicity specify path to the script :

/tmp/shellscript.bash
/tmp/testdir/shellscript.bash
exec /tmp/shellscript.bash

Nada - nothing - won’t let me run it, pemission denied, more denial (note : my name is an anagram of denial)… if I put that same script in root’s home and run it - it runs fine…

I’m guessing it’s some ugly selinux thing, inherited permissions or even ACL’s… ugly ugly ugly… thanks RHEL 8!

Might pay me to try and figure this out in an RHEL 8 VM I have… it doesn’t “feel” like factory default setting - but I need to confirm that…

Right now - the finger of suspicion (on my part) is point dead straight at selinux (I DETEST IT!)

1 Like