Mount USB device on router - OpenWrt - linux

I am new to OpenWrt and Linux/Unix shell. Prior to this, was using dd-wrt for 2 years. Recently switched to OpenWrt and got the basic setup done(wifi/internet working). I need to install transmission my router. But, USB device won't mount.
The Details of the router are as follows:
Router Model:
Asus RT-N13U B1
Image flashed:
chaos_calmer 15.05.1 (openwrt-15.05.1-ramips-rt305x-rt-n13u-squashfs-sysupgrade.bin)
Usb Details:
Crusier Blade 16GB usb 2.0
Formatted to ext4 using GParted bootable cd
Drivers Installed:
kmod-usb-core(preinstalled)
kmod-usb-dwc2(preinstalled)
kmod-usb2
kmod-usb-storage
kmod-fs-ext4
kmod-scsi-core(preinstalled)
Here are permissions for dev/sda, /dev/sda1 and /mnt (set 777 manually):
~#ls -l /dev
brwxrwxrwx 1 root root 8, 0 Jan 17 21:56 sda
brwxrwxrwx 1 root root 8, 1 Jan 17 21:56 sda1
~#ls -l ..
drwxrwxrwx 2 root root 0 Jan 16 21:28 mnt
Error while mounting:
~# mount -t ext4 /dev/sda1 /mnt
mount: mounting /dev/sda1 on /mnt failed: No such file or directory
echo $?
255
sda1 is present inside dev and /mnt directory exists. Still it shows an error.
I have tried installing/reinstalling and then mounting, but for the same result. Also when I disconnect the USB sda and sda1 folders disappear and then reappear when USB is reconnected so I guess the device is being detected successfully.
What is it, that I am missing?
Edit:
Added edits as suggested in the comments.
dmesg output (The output is very big so linked it)
Edit 2:
Switched to LEDE 17. Is more stable and have had zero issues in the past week.

the critical part of the dmesg output is
[ 9.410000] mount_root: loading kmods from internal overlay
[ 9.940000] SCSI subsystem initialized
[ 9.960000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 9.980000] ehci-platform:EHCI generic platform driver [ 9.990000] usb-storage 1-1:1.0: no of_node; not parsing pinctrl DT
[ 9.990000] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 10.010000] scsi host0: usb-storage 1-1:1.0
[ 10.020000] usbcore: registered new interface driver usb-storage
[ 10.100000] block: attempting to load /tmp/jffs_cfg/upper/etc/config/fstab
[ 10.120000] block: extroot: not configured
[ 10.130000] mount_root: switching to jffs2 overlay
[ 10.180000] procd: - early -
[ 11.020000] scsi 0:0:0:0: Direct-Access SanDisk Cruzer Blade 1.27 PQ: 0 ANSI: 6
[ 11.030000] sd 0:0:0:0: no of_node; not parsing pinctrl DT
[ 11.050000] sd 0:0:0:0: [sda] 30529536 512-byte logical blocks: (15.6 GB/14.5 GiB)
[ 11.070000] sd 0:0:0:0: [sda] Write Protect is off
[ 11.070000] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[ 11.090000] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 11.120000] sda: sda1
[ 11.130000] sd 0:0:0:0: [sda] Attached SCSI removable disk
[ 11.550000] EXT4-fs (sda1): Cannot load crc32c driver
oh no, this seems to be a bug
Bug#819725: ext4 missing softdep on crc32c module
https://lists.debian.org/debian-kernel/2016/04/msg00013.html
the following workaround is not applicable because initramfs is a native file system at startup time (https://en.wikipedia.org/wiki/Initramfs) and has no influence when the system is fully up (rootfs is mounted):
Until this is fixed in the kernel package, you can work around it by
either:
Setting base-installer/initramfs-tools/driver-policy to "most" instead of "dep"
Setting base-config/late_command to a script that adds crc32c to /etc/initramfs-tools/modules
post the stack trace anyway, maybe there is another workaround
this is overcomplicated stuff...
here is maybe a solution https://forum.openwrt.org/viewtopic.php?id=69175
download kmod-lib-crc32c and kmod-crypto-crc32c
if this is not working maybe the easiest solution is to format the USB stack as VFAT and to wait for a new kernel...
this is not a permissions error. a permission error would return EPERM -> error code 1 Operation not permitted
it would be interesting to know what exit code the mount returns. The 'exit behavior is very different in the several mount version' i.e. mount(2) and mount(8)
for getting the return value, type in a shell the command
mount /dev/sda1 /mnt
then
echo $?
the number is the returned exit code of the mount (the 255 means 'exit status out of range' in this case '-1', http://www.tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF)
a listing of the mount(8) exit codes is i.e. in http://www.stackoverflow.com/questions/33167585/what-are-the-return-codes-values-of-linux-umount
http://www.becane.com/2014/09/02/understanding-exit-codes-and-how-to-use-them-in-a-bash-script
beside the return value mount(2) also sets an error code in errno (http://man7.org/linux/man-pages/man3/errno.3.html). printing errno in shell is a bit difficult it is easier to get a reference like http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html and search for the error string, in this case No such file or directory
the string No such file or directory is system error ENOENT
As a system error ENOENT means A pathname was empty or had a nonexistent component. (http://man7.org/linux/man-pages/man2/mount.2.html)
try sudo mount -t ext4 /dev/sda1 /mnt because the stick is formatted in ext4
if this is not working dmesg output would be interesting
detach usb device, reattach usb device, type dmesg and see the output. in the output of dmesg you also see which drivers are loaded for the device
https://wiki.openwrt.org/doc/howto/usb.storage says that you need several more drivers (block-mount, kmod-scsi-core,...) because a usb stick (USB Mass Storage class) is also a SCSI and a block device...
(linux system error codes are in http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html)
print a stack trace sudo strace -f mount -t ext4 -o default /dev/sda1 /mnt and post it

Related

Kernel Panic with ramfs on embedded device: No filesystem could mount root

I'm working on an embedded ARM device running Linux (kernel 3.10), with NAND memory for storage. I'm trying to build a minimal linux which will reside on its own partition and carry out updates of the main firmware.
The kernel uses a very minimal root fs which is stored in a ramfs. However, I can't get it to boot. I get the following error:
[ 0.794113] List of all partitions:
[ 0.797600] 1f00 128 mtdblock0 (driver?)
[ 0.802669] 1f01 1280 mtdblock1 (driver?)
[ 0.807697] 1f02 1280 mtdblock2 (driver?)
[ 0.812735] 1f03 8192 mtdblock3 (driver?)
[ 0.817761] 1f04 8192 mtdblock4 (driver?)
[ 0.822794] 1f05 8192 mtdblock5 (driver?)
[ 0.827820] 1f06 82944 mtdblock6 (driver?)
[ 0.832850] 1f07 82944 mtdblock7 (driver?)
[ 0.837876] 1f08 12288 mtdblock8 (driver?)
[ 0.842906] 1f09 49152 mtdblock9 (driver?)
[ 0.847928] No filesystem could mount root, tried: squashfs
[ 0.853569] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
[ 0.861806] CPU: 0 PID: 1 Comm: swapper Not tainted 3.10.73 #11
[ 0.867732] [<800133ec>] (unwind_backtrace+0x0/0x12c) from [<80011a50>] (show_stack+0x10/0x14)
(...etc)
The root fs is built by the build process, using the following (simplified for clarity):
# [Copy some things to $(ROOTFS_OUT_DIR)/mini_rootfs]
cd $(ROOTFS_OUT_DIR)/mini_rootfs && find . | cpio --quiet -o -H newc > $(ROOTFS_OUT_DIR)/backup.cpio
gzip -f -9 $(ROOTFS_OUT_DIR)/backup.cpio
This creates $(ROOTFS_OUT_DIR)/backup.cpio.gz
The kernel is then built like this:
#$(MAKE) -C $(LINUX_SRC_DIR) O=$(LINUX_OUT_DIR) \
CONFIG_INITRAMFS_SOURCE="$(ROOTFS_OUT_DIR)/backup.cpio.gz" \
CONFIG_INITRAMFS_ROOT_UID=0 CONFIG_INITRAMFS_ROOT_GID=0
I think this means it uses the same config as the main firmware (built elsewhere), but supplies the minimal ramfs image using CONFIG_INITRAMFS_SOURCE.
From Kernel.Org, the ramfs is always built anyway, and CONFIG_INITRAMFS_SOURCE is all that is needed to specify a pre-made root fs to use. There are no build errors to indicate that there is a problem creating the ramfs, and the size of the resulting kernel looks about right. backup.cpio.gz is about 3.6 MB; the final zImage is 6.1 MB; the image is written to a partition which is 8 MB in size.
To use this image, I set some flags used by the (custom) boot loader which tell it to boot from the minimal partition, and also set a different command line for the kernel. Here is the command line used to boot:
console=ttyS0 rootfs=ramfs root=/dev/ram rw rdinit=/linuxrc mem=220M
Note that the nimimal root fs contains "/linuxrc", which is actually a link to /bin/busybox:
lrwxrwxrwx 1 root root 11 Nov 5 2015 linuxrc -> bin/busybox
Why doesn't this boot? Why is it trying "squashfs" filesystem, and is this wrong?
SOLVED! It turned out that a file name used by the (custom) build system had changed as part of an update, and so it was not putting the correct kernel image into the firmware package. I was actually trying to boot the wrong kernel with the "rootfs=ramfs" parameter, one which didn't have a ramfs.
So, for future reference, this error occurs if you specify "rootfs=ramfs" but your kernel wasn't built with any rootfs built in (CONFIG_INITRAMFS_SOURCE=... NOT specified)

sd card data broken after umount

I wrote an SD host-controller Linux driver for a totally customized board, using IP TE4395.
With the driver I wrote,
I can mount an SD card, read and write.
when mounted, once I umount, the next mount will fail.
command mount -o remount /dev/mmcblk0p1 worked normally....
# ls /mnt/
aaa.txt lost+found
# mount -o remount /dev/mmcblk0p1
EXT4-fs (mmcblk0p1): re-mounted. Opts: block_validity,delalloc,barrier,user_xattr,acl
# echo adfaf >/mnt/bbb.txt
# ls /mnt/
aaa.txt bbb.txt lost+found
# cat /mnt/bbb.txt
adfaf
# sync
# ls /mnt/
aaa.txt bbb.txt lost+found
# umount /mnt/
# mount /dev/mmcblk0p1 /mnt
mount: mounting /dev/mmcblk0p1 on /mnt failed: Invalid argument
I know the reason.
the driver has a problem. I added some code for debug, that read register when driver write registers.
And the Data Port register is special, when access the register the buffer pointer inside the controller will be incremented automatically.
The debug code read before and after write to the register, so accessed the register 3 times, but expected just 1 time access(write).

showing the name of the hard disk devices using grep

Why does this command:
[jalal#galapagos-20] (42)$ dmesg | egrep '(s|h)d[a-z]'
Shows the following? Can you please show step by step?
ACPI: SSDT 00000000d8ffbbd8 03528 (v01 SaSsdt SaSsdt 00003000 INTL 20091112)
NMI watchdog enabled, takes one hw-pmu counter.
sd 0:0:0:0: [sda] 500118192 512-byte logical blocks: (256 GB/238 GiB)
sd 0:0:0:0: [sda] 4096-byte physical blocks
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7
sd 0:0:0:0: [sda] Attached SCSI disk
EXT4-fs (sda3): mounted filesystem with ordered data mode. Opts:
dracut: Mounted root filesystem /dev/sda3
snd_hda_intel 0000:00:03.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
snd_hda_intel 0000:00:03.0: irq 33 for MSI/MSI-X
snd_hda_intel 0000:00:03.0: setting latency timer to 64
snd_hda_intel 0000:00:1b.0: PCI INT A -> GSI 22 (level, low) -> IRQ 22
snd_hda_intel 0000:00:1b.0: irq 34 for MSI/MSI-X
snd_hda_intel 0000:00:1b.0: setting latency timer to 64
sound hdaudioC1D2: autoconfig for ALC3220: line_outs=1 (0x1b/0x0/0x0/0x0/0x0) type:line
sound hdaudioC1D2: speaker_outs=1 (0x14/0x0/0x0/0x0/0x0)
sound hdaudioC1D2: hp_outs=1 (0x15/0x0/0x0/0x0/0x0)
sound hdaudioC1D2: mono: mono_out=0x0
sound hdaudioC1D2: inputs:
sound hdaudioC1D2: Front Mic=0x1a
sound hdaudioC1D2: Rear Mic=0x18
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda7): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda4): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda6): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda5): mounted filesystem with ordered data mode. Opts:
Adding 67108860k swap on /dev/sda2. Priority:-1 extents:1 across:67108860k SS
snd_hda_intel 0000:00:1b.0: IRQ timing workaround is activated for card #1. Suggest a bigger bdl_pos_adj.
The command dmesg dumps the kernel log buffer to stdout. This output consists of a bunch of log messages, each on a separate line.
That output is piped to the command egrep with the option (s|h)d[a-z]. egrep checks its stdin (the output of dmesg) one line at a time for a match against the regular expression (s|h)d[a-z]. This regular expression will match a series of characters where:
The first character is s or h
The second character is d
The third character is in the ASCII range (inclusive) between a and z (the lowercase letters a to z).
egrep prints to stdout any lines which match the supplied regular expression.
The egrep command is using the regular expression (s|h)d[a-z] for filtering lines containing the sequences hda to hdz and sda to sdz on the output of dmesg - traditional names for disk devices in Linux.
This regular expression could be switched to [sh]d[a-z], which has the same effect but you may find easier to understand.
There are several false positives if you are looking for disks, like the lines containing "hdaudio".

error when changing mount location for external hdd

I will admit this might be a bit complicated and maybe not the best method so if you have a better solution let me know...
I have a 'server' that I put lubuntu 14.4 on. I am attempting to attach an external hdd formatted to ext3 to the folder /home/external so that my ftp users are able to get to the files on it without leaving the /home directory (to which I have them 'chained' / chrooted).
The hdd will mount just fine (no errors) with the automatic mount options. but every time I try to change the mount point to something other than /media//external I get:
Error mounting system-managed device /dev/sdd1: Command-line `mount "/mnt/
external"' exited with non-zero exit status 32: mount: wrong fs type, bad option,
bad superblock on /dev/sdd1
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
(udisks-error-quark, 0)
As far as I can tell it does not matter where I try to mount it even tried /mnt/external with same results.
Output of dmesg | tail (before mount changes):
sd 6:0:0:0: [sdd] Write Protect is off
sd 6:0:0:0: [sdd] Mode Sense: 23 00 00 00
sd 6:0:0:0: [sdd] No Caching mode page found
sd 6:0:0:0: [sdd] Assuming drive cache: write through
sdd: sdd1
sd 6:0:0:0: [sdd] Attached SCSI disk
EXT4-fs (sdd1): mounting ext3 file system using the ext4 subsystem
EXT4-fs (sdd1): mounted filesystem with ordered data mode. Opts: (null)
Output of dmesg | tail (after mount changes):
sd 6:0:0:0: [sdd] Mode Sense: 23 00 00 00
sd 6:0:0:0: [sdd] No Caching mode page found
sd 6:0:0:0: [sdd] Assuming drive cache: write through
sdd: sdd1
sd 6:0:0:0: [sdd] Attached SCSI disk
EXT4-fs (sdd1): mounting ext3 file system using the ext4 subsystem
EXT4-fs (sdd1): mounted filesystem with ordered data mode. Opts: (null)
EXT4-fs (sdd1): Unrecognized mount option "x-gvfs-show" or missing value
Just to be sure, did you actually unmount the block device in question before you tried to mount it on a different location?
Problem fixed: I was using the disks GUI to change the mount options because I didn't want to screw up my fstab.conf file. For some reason when I check 'Show in user interface' it only adds x-gvfs-show instad of comment=x-gvfs-show (which is apparently the correct syntax for that option). Having manually added the 'comment=' I can say the problem is resolved.

Very low performance of g_mass_storage virtual usb device

Hello I am using Linux usb gadget facility to emulate a USB flash drive. It is working fine except for very low performance.
I use a 4Gb file, created by dd and created a ext2 or vfat (tried both) partition on it. Than I mount it using the following command sequence:
# modprobe dummy_hcd is_super_speed=1 # I tried is_high_speed=1, and no parameter too
# modprobe g_mass_storage file=/home/del/img/flash stall=0 # tried w/o stall=0 too
# mount /dev/sdc1 /mnt/tmp
After that I get /dev/sdc and /dev/sdc1 devices created without any errors in dmesg:
[1256700.986581] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256701.022551] gadget: high-speed config #1: Linux File-Backed Storage
[1256701.242481] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256701.278422] gadget: high-speed config #1: Linux File-Backed Storage
[1256701.422339] gadget: high-speed config #1: Linux File-Backed Storage
[1256934.915697] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256934.951628] gadget: high-speed config #1: Linux File-Backed Storage
[1256935.915155] usb 3-1: reset high-speed USB device number 5 using dummy_hcd
[1256935.951090] gadget: high-speed config #1: Linux File-Backed Storage
[1256936.095018] gadget: high-speed config #1: Linux File-Backed Storage
[1317073.396892] usb-storage 3-1:1.0: Quirks match for vid 0525 pid a4a5: 10000
[1317073.396995] scsi53 : usb-storage 3-1:1.0
[1317074.411883] scsi 53:0:0:0: Direct-Access Linux File-CD Gadget 0302 PQ: 0 ANSI: 2
[1317074.412669] sd 53:0:0:0: Attached scsi generic sg3 type 0
[1317074.431910] sd 53:0:0:0: [sdc] 8388608 512-byte logical blocks: (4.29 GB/4.00 GiB)
[1317074.443816] sd 53:0:0:0: [sdc] Write Protect is off
[1317074.443821] sd 53:0:0:0: [sdc] Mode Sense: 0f 00 00 00
[1317074.455839] sd 53:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[1317074.551757] sdc: sdc1
[1317074.683704] sd 53:0:0:0: [sdc] Attached SCSI removable disk
The problem is that IO performance is very poor. Writing 200Mb file takes quite a while:
$ ls -lh file
-rw-rw-r-- 1 root del 206M Sep 4 09:34 file
$ time sudo cp file /mnt/tmp/
real 11m59.618s
user 0m0.000s
sys 0m0.260s
Which is about 300K/sec. However the same file on the same system is copied to a real USB flash in less than a minute.
Iotop shows something like this:
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
9986 be/4 root 0.00 B/s 262.05 K/s 0.00 % 99.86 % cp file /mnt/tmp/
20651 be/4 root 51.77 K/s 238.95 K/s 0.00 % 93.23 % [file-storage]
Can anything be done to improve the performance of g_mass_storage-emulated USB drive?
PS: I am using kernel
$ uname -rm
3.2.0-4-686-pae i686
Same here.
After one night at 6:00 i had a solution for me.
modprobe g_mass_storage file=/home/del/img/flash stall=0 buflen=65536
This made up to 5MByte/sec
modprobe g_mass_storage file=/home/del/img/flash stall=0 nofua=1
This made up to 11MByte/sec
A combination of "buflen" and "nofua" did not really helped.
About "nufua" read here: http://lxr.free-electrons.com/source/drivers/usb/gadget/file_storage.c?v=3.5
Ultrasoft /

Resources