I have very strange problem.
I made script with a function which wipes SD card and sets one big partition with some directories. Function is called on first boot by uci-defaults script. Also there is an interactive script for user but it doesnt matter for my question.
Now here's the problem:
1. First boot call (after sysupgrade with factory reset)
Script is running well, no problems, mounting works, fstab entry is changed and enabled, final check is partition mounted is succesfull. At least this is how i see it in logs. But when i do "mount" i see nothing is mounted. Reboot doesnt help. Only turning off and on the device (or "block mount" command).
2. Calling uci-defaults script manually
All the same but at the end device is mounted.
function script
#!/bin/bash
create_sd(){
if [ "$1" = "34lkmbakjrt-2q" ]; then
DEVICE=/dev/sda
if [ -n "$DEVICE" ]; then
PARTITION="${DEVICE}1"
DIR="$2"
TMPDIR=/tmp/fake_sda1
MAC="$3"
mkdir -p $TMPDIR
mkdir -p $DIR
if [ "$(mount | grep $DEVICE?)" ]; then
#ls $DEVICE? | xargs -n1 umount -l #force unmount all SD card partitions
/sbin/block umount
fi
mount --bind $TMPDIR $DIR #mounts temporary directory to gather data sent by move_data cron script i time when sd is being prepared
dd if=/dev/zero of=$DEVICE bs=1M count=1 #wipe partition table by writing with 0 first 1MB of SD
{
echo ,,,-
} | sfdisk $DEVICE #creates one partition on whole device
mkfs.ext4 -L $MAC -F $PARTITION
umount -l ${DIR}
block detect > /etc/config/fstab #autogenerates fstab
uci set fstab.@mount[-1].target=${DIR}
uci set fstab.@mount[-1].enabled=1
uci commit fstab
/sbin/block mount #mounts all
if [ "$(df -h | grep $PARTITION)" ]; then
echo "SUCCESS, SC_Card is mounted now. Deleting temporary directory ..."
rsync $TMPDIR $DIR
mkdir -p "$DIR/logs" "$DIR/files" #in case TMPDIR was empty
rm -rf $TMPDIR
exit 0
else
echo 'SD card is present but not mounted.'
exit 1
fi
else
echo 'SD card is not present.'
exit 1
fi
else
echo "You cant call this function directly. Call dominik_sd instead."
fi
}
uci-defaults caller
#!/bin/bash
echo "=========/etc/uci-defaults/97_dominik_sd_boot================="
echo `date '+%d/%m/%Y_%H:%M:%S'`
. /usr/lib/dominik_lib
. /usr/lib/dominik_sdfunc
create_sd "34lkmbakjrt-2q" ${SDCARD_DIR} ${MAC}
#create_sd "34lkmbakjrt-2q" "/mnt/sda1" "SOMEMACADDRESS"
block mount
exit 0
and here's the log from first boot
=========/etc/uci-defaults/97_ocko_sd_boot=================
15/04/2018_10:31:42
1+0 records in
1+0 records out
sfdisk: Checking that no-one is using this disk right now ...
sfdisk: OK
sfdisk: /dev/sda: unrecognized partition table type
sfdisk: No partitions found
sfdisk: Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Disk /dev/sda: 1023 cylinders, 122 heads, 62 sectors/track
Old situation:
New situation:
Units: cylinders of 3872768 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sda1 0+ 1022 1023- 3868985+ 83 Linux
/dev/sda2 0 - 0 0 0 Empty
/dev/sda3 0 - 0 0 0 Empty
/dev/sda4 0 - 0 0 0 Empty
Successfully wrote the new partition table
sfdisk: If you created or changed a DOS partition, /dev/foo7, say, then use dd($
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
Re-reading the partition table ...
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 967246 4k blocks and 241920 inodes
Filesystem UUID: 65ef39cf-4d69-40e1-92cb-fe6955c5e149
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 0/30^H^H^H^H^H ^H^H^H^H^Hdone $
Writing inode tables: 0/30^H^H^H^H^H ^H^H^H^H^Hdone $
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: 0/30^H^H^H^H^H $
SUCCESS, SC_Card is mounted now. Deleting temporary directory ...
skipping directory fake_sda1