Jump to content

How to create script to flash USB drive.


Recommended Posts

Hello,

I am using unassigned devices to mount USB flash drives on unRAID 6.11.5. My goal is to format it with FAT32, copy the contents of an ISO file, copy the contents of a folder from unRAID, and then change a few files and parameters.

I seem to have most of the needed commands, but cannot make the device bootable. Here is what I have so far.

#!/bin/bash
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
## Available variables:
# ACTION - if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# DEVICE - partition device, e.g. /dev/sda1
# UD_DEVICE - unassigned devX designation
# SERIAL - disk serial number
# LABEL - partition label
# LUKS - if the device is encrypted, this is the partition device, e.g. /dev/sda1
# FSTYPE - partition filesystem
# MOUNTPOINT - where the partition is mounted
# OWNER - "udev" if executed by UDEV, otherwise "user"
# PROG_NAME - program name of this script
# LOGFILE - log file for this script

ISO=/mnt/user/Images/Deployments/USB/apps/Hiren\'s.BootCD.15.2.iso
ROOTDRV=/mnt/user/Images/Deployments/USB/Root

/usr/local/emhttp/webGui/scripts/notify -e "unRAID Server Notice" -s "USB Script" -d "Starting USB Creation" -i "normal"

sleep 10

/usr/local/sbin/rc.unassigned umount ${DEVICE}
sfdisk --delete ${DEVICE}
echo ',,c;' | sfdisk ${DEVICE}
/usr/local/sbin/rc.unassigned mount ${DEVICE}
sleep 10
sfdisk -A ${MOUNTPOINT}
mlabel -i ${MOUNTPOINT} ::${LABEL}

isoinfo -f -R -i $ISO | while read line; do
  d=$(dirname $line)
  od=${MOUNTPOINT}${d}
  [ -f $od ] && rm -f $od
  [ -d $od ] || mkdir -p $od
  isoinfo -R -i ${ISO} -x $line > ${MOUNTPOINT}${line}
done

rsync -a -v ${ROOTDRV} $MOUNTPOINT/ 2>&1

mlabel -i ${MOUNTPOINT} ::MYBOOT

/usr/local/sbin/rc.unassigned umount ${DEVICE}

/usr/local/emhttp/webGui/scripts/notify -e "unRAID Server Notice" -s "USB Script" -d "USB Drive is ready for use." -i "normal"

 

These are commands I picked up from around the web. They all seem to work so far except the device is not bootable. Or, rather, it does boot, but gives an error instead of the HBCD boot menu.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...