{"id":470,"date":"2015-02-18T13:44:23","date_gmt":"2015-02-18T19:44:23","guid":{"rendered":"https:\/\/www.ppsstudios.com\/blog\/?p=470"},"modified":"2018-08-07T11:09:00","modified_gmt":"2018-08-07T17:09:00","slug":"linux-find-what-is-preventing-you-from","status":"publish","type":"post","link":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/","title":{"rendered":"Linux &#8211; Find what is Preventing You from Unmounting a Drive"},"content":{"rendered":"<p><i>Disclaimer: I&#8217;ve had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I need to reboot.<\/i><\/p>\n<p>So you&#8217;ve gone through the process of mounting your drive in Linux:<\/p>\n<pre class=\"lang:sh decode:true\">&gt; sudo fdisk -l\r\nDevice Boot = \/dev\/sdb1 (and a bunch of other technical information regarding drive size, id, and such)\r\n&gt;\r\n&gt; sudo mount -t ntfs-3g \/dev\/sdb1 \/media\/TOSHIBA\r\n&gt;<\/pre>\n<p>You run a bunch of stuff, get it all working, then find you need to take the drive to work the next day, so you try to unmount it.<\/p>\n<pre class=\"lang:sh decode:true\">&gt; sudo umount \/media\/TOSHIBA\r\numount: \/media\/TOSHIBA: device is busy.\r\n(In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))\r\n&gt;\r\n<\/pre>\n<p><!--more--><\/p>\n<p>Well, being a Windows guy at heart, and not really understanding why everything here needs to be so technical, this message never told me ANYTHING. I would try typing just plain &#8220;lsof&#8221; or &#8220;lsof(8)&#8221; or &#8220;fuser(1)&#8221; with no useful results.<\/p>\n<p>Then I asked a friend.<\/p>\n<p>&#8220;<span class=\"lang:sh decode:true crayon-inline \">lsof\u00a0| grep &lt;stuff&gt;<\/span>\u00a0,&#8221; he said.<\/p>\n<p>&#8220;Like,\u00a0<span class=\"lang:sh decode:true crayon-inline \">&lt;stuff&gt;<\/span>\u00a0 would be the <span class=\"lang:sh decode:true crayon-inline \">\/dev\/sdb1<\/span>\u00a0?&#8221;<\/p>\n<p>&#8220;Yeah.&#8221;<\/p>\n<p>So I tried it:<\/p>\n<pre class=\"lang:sh decode:true\">&gt; sudo lsof | grep \/dev\/sdb1\r\nmount.ntf\u00a0\u00a0\u00a0\u00a0 2096\u00a0\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0 3u\u00a0\u00a0\u00a0\u00a0 BLK\u00a0\u00a0\u00a0 8,33 0x1d1ba997e00\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2897182\u00a0\u00a0 \/dev\/sdb1<\/pre>\n<p>&#8220;Oh,&#8221; he said. &#8220;Try the mount path.\u00a0<span class=\"lang:sh decode:true crayon-inline \">\/dev\/sdb1<\/span>\u00a0 is the device which is mounted somewhere else.&#8221;<\/p>\n<pre class=\"lang:sh decode:true\">&gt; sudo lsof | grep \/media\/TOSHIBA\r\n&gt;<\/pre>\n<p>&#8220;Nothing,&#8221; I said. &#8220;Just a blank line.&#8221;<\/p>\n<p>&#8220;Looks like no program has any file open on it?&#8221;<\/p>\n<p>&#8220;Let me try again.&#8221;<\/p>\n<pre class=\"lang:sh decode:true\">bash\u00a0\u00a0\u00a0\u00a0 2068\u00a0\u00a0\u00a0\u00a0 daniel\u00a0\u00a0\u00a0 cwd\u00a0\u00a0\u00a0 DIR\u00a0\u00a0\u00a0 8,33\u00a0\u00a0\u00a0\u00a0 8192\u00a0\u00a0\u00a0 17459\u00a0 \/media\/TOSHIBA\r\ngrep \u00a0\u00a0\u00a0 2254\u00a0\u00a0\u00a0\u00a0 root \u00a0\u00a0 \u00a0\u00a0 cwd\u00a0\u00a0\u00a0 DIR\u00a0\u00a0\u00a0 8,33\u00a0\u00a0\u00a0\u00a0 8192\u00a0\u00a0\u00a0\u00a0 17459\u00a0 \/media\/TOSHIBA\r\nlsof \u00a0\u00a0\u00a0 2255\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cwd\u00a0\u00a0\u00a0 DIR\u00a0\u00a0\u00a0 8,33\u00a0\u00a0\u00a0\u00a0 8192\u00a0\u00a0\u00a0\u00a0 17459\u00a0 \/media\/TOSHIBA<\/pre>\n<p>&#8220;Ahh&#8230;It may have been because I was still cd&#8217;d into it.&#8221;<\/p>\n<p>&#8220;Yes!&#8221;<\/p>\n<p>So lessons learned:<\/p>\n<ul>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Grep\" target=\"_blank\" rel=\"noopener\">grep<\/a>, no matter how weird and complicated it looks with all those pipes and stuff, is still VERY useful.<\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Lsof\" target=\"_blank\" rel=\"noopener\">lsof<\/a>\u00a0is the command of choice for figuring this out.<\/li>\n<li>Use the mount point rather than the drive itself when searcing the lsof output text.<\/li>\n<li>Even just navigating into a drive will lock it from being unmounted &#8211; it&#8217;s not like in Windows where if you &#8220;Safely Remove Hardware&#8221; or yank the USB cable, the computer conveniently closes the explorer window for you.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Disclaimer: I&#8217;ve had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[174],"tags":[466,464,371,463,465,469,467,468,462],"class_list":["post-470","post","type-post","status-publish","format-standard","hentry","category-computer","tag-bash","tag-drive","tag-linux","tag-mount","tag-processes","tag-script","tag-sh","tag-shell","tag-umount"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios\" \/>\n<meta property=\"og:description\" content=\"Disclaimer: I&#8217;ve had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\" \/>\n<meta property=\"og:site_name\" content=\"PPSStudios\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-18T19:44:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-08-07T17:09:00+00:00\" \/>\n<meta name=\"author\" content=\"Daniel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\"},\"author\":{\"name\":\"Daniel\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888\"},\"headline\":\"Linux &#8211; Find what is Preventing You from Unmounting a Drive\",\"datePublished\":\"2015-02-18T19:44:23+00:00\",\"dateModified\":\"2018-08-07T17:09:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\"},\"wordCount\":316,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888\"},\"keywords\":[\"bash\",\"drive\",\"linux\",\"mount\",\"processes\",\"script\",\"sh\",\"shell\",\"umount\"],\"articleSection\":[\"Computer\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\",\"url\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\",\"name\":\"Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios\",\"isPartOf\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#website\"},\"datePublished\":\"2015-02-18T19:44:23+00:00\",\"dateModified\":\"2018-08-07T17:09:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ppsstudios.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux &#8211; Find what is Preventing You from Unmounting a Drive\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#website\",\"url\":\"https:\/\/www.ppsstudios.com\/blog\/\",\"name\":\"PPSStudios\",\"description\":\"Formerly \u10d3\u10d0\u10dc\u10d8\u10d4\u10da\u10d8 \u10de\u10d0\u10d5\u10da\u10d8\u10d0\u10e8\u10d5\u10d8\u10da\u10d8\",\"publisher\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ppsstudios.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888\",\"name\":\"Daniel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3a47193e75f82b6ce5dc02478226e41676f8c8cfbb40d962f0ddff8d18e9e3e1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3a47193e75f82b6ce5dc02478226e41676f8c8cfbb40d962f0ddff8d18e9e3e1?s=96&d=mm&r=g\",\"caption\":\"Daniel\"},\"logo\":{\"@id\":\"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.ppsstudios.com\"],\"url\":\"https:\/\/www.ppsstudios.com\/blog\/author\/danipavliashvili\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/","og_locale":"en_US","og_type":"article","og_title":"Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios","og_description":"Disclaimer: I&#8217;ve had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I [&hellip;]","og_url":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/","og_site_name":"PPSStudios","article_published_time":"2015-02-18T19:44:23+00:00","article_modified_time":"2018-08-07T17:09:00+00:00","author":"Daniel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Daniel","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#article","isPartOf":{"@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/"},"author":{"name":"Daniel","@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888"},"headline":"Linux &#8211; Find what is Preventing You from Unmounting a Drive","datePublished":"2015-02-18T19:44:23+00:00","dateModified":"2018-08-07T17:09:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/"},"wordCount":316,"commentCount":0,"publisher":{"@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888"},"keywords":["bash","drive","linux","mount","processes","script","sh","shell","umount"],"articleSection":["Computer"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/","url":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/","name":"Linux - Find what is Preventing You from Unmounting a Drive - PPSStudios","isPartOf":{"@id":"https:\/\/www.ppsstudios.com\/blog\/#website"},"datePublished":"2015-02-18T19:44:23+00:00","dateModified":"2018-08-07T17:09:00+00:00","breadcrumb":{"@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ppsstudios.com\/blog\/2015\/02\/linux-find-what-is-preventing-you-from\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ppsstudios.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux &#8211; Find what is Preventing You from Unmounting a Drive"}]},{"@type":"WebSite","@id":"https:\/\/www.ppsstudios.com\/blog\/#website","url":"https:\/\/www.ppsstudios.com\/blog\/","name":"PPSStudios","description":"Formerly \u10d3\u10d0\u10dc\u10d8\u10d4\u10da\u10d8 \u10de\u10d0\u10d5\u10da\u10d8\u10d0\u10e8\u10d5\u10d8\u10da\u10d8","publisher":{"@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ppsstudios.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/cb11d96049a08f0853830238a95f2888","name":"Daniel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3a47193e75f82b6ce5dc02478226e41676f8c8cfbb40d962f0ddff8d18e9e3e1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3a47193e75f82b6ce5dc02478226e41676f8c8cfbb40d962f0ddff8d18e9e3e1?s=96&d=mm&r=g","caption":"Daniel"},"logo":{"@id":"https:\/\/www.ppsstudios.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.ppsstudios.com"],"url":"https:\/\/www.ppsstudios.com\/blog\/author\/danipavliashvili\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/posts\/470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/comments?post=470"}],"version-history":[{"count":2,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":554,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/posts\/470\/revisions\/554"}],"wp:attachment":[{"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ppsstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}