• 0

Unmount a Device Without Knowing Where It's Mounted


Question

I've written a python script to fill a need at work. We have to wipe hard drives using specific methods and requirements (wiping it multiple times over), and it was easier for me to script it, but I happened upon a question, more for myself. In order for the device to get wiped, it cannot be mounted. So let's say that I tell the script to wipe /dev/sdc , which should kill the whole drive. However, let's say /dev/sdc1 is a partition that is mounted, but there's no way I can predict what it is mounted as. Is it possible to detect where the device is mounted to, if it is, or a way to force unmount it without knowing where it's mounted?

It's too easy for me to just unmount it, but I'm going for modularity here. I want the rest of my guys in the shop to be able to double click the icon, enter the device ID, and let it go, without having to worry about unmounting things manually.

Edit: Here is the source code.

#!/usr/bin/env python
#Killdisk 11.10.6 - October 6th 2011
#Author: Marcus Dean Adams (marcusdean.adams@gmail.com)
#Licensed under version 3 of the GNU General Public License
#A copy of the GNU GPL should be included with this software.
#If it is not, you can view the latest version at
#http://www.gnu.org/licenses/gpl.html

#Imports functions
import os
import sys
import time

#Checks that the user is running a Linux/Unix system
if os.name!="posix  print "This program is designed to run only on Unix like"
    print "operating systems."
    print ""
    raw_input("Press Enter to exit...")
    sys.exit("Exiting

#Welcome message
print ""
print "KillDisk 11.10.6"
print ""
print "This program will erase any file, disk or partition you specify."
print "At any time you can press Ctrl+C to cancel the program."
print "If you do so before a wipe operation has begun, no changes"
print "will have been made to the drive."
print ""
print "If you experience any problems with this software, feel free to e-mail me:"
print "Marcus Dean Adams (marcusdean.adams@gmail.com)"
print ""
raw_input("Press Enter to continue...")
print ""

#Prompts for the type of wipe to be executed, and sets variables accordingly.
print "What type of wipe would you like to perform? "
print ""
print "1) Overwrite all sectors with zeros (Faster, less secure)"
print "2) Overwrite all sectors with random data (Slower, more secure)"
print ""
style=raw_input("Enter a number: ")
if style=="1":
    wipe="dd if=/dev/zero of="
elif style=="2":
    wipe="dd if=/dev/urandom of="
else:
    print "Invalid input, exiting program to avoid unwanted"
    print "damage to data."
    print ""
    raw_input("Press Enter to exit...")
    sys.exit("Exiting

#Displays partitions on all disks.
print ""
print "Displaying partition tables of all drives in 3 seconds..."
time.sleep(3)
os.system("su-to-root -c 'fdisk -l'")
print ""
print "Please choose a device to kill.  Remember if you want to"
print "wipe the whole drive and not just a partition, you can"
print "remove the number appended.  Example /dev/sdc1 becomes /dev/sdc ."
print ""
device=raw_input("Enter device: ")
print ""
count=input("How many times would you like to wipe the device? ")
print ""
print "Writing changes to disk.  All data on %s will be lost."%(device)
print ""
raw_input("Press Enter to continue, or Ctrl+C to exit: ")
print ""
lap=1
for i in range(count):
    print "Processing wipe count %s of %s..."%(lap, count)
    os.system((wipe + "%s")%(device))
    lap=lap+1
print ""
"Done!"

exit

2 answers to this question

Recommended Posts

  • 0

You don't need to specify where it's mounted, the umount command can take either a directory where it's mounted or the device itself. If you want to confirm it by saying where it's currently mounted, you can just use the mount command without any arguments and that will give a list of device to directory (as well as its filesystem type and mount options). If you want to unmount any partitions, you can use fdisk -l and get any sub-devices from there and unmount all those.

This topic is now closed to further replies.
  • Posts

    • I think it could, but not intelligently, it would just be a matter of switching plans depending on if you want your cores parked. Still, that is probably something most gamers would be happy with. Important to note, that only matters for 3D chips with two CCDs, the 8-core X3D chips only have one CCD, so it doesn't matter. There are really two similar issue here when it comes to these multiple CCD chips. 1, better schedular understanding of what cores are best for what tasks. the probably need to just create a database of apps that will guide the windows scheduler, similar to NVidia's game ready drivers. You really have 3 categories to choose from, apps that should be pinned to 3D cores, apps that should be pinned to the fastest cores (non-3D on only chips, doesn't matter on newer), and apps that benefit from using as many cores as possible even if it means mixing both types. 2, Windows as a concept of NUMA Nodes (non-uniform memory access) for servers with multiple CPUs. It allows the scheduler to choose the best CPU based on what memory addresses are physically connected to that CPU's memory controller and avoid the costly operation of using a different CPU to access memory. I feel like they need a similar concept for NUCA Nodes (non-uniform cache access), so the scheduler understands what areas of cache are directly connected to what cores to prevent the costly operation of a core trying to access L3 cache from a different CCD.
    • Firstly, before responding, learn something, even if it's just a little bit, about computers and software. Secondly, and also before responding, learn to read, because at no point have I written anything about a Windows 11 Mobile.
    • The smart switch itself isn't doing the filtering. It's just a physical toggle for the filter. The idea is you will be less tempted to bypass the filter if you have to physically get up and walk to the other side of the house and press a button. This isn't being used to filter inappropriate content, it's to break an addiction to stupid sites like Facebook, Instagram or.... Neowin. Hahaha
    • raptors are meaningless monsters. I'm not gaming..
    • Firefox 140.0 by Razvan Serea Firefox is a fast, full-featured Web browser. It offers great security, privacy, and protection against viruses, spyware, malware, and it can also easily block pop-up windows. The key features that have made Firefox so popular are the simple and effective UI, browser speed and strong security capabilities. Firefox has complete features for browsing the Internet. It is very reliable and flexible due to its implemented security features, along with customization options. Firefox includes pop-up blocking, tab-browsing, integrated Google search, simplified privacy controls, a streamlined browser window that shows you more of the page than any other browser and a number of additional features that work with you to help you get the most out of your time online. Note: Firefox 140.0 changelog is not yet available. Download: Firefox 64-bit | Firefox 32-bit | ARM64 | ~60.0 MB (Freeware) Download: Firefox 140.0 for Linux | 64-bit | ~90.0 MB Download: Firefox for MacOS | 127.0 MB View: Firefox Home Page | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • One Month Later
      GoForma earned a badge
      One Month Later
    • Week One Done
      GoForma earned a badge
      Week One Done
    • Week One Done
      ravenmanNE earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      644
    2. 2
      Michael Scrip
      226
    3. 3
      ATLien_0
      217
    4. 4
      +FloatingFatMan
      144
    5. 5
      Xenon
      137
  • Tell a friend

    Love Neowin? Tell a friend!