# Umount -f USB stick resluts in a kernel panic



## Graaf_van_Vlaanderen (Apr 5, 2009)

I followed the guidelines in mounting a USB drive, which are explained in the FreeBSD doc:


```
% mount -t msdosfs -o -m=644,-M=755 /dev/da2s1 /mnt/username
```

I tried everything to umount USB-drive normally but without success and in the end tried a forced umount:

```
# umount -f /mnt/username
```
which resulted in a kernel panic.

Then I retried something different:


```
# mount -t msdosfs /dev/da2s1 /usr/home/username/USB_drive/
```


```
# umount /usr/home/username/USB_drive/
```

This worked fine for at least two machines.
What am I missing that I received a kernel panic?

PS: The kernel panic resulted on a machine on which the kernel had been recompiled for dtrace. In this case the probes were not loaded. (An experiment with dtrace already resulted in a kernel panic.)


----------



## ale (Apr 5, 2009)

Graaf_van_Vlaanderen said:
			
		

> I tried everything to umount USB-drive normally but without success and in the end tried a forced umount:
> 
> ```
> # umount -f /mnt/username
> ...


This is "normal". 
I mean it's a well known behaviour.

Instead of forcing the umount, try to understand which process is blocking it.
Use for example _fstat_ (from the base system) or _lsof_ (from ports).

Let's hope that with all the work about USB that are doing in CURRENT thing will get better.


----------



## Graaf_van_Vlaanderen (Apr 5, 2009)

Thanks for the feedback. I often use the 'umount -f' in Solaris.
But indeed it's better to take a little bit more time to investigate what is blocking from doing a proper umount.

I suspect that mounting something on /mnt or the overwhelmingly options in FreeBSD doc might block a proper umount.


----------



## ale (Apr 5, 2009)

Graaf_van_Vlaanderen said:
			
		

> I suspect that mounting something on /mnt or the overwhelmingly options in FreeBSD doc might block a proper umount.


No, it's not about the mount point or the options, it's a process holding opened files.


----------



## DutchDaemon (Apr 5, 2009)

You're not trying to umount from within the mount, are you?


----------



## Graaf_van_Vlaanderen (Apr 5, 2009)

DutchDaemon said:
			
		

> You're not trying to umount from within the mount, are you?



No certainly not.
I knew from before that 'umount -f' involves a certain amount of risk, however I was completely surprised that it generated a kernel panic.

I'm also a little bit disappointed with the FreeBSD documentation on this topic,
since every step I followed (including the creation of the directory under /mnt) resulted in an unmountable situation.

The documentation is somewhat contradictory:

As an example it mounts a USB device under /mnt, while according to the FreeBSD hier it should be mounted under /media.
The example in the FreeBSD doc shows how to mount the stick, but doesn't mention how to umount this same stick.

By the way, are there any tools to examine this core dump generated by this kernel panic?


----------



## ale (Apr 5, 2009)

Graaf_van_Vlaanderen said:
			
		

> By the way, are there any tools to examine this core dump generated by this kernel panic?


Sure, start from here http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/kerneldebug.html.
Anyway I wouldn't waste my time on that as it's a well known problem.


----------



## ale (Apr 5, 2009)

Graaf_van_Vlaanderen said:
			
		

> I'm also a little bit disappointed with the FreeBSD documentation on this topic,
> since every step I followed (including the creation of the directory under /mnt) resulted in an unmountable situation.


Can you exemplify that?



			
				Graaf_van_Vlaanderen said:
			
		

> The documentation is somewhat contradictory:
> 
> As an example it mounts a USB device under /mnt, while according to the FreeBSD hier it should be mounted under /media.


You can mount devices wherever you want with some limitations (own the mount point,...)



			
				Graaf_van_Vlaanderen said:
			
		

> The example in the FreeBSD doc shows how to mount the stick, but doesn't mention how to umount this same stick.


The chapter about usb devices tells that "_the disk must be unmounted before_" unplugging the device, and it should be done like with every other device, like described here http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/book.html#DISKS-UMOUNT


----------



## Graaf_van_Vlaanderen (Apr 6, 2009)

ale said:
			
		

> Can you exemplify that?



Well, I just followed the guidelines described in the doc.
At a certain moment I thought the USB-stick was properly umounted
after 
	
	



```
# umount -a -t msdosfs
```
 since the terminal did not return anything anymore. However I still could access the USB-stick. That's why I ended up using a forced umount.



			
				ale said:
			
		

> You can mount devices wherever you want with some limitations (own the mount point,...)


Sure, that's in the end what I also did when mounting under my user account, like described in my first post. It would just look nicer for the doc if it would use /media instead of /mnt.



			
				ale said:
			
		

> The chapter about usb devices tells that "_the disk must be unmounted before_" unplugging the device, and it should be done like with every other device, like described here http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/book.html#DISKS-UMOUNT



Of course, what is otherwise the point of the umount command?


----------



## lme@ (Apr 6, 2009)

Which Version of FreeBSD are you running?
trasz@ MFCed some patches that should prevent panics on unmounting.
You need 7-STABLE or better (for removing umass devices) CURRENT.


----------



## iic2 (Apr 6, 2009)

mount_msdosfs /dev/da0s1 /b

umount /dev/da0s1

Works everytime and with freeBSD 7.1 stable you don't even have to umount.


----------



## lme@ (Apr 6, 2009)

Just a note: mount_* is deprecated, please use mount -t fstype.


----------



## phoenix (Apr 6, 2009)

Graaf_van_Vlaanderen said:
			
		

> The documentation is somewhat contradictory:



Including a link to which document(s) you are talking about would be very useful.  It's hard to check the docs, and possibly submit PRs to improve them, if we don't know which doc(s) you are talking about.


----------



## Graaf_van_Vlaanderen (Apr 6, 2009)

phoenix_rizzen said:
			
		

> Including a link to which document(s) you are talking about would be very useful.  It's hard to check the docs, and possibly submit PRs to improve them, if we don't know which doc(s) you are talking about.



http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/usb-disks.html

-> Paragraph 18.5: USB storage devices
The "final step" of paragraph 18.5.2


----------



## phoenix (Apr 7, 2009)

There's nothing in there that contradicts hier(7).  hier(7) mentions that /media can be used to create sub-directories for removable media, but that /mnt can also be used for temporary mount points (like would be used for removable media).

All of my FreeBSD systems (4.4 through 7.1) have empty /mnt and /media directories, and most don't even have a /media directory.

Note also the use of "[o]ne way to do that is for root to create a subdirectory owned by that user as /mnt/username".  It's not saying that's the only way, that it's carved in stone, and that your house will burn down if you decide to use /media instead.  

Personally, I prefer to use mount points within the user's directory for temporary mount points.  Keeps the permissions simpler, especially on multi-user setups.


----------



## Graaf_van_Vlaanderen (Apr 7, 2009)

phoenix_rizzen said:
			
		

> Personally, I prefer to use mount points within the user's directory for temporary mount points.  Keeps the permissions simpler, especially on multi-user setups.



Which is what I additionally posted in my first post and indeed works fine.


----------

