Build U-Boot SPL for custom board - bootloader

I have built a custom board with a iMX6 Processor.
Unfortunately i have not stripped out the Bootloader Config pins. They are still unconnected BGA-Balls. I do have access to UART1-3, JTAG and SD-Card interface and also to the BOOT0 and BOOT1 pins.
No i would like to start a U-Boot. Therefore i have ported or added my own board to the configs. I can build U-Boot successfull (not tested on the board yet).
Then i thought, i could download u-boot into the internal RAM of the i.MX6. unfortunately the i.MX got only 68kb RAM. The u-boot is about 160kb.
After some googling i saw that there is a possibility to compile a SP-Loader (SPL) which will first start, then load u-boot from SD-Card into the DDR3 RAM and then start the regular U-Boot from external DDR3 RAM.
I also found this readme:
https://github.com/ARM-software/u-boot/blob/master/doc/README.SPL
This is my actual defconfig file:
CONFIG_ARM=y
CONFIG_ARCH_MX6=y
CONFIG_TARGET_EVAL1A=y
CONFIG_MXC_UART=y
CONFIG_DM_MMC=y
CONFIG_SYS_TEXT_BASE=0x87800000
CONFIG_SPL_TEXT_BASE=0x0907000
CONFIG_SPL=y
CONFIG_SPL_BUILD=y
CONFIG_SPL_SERIAL_SUPPORT=y
CONFIG_SPL_FS_FAT=y
CONFIG_SPL=y
Im a little bit confused about SYS_TEXT_BASE and SPL_TEXT_BASE.
I think SPL_TEXT_BASE is where my SPL will reside? So 907000 is the start of the internal RAM. SYS_TEXT_BASE should be the start of the external DDR3 RAM right?
Anway, with the above config and the following commands:
make mrproper
make myBoard_config
make
I only get the regular u-boot.bin which is about 160kb in size.
What do i wrong? How can i build the SPL into a separate binary?
Thanks.
Edit: i solved it that way:
If you build linux by your self for your own board of even for an other board then you often get three different files.
U-Boot Bootloader
Linux Kernel (zImage, uImage)
rootfs (debian, ubuntu etc.)
Usually you get some advice how to format your SD-Card properly and copy your files onto them. But normally it is more convenient to have only one single image file which you can flash onto your card using some 3rd party tool like balena etcher.
During my development of the i.MX6 DevBoard i have created a shell script which does exactly this. Combining all these three parts into one image.
I provide this script here for free, without any further comments or instructions. This script was tested with an i.MX6 Controller using mainline U-Boot and Mainline Linux.
The script is provided without any warranty. Use it at your own risk.
#!/bin/bash
# Copyright: C. Hediger, 2019
# databyte.ch
# provided without warranty. use it at your own risk!
echo "-------------------------------------------"
echo "-------- SD-Card image generator ----------"
echo "-------------------------------------------"
echo ""
#echo "Please enter the Size of your Image"
read -p 'Size for *.img [MB] default 512MByte: ' imagesize
if [ -z "$imagesize" ]
then
imagesize="512"
fi
#echo "Please enter the destination of the image"
read -p 'Path to Image default /home/<user>/Desktop/sdcard/sdimage.img: ' imagepath
if [ -z "$imagepath" ]
then
imagepath="/home/"$USER"/Desktop/sdcard/sdimage.img"
fi
#echo "Please enter the path of the u-boot.imx"
read -p 'Path to u-boot default /home/<user>/Desktop/sdcard/u-boot.imx: ' ubootpath
if [ -z "$ubootpath" ]
then
ubootpath="/home/"$USER"/Desktop/sdcard/u-boot.imx"
fi
#echo "Please enter the path of the rootfs.tar.gz"
read -p 'Path to rootfs default /home/<user>/Desktop/sdcard/rootfs.tar.gz: ' rootfspath
if [ -z "$rootfspath" ]
then
rootfspath="/home/"$USER"/Desktop/sdcard/rootfs.tar.gz"
fi
read -p 'Strip output directory? Default 1: ' stripcount
if [ -z "$stripcount" ]
then
stripcount="1"
fi
#echo "Please enter the path of the kernel"
read -p 'Path to kernel default /home/<user>/Desktop/sdcard/zImage: ' kernelpath
if [ -z "$kernelpath" ]
then
kernelpath="/home/"$USER"/Desktop/sdcard/zImage"
fi
#echo "Please enter the path of the device tree blob"
read -p 'Path to *.dtb default /home/<user>/Desktop/sdcard/eval1a.dtb: ' dtbpath
if [ -z "$dtbpath" ]
then
dtbpath="/home/"$USER"/Desktop/sdcard/eval1a.dtb"
fi
ddimagesize=$((imagesize * 2))k
partitionsize=+$((imagesize - 20))M
#echo $imagesize
#echo $imagepath
#echo $partitionsize
dd status=progress if=/dev/zero of=$imagepath bs=512 count=$ddimagesize
(
echo o # Create a new empty DOS partition table
echo p # Add a new partition
#echo u # change units to cylinders
echo x # expert mode
echo h # Partition number
echo 255
echo s
echo 63
echo c
echo
echo r
echo n
echo p
echo 1
echo 4096
echo $partitionsize
echo p
echo w
) | fdisk $imagepath
dd bs=512 seek=2 conv=notrunc if=$ubootpath of=$imagepath
loodevice="$(sudo losetup --partscan --show --find $imagepath)"
loopartition="$loodevice"p1
mountfolder=/mnt/sdcardtmpfolder
echo "Device: "$loodevice
echo "Partition: "$loopartition
sudo mkfs.ext2 $loopartition
sudo mkdir -p $mountfolder
sudo mount $loopartition $mountfolder
sudo cp $rootfspath "$mountfolder"/rootfs.tar.gz
sudo tar xzf "$mountfolder"/rootfs.tar.gz -C $mountfolder --strip-components=$stripcount
sudo cp $kernelpath "$mountfolder"/boot/zImage
sudo cp $dtbpath "$mountfolder"/boot/imx6ull-dtb-eval1a.dtb
sudo rm "$mountfolder"/rootfs.tar.gz
echo " ----- Please extract rootfs -----"
read
sudo umount /mnt/sdcardtmpfolder
sudo fsck.ext4 $loopartition
sudo losetup -d $loodevice
sudo rm -R /mnt/sdcardtmpfolder
sudo gparted $imagepath

Related

How do I get USB device info from a script running within a Docker container in a bash script?

I made a mount.sh file inspired by balena-storage. It works when I login to the container via the balena.io dashboard where I'm deploying (could be the same elsewhere) and run the script manually. It hangs with unpopulated variables when the container runs the script when starting (a script that runs the script). I think it’s a permissions issue or script running script thing. I'm not sure how to proceed in reading USB device variables.
mount.sh:
# Automatically mount a USB drive by specified volume name.
# Note: make sure to have USB_VOLUME_NAME set in env vars.
# Thanks: https://github.com/balena-io-playground/balena-storage
echo "Checking for USB_VOLUME_NAME..."
echo "A"
if [[ -z $USB_VOLUME_NAME ]]; then
echo "Make sure to set environment variable USB_VOLUME_NAME in order to find a connected USB drive by that label and connect to it. Exiting..." >> /usr/src/app/mount.log
exit 1
fi
echo "B"
# Get device by label env var set in balena.io dashboard device env vars
USB_DEVICE=$(blkid -L $USB_VOLUME_NAME)
if [[ -z $USB_DEVICE ]]; then
echo "Invalid USB_DEVICE name: $USB_DEVICE" >> /usr/src/app/mount.log
exit 1
fi
echo $USB_DEVICE
echo "C"
# Get extra device info
ID_FS_TYPE=${ID_FS_TYPE:=$(/bin/udevadm info -n $USB_DEVICE | /usr/bin/awk -F "=" '/ID_FS_TYPE/{ print $2 }')}
ID_FS_UUID_ENC=${ID_FS_UUID_ENC:=$(/bin/udevadm info -n $USB_DEVICE | /usr/bin/awk -F "=" '/ID_FS_UUID_ENC/{ print $2 }')}
ID_FS_LABEL_ENC=${ID_FS_LABEL_ENC:=$(/bin/udevadm info -n $USB_DEVICE | /usr/bin/awk -F "=" '/ID_FS_LABEL_ENC/{ print $2 }')}
MOUNT_POINT=/mnt/$USB_VOLUME_NAME
echo $ID_FS_TYPE
echo $ID_FS_UUID_ENC
echo $ID_FS_LABEL_ENC
echo $MOUNT_POINT
echo "D"
# Bail if file system is not supported by the kernel
if ! /bin/grep -qw $ID_FS_TYPE /proc/filesystems; then
echo "File system not supported: $ID_FS_TYPE" >> /usr/src/app/mount.log
exit 1
fi
echo "E"
# Mount device
if /bin/findmnt -rno SOURCE,TARGET $USB_DEVICE >/dev/null; then
echo "Device $USB_DEVICE is already mounted!" >> /usr/src/mount.log
else
echo "Mounting - Source: $USB_DEVICE - Destination: $MOUNT_POINT" >> /usr/src/app/mount.log
/bin/mkdir -p $MOUNT_POINT
/bin/mount -t $ID_FS_TYPE -o rw $USB_DEVICE $MOUNT_POINT
fi
echo "F"
When the container runs the script, it gets stuck after "D", with ID_FS_TYPE, ID_FS_UUID_ENC and ID_FS_LABEL_ENC being empty (a good reason to hang).
output:
Checking for USB_VOLUME_NAME...
A
B
/dev/sda1
C
/mnt/MYDRIVE
D
My dockerfile.template:
FROM balenalib/%%BALENA_MACHINE_NAME%%-node
# Enable udev for detection of dynamically plugged devices
ENV UDEV=on
COPY udev/usb.rules /etc/udev/rules.d/usb.rules
# Install dependencies
RUN install_packages util-linux
WORKDIR /usr/src/app
# Move scripts used for mounting USB
COPY scripts scripts
RUN chmod +x scripts/*
# server.js will run when container starts up on the device
CMD ["/bin/bash", "/usr/src/app/scripts/start.sh"]
start.sh:
echo "Mounting USB drive..."
cd /usr/src/app/scripts
/bin/bash mount.sh
# It won't get this far while the script above hangs.
echo "Starting server..."
cd /usr/src/app
/usr/local/bin/yarn run serve
I can confirm that everything works when running from within the container manually:
cd /usr/src/app/scripts
/bin/bash mount.sh
Output:
Checking for USB_VOLUME_NAME...
A
B
/dev/sda1
C
vfat
BE23-31BA
MYDRIVE
/mnt/MYDRIVE
D
E
F
(and the drive mounted)
How would I resolve the empty variables?
Always quote every shell variable you use. (Unless you're absolutely sure of what you're doing, and what you expect to happen if the variable value is empty or includes spaces.)
Without quoting, when you
/bin/grep -qw $ID_FS_TYPE /proc/filesystems
and $ID_FS_TYPE is empty, that word just gets omitted from the command line, so you get
/bin/grep -qw /proc/filesystems
which uses /proc/filesystems as a regexp, and tries to grep over its stdin; this leads to the apparent hang you see.
If instead you quote it:
/bin/grep -qw "$ID_FS_TYPE" /proc/filesystems
it will get an empty string as the regexp parameter and a filename as the input parameter, which will trivially succeed (but not hang).
For similar reasons, I'd expect you'd get a shell syntax error if $USB_VOLUME_NAME is unset, and the whole script will act oddly if that variable name has a space in it.

tshark to split pcap file based on MAC address

I have around 7 PCAP files and I would like to split them based on MAC address then place them into separate files and a new directory for each PCAP file based on the title of the PCAP files. My current approach (see below) is obviously not the best approach and would need the loop part.
#!/bin/bash
#Name of PCAP file to analyse
pcap_file="tcpdump_2019-06-21_213044.pcap"
#MAC address to filter
mac="00:17:88:48:89:21"
mkdir /2019-06-21/
for steam in $pcap_file;
do
/usr/bin/tshark -r $pcap_file -Y "eth.addr eq 00:17:88:48:89:21" -w
$mac.pcap
done
#!/bin/bash
pcap_file=(tcpdump_2019-07-01_000001.pcap tcpdump_2019-06-26_120301.pcap)
macs=( 00:17:88:71:78:72 )
devices=(phillips_1 phillips_2)
for pcf in ${pcap_file[*]}
do
echo "$pcap_file" >&2
/usr/bin/tshark -r "$pcf" -Y "eth.addr eq $macs" -w "$devices.pcap"
done
Something like:
#!/bin/bash
# usage "$0" pcap_file1 pcap_file2 ...
#macs=( 00:17:88:48:89:21 00:17:88:48:89:22 00:17:88:48:89:23 )
ips=( 192.168.202.68 192.168.202.79 192.168.229.153 192.168.23.253 )
for pcf in "$#"
do
dir="`basename "$pcf" | sed -r 's/(tcpdump_)(.*)(_[0-6]{6}.pcap)/\2/'`"
mkdir "$dir"
cd "$dir" || exit # into the newly created child dir
pcf="`realpath -e "$pcf"`" # make sure the file can be found from the new directory
#for mac in ${macs[*]}
for ip in ${ips[*]}
do
#echo "$mac" >&2
echo "$ip" >&2
#/usr/bin/tshark -r "$pcf" -Y "eth.addr eq $mac" -w "$mac.pcap"
/usr/bin/tshark -r "$pcf" -Y "ip.addr == $ip" -w "$ip.pcap"
done
cd .. # back to the parent dir
done
Where in your case you would use the commented out lines.
I used IPs to test, for I couldn't find an appropriate file to test mac's on. I used the file maccdc2012_00000.pcap.gz found here: https://www.netresec.com/?page=MACCDC to test (note: my example takes a long time to finish on that large file).

Make ubuntu persistent live iso faster

First, I want to share my experience about how to make a USB pendrive of Ubuntu live iso, which is multiboot and it can duplicate itself by a bash code. I am trying to guide you to make something like that, then, as long as I'm not an expert, asking how can I make it faster(while booting, operating or cloning)?
First of all, you should partition your usb flash driver to two partitions by some tools like GParted. One fat32 partition and the other ext2 with the fix size of 5500MB(if you change its size then you have to change this number in the bash code too). You can find the size of the first partition by the whole size of your usb flash drive minus the size of second partition.
Second, you must download ubuntu iso image(I downloaded lubuntu 13.10 because it's faster, but I think ubuntu must work too) then copy it in the first partition(the fat32 partition.) and rename it to ubuntu.iso.
Third, run this command to install grub bootloader(you can find this command in the bash code too)
sudo grub-install --force --no-floppy --boot-directory=/mnt/usb2/boot /dev/sdc1
"/mnt/usb2" directory is the one that you mounted the first partition and /dev/sdc1 is its device. If you don't know about this information just use fdisk -l or Menu->Preferences->Disks to find out. Then copy the following files in their mentioned directories and reboot to usb flash(for my motherboard by pushing F12 then selecting my flash device from the "HDD Hard" list .)
/path to the first partition/boot/grub/grub.cfg
set timeout=10
set default=0
menuentry "Run Ubuntu Live ISO Persistent" {
loopback loop /ubuntu.iso
linux (loop)/casper/vmlinuz persistent boot=casper iso-scan/filename=/ubuntu.iso noeject noprompt splash --
initrd (loop)/casper/initrd.lz
}
menuentry "Run Ubuntu Live ISO(for clone to a new USB drive)" {
loopback loop /ubuntu.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/ubuntu.iso noeject noprompt splash --
initrd (loop)/casper/initrd.lz
}
the bash code:
/path to the first partition/boot/liveusb-installer
#!/bin/bash
destUSB=$1
# insert mountpoint, receive device name
get_block_from_mount() {
dir=$(readlink -f $1)
MOUNTNAME=`echo $dir | sed 's/\\/$//'`
if [ "$MOUNTNAME" = "" ] ; then
echo ""
return 1
fi
BLOCK_DEVICE=`mount | grep "$MOUNTNAME " | cut -f 1 -d " "`
if [ "$BLOCK_DEVICE" = "" ] ; then
echo ""
return 2
fi
echo $BLOCK_DEVICE
return 0
}
sdrive=$(echo $destUSB | sed 's/\/dev\///')
if ! [ -f /sys/block/$sdrive/capability ] || ! [ $(($(< /sys/block/$sdrive/capability )&1)) -ne 0 ]
then
echo "Error: The argument must be the destination usb in /dev directory!"
echo "If you don't know this information just try 'sudo fdisk -l' or use Menu->Prefrences->Disks"
exit 1
fi
srcDirectory=/isodevice
srcDev=`get_block_from_mount $srcDirectory`
srcUSB="${srcDev%?}"
if [ $srcUSB == $destUSB ]; then
echo "Error: The argument of device is wrong! It's the source USB drive."
exit 1
fi
diskinfo=`sudo parted -s $destUSB print`
echo "$diskinfo"
# Find size of disk
v_disk=$(echo "$diskinfo"|awk '/^Disk/ {print $3}'|sed 's/[Mm][Bb]//')
second_disk=5500
if [ "$v_disk" -lt "6500" ]; then
echo "Error: the disk is too small!!"
exit 1
elif [ "$v_disk" -gt "65000" ]; then
echo "Error: the disk is too big!!"
exit 1
fi
echo "Partitioning ."
# Remove each partition
for v_partition in $(echo "$diskinfo" |awk '/^ / {print $1}')
do
umount -l ${destUSB}${v_partition}
parted -s $destUSB rm ${v_partition}
done
# Create partitions
let first_disk=$v_disk-$second_disk
parted -s $destUSB mkpart primary fat32 1 ${first_disk}
parted -s $destUSB mkpart primary ext2 ${first_disk} ${v_disk}
echo "Formatting .."
# Format the partition
mkfs.vfat ${destUSB}1
mkfs.ext2 ${destUSB}2 -L home-rw
echo "Install grub into ${destUSB}1 ..."
mkdir /mnt/usb2
mount ${destUSB}1 /mnt/usb2
grub-install --force --no-floppy --boot-directory=/mnt/usb2/boot $destUSB
cp $srcDirectory/boot/grub/grub.cfg /mnt/usb2/boot/grub
cp $srcDirectory/boot/liveusb-installer /mnt/usb2/boot
echo "Copy ubuntu.iso from ${srcUSB}1 to ${destUSB}1......"
cp $srcDirectory/ubuntu.iso /mnt/usb2
umount -l ${destUSB}1
rm -r /mnt/usb2
echo "Copy everything from ${srcUSB}2 to ${destUSB}2 ............"
dd if=${srcUSB}2 of=${destUSB}2
echo "It's done!"
exit 0
So after that if you want to clone this flash, just reboot to the second option of grub boot loader then put another usb flash drive on and run liveusb-installer /dev/sdc. It will make another usb drive with every installed apps from the first one into /dev/sdc drive. I made this code so all of my students have the same flash drive to practice programming with c, python or sage everywhere. The speed of non-persistent (the second option in grub menu) is fine, but the fist option, which is the persistent one, is take 3-4 min to boot and after that its a little bit slow! Also, the installation(duplication) take a half an hour to complete! Is there any improvement to make it faster in any way?
any suggestion will be appreciated
As I said before, if lubuntu boots non-persistent, it will be faster. So I infer that if I just keep home directory persistent then the rest of folders of root directory would be in the RAM, then it must be faster. For achieving this, I changed it a little bit to boot with /home persistent and install every application after each boot, automatically. It's turned out in this way the boot time doesn't changed(booting + installing) but operating is so faster, which is great for me.
I didn't change grub.cfg at all. I changed the bash code(liveusb-installer) to label the second partition to home-rw, so the rest of folders just stay in RAM.
In the bash code: /path to the first partition/boot/liveusb-installer, just change the line of mkfs.ext2 ${destUSB}2 -L casper-rw to mkfs.ext2 ${destUSB}2 -L home-rw.
After changing liveusb-installer you can use that when you want to clone this USB drive. If you installed it before(by using above recipes) then just go to second option of grub menu(the non-persistent one) then format the second partition and label it to home-rw. After that just reboot to first option of grub menu, then become online and install any program that you wish to be there always.
sudo apt-get update
sudo apt-get install blablabla
After installing, copy every packages and lists to ~/apt directory by running these commands:
mkdir ~/apt
mkdir ~/apt/lubuntu-archives
mkdir ~/apt/lubuntu-lists
cp /var/cache/apt/archives/*.deb ~/apt/lubuntu-archives
cp /var/lib/apt/lists/*ubuntu* ~/apt/lubuntu-lists
Now copy following files in ~/apt directory
/home/lubuntu/apt/start-up
#!/bin/bash
apt_dir=/home/lubuntu/apt
# This script meant to open by /home/lubuntu/apt/autostart
for file in $(ls $apt_dir/lubuntu-archives)
do
ln -s $apt_dir/lubuntu-archives/$file /var/cache/apt/archives/$file
done
for file in $(ls $apt_dir/lubuntu-lists)
do
ln -s $apt_dir/lubuntu-lists/$file /var/lib/apt/lists/$file
done
apt-get install -y binutils gcc g++ make m4 perl tar \
vim codeblocks default-jre synapse
exit 0
Also change the above packages to blablabla of the install command.
/home/lubuntu/apt/autostart
#!/bin/bash
# This script meant to open by /home/lubuntu/.config/lxsession/Lubuntu/autostart
# or autostart of "Menu->Perferences->Default applications for LXSession"
xterm -e /usr/bin/sudo /bin/bash /home/lubuntu/apt/start-up
synapse
Then edit this file /home/lubuntu/.config/lxsession/Lubuntu/autostart and add the address of above file into it. Like this:
/home/lubuntu/apt/autostart
Now after each reboot a nice terminal will be opened and all the packages will install as I wish! The advantage of this method over persistent root directory is the much faster operation, for instance, opening windows or running programs. But the time of cloning and booting are steal long. I will be so glad that anybody helps me to make it more professional and faster.

Should this be done with bash script or automator or applescript?

I have bash command that contains a variable to a file which updates the firmware for a specific hardware and give it a serial number.
#!/bin/bash
fpath=$(dirname "$0")
ee_image=mlr-2000119.bin
sudo nvram tbt-options=4
sudo /usr/sbin/bless -mount / -firmware "$fpath/ThorUtilDevice.efi" -payload "$fpath/$ee_image" -options "-o -ej 1 -blast efi-apple-payload0-data"
sudo reboot now
I would like to create a file through automator or applescript that will create this same file but will automatically increase the ee_image bin file name by one. So that the end user doesn't always have to open the command file in text edit, make the change manually then save then execute the file..
Any help with this would be a God send.
The last line in your script sudo reboot now would make any sort of loop meaningless.
However, if you insist, use may a loop:
#!/bin/bash
fpath=$(dirname "$0")
for i in {2000119..3000119}; do
ee_image=mlr-${i}.bin
sudo nvram tbt-options=4
sudo /usr/sbin/bless -mount / -firmware "$fpath/ThorUtilDevice.efi" -payload "$fpath/$ee_image" -options "-o -ej 1 -blast efi-apple-payload0-data"
sudo reboot now
done
This would loop through mlr-2000119.bin to mlr-3000119. You can also consider passing an argument to the script in which case you can use your original script with the ee_image line as
ee_image=mlr-$1.bin
and invoke bash /path/to/your/script.sh 2000119
#devnull wrote:
The last line in your script sudo reboot now would make any sort of loop meaningless.
I believe that the reboot command is just like any other command. It should be echoed to a file rather than being run to generate the script for the end-user.
I think that a good idea would be to have a script that creates scripts.
This is similar to how many websites work. The script on the server can echo HTML, CSS, and JavaScript code for consumption by the web browser.
Here is an example:
#!/bin/bash
# set the path to the dir
dir=$(dirname $0)"/"
# set the path to the file that keeps track of the serial numbers
snFile="$dir""sn.txt"
# set the file name of the file to be generated
fileName="serialize"
# read the last serial number used
if [ -e "$snFile" ];
then
read lastSN < "$snFile"
else
lastSN="0"
fi
# increment the serial number
let "nextSN = $lastSN + 1"
echo "$nextSN" > "$snFile"
# create a path variable for the file being created.
generatedPath="$dir$fileName$nextSN.sh"
# generate the script
echo "#!/bin/bash" > "$generatedPath"
echo 'fpath=$(dirname "$0")' >> "$generatedPath"
echo '' >> "$generatedPath"
echo "ee_image=mlr-$nextSN.bin" >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo nvram tbt-options=4' >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo /usr/sbin/bless -mount / -firmware \"$fpath/ThorUtilDevice.efi\" -payload \"$fpath/$ee_image\" -options \"-o -ej 1 -blast efi-apple-payload0-data\" \' >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo reboot now' >> "$generatedPath"
# give the user some feedback
echo "generatedPath: $generatedPath"
If having your end-user run a bash script is good enough, then I think that you're almost done.
If you want to have an even better user interface and have a Mac application for the end-user to run, send me an email and I can help you with that.
kaydell#learnbymac.com

Clonezilla custom-ocs bash script failing on ocs-onthefly command

I'm doing a custom clonezilla.. one for source to send a local disk to remote disk with ocs-onthefly... that custom-ocs is working fine.
However, the custom-ocs for the destination for some reason is not working.. the problem is the last line "/usr/sbin/ocs-onthefly -s $src_ip -t $dest_disk" .. for some reason clonezilla is balking at that line and gives the usage/help output instead of running the command..
Any ideas on why the ocs-onthefly command is not accepting the parameters? The parameters are correct. If you run "/usr/sbin/ocs-onthefly -s 192.168.150.1 -t sda" it runs fine.
custom-ocs for destination script is here: https://www.dropbox.com/s/9mfrt0n50sheayn/custom-ocs_destination-REVISED.txt
Attempting a code block also:
#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Ref: http://sourceforge.net/forum/forum.php?thread_id=1759263&forum_id=394751
# In this example, it will allow your user to use clonezilla live to choose
# (1) backup the image of /dev/hda1 (or /dev/sda1) to /dev/hda5 (or /dev/sda5)
# (2) restore image in /dev/hda5 (or /dev/sda5) to /dev/hda1 (or /dev/sda1)
# When this script is ready, you can run
# ocs-iso -g en_US.UTF-8 -k NONE -s -m ./custom-ocs
# to create the iso file for CD/DVD. or
# ocs-live-dev -g en_US.UTF-8 -k NONE -s -c -m ./custom-ocs
# to create the zip file for USB flash drive.
# Begin of the scripts:
# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
# load the setting for clonezilla live.
[ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf
# Load language files. For English, use "en_US.UTF-8".
ask_and_load_lang_set en_US.UTF-8
# The above is almost necessary, it is recommended to include them in your own custom- ocs.
# From here, you can write your own scripts.
# functions
decide_sda_or_hda() {
if [ -n "$(grep -Ew sda1 /proc/partitions)" ]; then
disk=sda
elif [ -n "$(grep -Ew hda1 /proc/partitions)" ]; then
disk=hda
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "No hard disk detected!"
echo "Program terminated!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
# src_part: hda1 or sda1, tgt_part: hda5 or sda5
dest_disk=${disk}
}
##################
###### MAIN ######
##################
# Set network on destination workstation 1
# Determine if active link then set act_eth
while [ -z "$(/sbin/mii-tool 2>/dev/null | awk -F ":" '/link ok/ {print $1}')" ]; do
dialog --title "NO LINK!!" --msgbox "\n Need an active link in order to continue!!" 6 50
done
act_eth=`/sbin/mii-tool 2>/dev/null | awk -F ":" '/link ok/ {print $1}'`
# Set IP Address of destination workstation 1
/sbin/ifconfig $act_eth 192.168.150.2 netmask 255.255.255.0 up
/sbin/route add default gw 192.168.150.254
/bin/echo "nameserver 8.8.8.8" >> /etc/resolv.conf
# Find the disk device
decide_sda_or_hda
# Prompt for IP address of source disk
OUTPUT="./input.txt"
>$OUTPUT
dialog --title "Need SOURCE IP" --inputbox "Enter IP address of the SOURCE server: " 8 60 2>$OUTPUT
src_ip=$(<$OUTPUT)
# Ready the destination disk to receive from source (source should already be waiting in clonezilla), and contact source to start transfer to destination
/usr/sbin/ocs-onthefly -s $src_ip -t $dest_disk
When I test via echo (not within clonezilla but just on a linux box) the dialog output for $src_ip and also $dest_disk it outputs the variables fine, so I really don't know why ocs-onthefly is not accepting it.
Looks like your ocs-onthefly command is getting unexpected arguments. To analyze, lets see the actual command with
echo /usr/sbin/ocs-onthefly -s $src_ip -t $dest_disk
Or, maybe even better, the result of running your script with
bash -x script
will tell you what is wrong.

Resources