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.
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"
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.
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
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 :
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!)