# USB drive causes kernel panics--sometimes

## virduun

I have an issue where plugging in my 8GB flash drive will often cause a kernel panic, forcing me to reboot.  Now, it doesn't happen every time.  I also have a 1GB drive, and I've noticed that the 8GB drive will sometimes work properly after I've previously mounted the 1GB drive.  However, sometimes the 8GB drive is picky about which port it's plugged into.  I have had it work in both frontside USB ports, but most of the time it seems to really prefer one of them.  The 1GB drive seems to always work.  I also have an external hard drive which I haven't tested yet.

Now, the 8GB drive is a SanDisk, but I'm pretty sure I cleaned that U3 crap off of it with the uninstaller, so theoretically that shouldn't be an issue (the 1GB drive is an LG, if that matters), and it is formatted in FAT32.

I did try to read some of the messages on the screen when I plugged in the 8GB and it seems to find the drive just fine, then starts setting up sdb, which is where USB drives seem to get placed on my system, but then at some point it gets a message that says "kernel panic - not syncing: fatal exception in interrupt".

I'm completely at a loss to even begin trying to figure out what is causing that strange behavior, and I'm kind of a new user.  I have a friend who's been using Gentoo for several years, but he's similarly stumped.  Any help would be appreciated. Thanks.  :Smile: 

----------

## Otamay

May I see the output of `fdisk -l /deb/sdb`?  =O

----------

## virduun

Actually, I don't normally have a sdb in /dev.  It seems to get created when I insert a USB device.

Edit: Sorry for the late reply.  I got sort of sidetracked last night.

Edit 2: In the event you wanted that done after mounting a drive, here's the output of that with the 1G mounted.  I tried to do it with both drives mounted, but the 8G didn't feel like working and i had to reboot (didn't see any text explicitly talking about kernel panic this time though--some stuff concerning scsi though...don't know if that means anything; just noting it in case it might):

Disk /dev/sdb: 1043 MB, 1043333120 bytes

64 heads, 32 sectors/track, 995 cylinders, total 2037760 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1   *          32     2037758     1018863+   c  W95 FAT32 (LBA)

Edit 3: Ok, after taking care of the output for the 1G drive, I decided to try if the 8G felt like working, and it did this time.  I put it in the other front port though, because that seems to increase the odds of it working:

Disk /dev/sdb: 8065 MB, 8065646080 bytes

8 heads, 32 sectors/track, 61535 cylinders, total 15753215 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1   *          32    15753214     7876591+   b  W95 FAT32

Edit 4: Attempting to put the 1G drive in with the 8G mounted just now caused a panic, with standard "not syncing: fatal exception in interrupt" language, forcing a reset.

----------

## TomCat1

I have the same problem. After plugging USB flash disc (tried two), I got kernel panic.

----------

## kurisu

Same here. I quite often experience this issue on various machines when attempting to hotplug external usb devices (hard disks in my case). No solution here yet either, however, this has never been occuring before upgrading to kernel versions >2.6.36 (currently running sys-kernel/gentoo-sources-2.6.38-r6 on all machines). Any suggestions?

----------

## kurisu

I have just read this bug report https://bugs.gentoo.org/show_bug.cgi?id=369061. Upgrading to sys-kernel/gentoo-sources-2.6.38-r7 seems to have fixed it for me.

----------

## virduun

I'm using 2.6.39-r1, and was using 2.6.39 when I originally started the thread.  Is there some kind of configuration in the kernel I should look into which might cause this issue if I misconfigured it?

@TomCat1

There's another thread discussing a similar issue here as well: https://forums.gentoo.org/viewtopic-t-882390.html  Kind of interesting that many of the people in that thread (including myself) have ASUS motherboards.

----------

## TomCat1

Now I have 2.6.39-gentoo-r1 and still have the problem.

I have Phenom 9950 on Gigabyte GA-MA790GP-DS4H, BIOS F7i 12/24/2010.

----------

## daddio

I'm also experiencing this issue.

In my case its an Archos media player and a 4GB usb pen drive that trigger the kernel panic.

I'm wondering how (if at all) it is possible to keep the output of dmesg from the panic?

Or is it not recorded anywhere since the kernel is in the process of wedging itself as it prints out...

I guess I could use a digital camera to capture it if need be.

[UPDATE]

I found that others had submitted the same problem on the LKML. 

It seems to affect only amd64 systems with certain motherboards... or something.

Anyway, I was all set to do a git-bisect. Went to all the trouble to clone the mainline kernel repository... buty I thought I ought to compile the latest git kernel just in case it is already fixed.

I copied my .config from 2.6.39, and compiled. it comes out as 3.0.0-rc3+, and the panic problem (which for me was quite reproducable... boot into kde, plug in the Archos, select "mount" in the archos, and boom! panic) is now gone.

I have no idea when this will make its way downstream. and I'm too lazy to git-bisect just to find out when it was fixed.

----------

## colo-des

I've solved it by applying this patch:

https://patchwork.kernel.org/patch/487421/

I leave the link to my comment I made in: https://bugs.gentoo.org

https://bugs.gentoo.org/show_bug.cgi?id=369061#c13

Greetings

----------

## colo-des

Well, it seems that after using it a while, the problem returned 

then I started looking for another patch has come out and meet me 

with this set of patches:

http://kernel.org/pub/linux/kernel/v2.6/stable-review/patch-2.6.39.2-rc1.gz

Then apply the changes to two files scsi_scan.c scsi_sysfs.c

and now I can say I made a thousand proofs of connecting and disconnecting 

USB sticks and so far I have not had more kernel panic.

https://bugs.gentoo.org/show_bug.cgi?id=369061#c14

Greetings

----------

## virduun

Do you mean apply the 2.6.39.2.-rc1 patch and then edit those files, or do you mean that it's enough to just edit those files in the current kernel version? For reference, I'm using 2.6.39-r1.  I looked at the patch file you linked and the lines you talk about adding in scsi_scan.c and scsi_sysfs.c in the buglist comment show up in the diffs.  Sorry, I'm kind of new and just asking for a bit of clarification.   :Smile: 

----------

## colo-des

Simply edit the two files and then recompile your kernel.

ctrl + w is the nano editor search command.

# nano -w /usr/src/linux-2.6.39-gentoo-r1/drivers/scsi/scsi_scan.c

ctrl+w: sdev->request_queue->queuedata = sdev;

and one line up...

blk_get_queue(sdev->request_queue);

# nano -w /usr/src/linux-2.6.39-gentoo-r1/drivers/scsi/scsi_sysfs.c

ctrl+w: /* NULL queue means the device can't be used */

and one line up...

blk_put_queue(sdev->request_queue);

# nano -w /usr/src/linux-2.6.39-gentoo-r1/drivers/scsi/scsi_sysfs.c

ctrl+w: struct device_attribute dev_attr_hstate =

static struct device_attribute dev_attr_hstate =

ctrl+w: struct attribute_group scsi_shost_attr_group =

static struct attribute_group scsi_shost_attr_group =

Greetings

----------

## virduun

I performed the modifications you indicated and so far the results look promising.  The 8GB flash drive which usually causes issues has worked in both of the front USB ports, and I plugged in the 1GB drive separately and with the 8GB drive also mounted, and that hasn't caused any panics either.  I haven't tried my external hard drive yet, but so far it looks like the fix worked. Thank you!!   :Smile: 

----------

## Kiwon Um

 *colo-des wrote:*   

> Simply edit the two files and then recompile your kernel.
> 
> ctrl + w is the nano editor search command.
> 
> # nano -w /usr/src/linux-2.6.39-gentoo-r1/drivers/scsi/scsi_scan.c
> ...

 

Does this patch work for 2.6.38-r6 (currently gentoo-stable version for amd64) as well?

Thanks.

----------

## colo-des

[/quote]

Does this patch work for 2.6.38-r6 (currently gentoo-stable version for amd64) as well?

Thanks.[/quote]

I have not installed the 2.6.38-r6, but I was comparing the two files of different versions and no change, so it's supposed to work. 

Regards

----------

## Kiwon Um

 *colo-des wrote:*   

> I have not installed the 2.6.38-r6, but I was comparing the two files of different versions and no change, so it's supposed to work. 

 

Thanks for your reply. Since the current stable version of official kernel is 2.6.39, I installed 2.6.39-r1 with the patch you suggested, yesterday. It works fine. I'm just little wondering about stability of the gentoo-test version (~arch). In the previous time, did any serious stability issue exist between test and stable versions?

----------

## virduun

Just as a note, I updated my system recently, which includes kernel version 2.6.39-r2, which does seem to have the fix.  Plugged some USB drives to test it after switching to the new kernel and it seems to be working fine.   :Smile: 

----------

