11.04.2017, 07:38
First, reboot your LM. Since you have tried different scripts your mount table is probably messed up. Second, make sure your flash drive is formatted as FAT or FAT32 (but not exFAT). Run this script once, then go to System Config > Status > System Status. In Partitions tab you should see that /dev/sda1 or similar is mounted under /mnt. Then you can use io.writefile('/mnt/myfile.txt', 'test') to write something onto USB drive.
Code:
devs = io.ls('/sys/class/block/')
table.sort(devs)
for _, dev in ipairs(devs) do
if dev:match('^sd%a%d$') then
part = dev
break
elseif not devn and dev:match('^sd%a$') then
devn = dev
end
end
part = part or devn
if part then
os.execute('umount -f /mnt 2>&-')
res, stat = io.readproc('mount /dev/' .. part .. ' /mnt 2>&1')
if stat == 0 then
alert('USB mount OK')
else
alert('USB mount failed: ' .. tostring(res))
end
else
alert('No valid USB devices found')
end