• 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

    • Is that the one that's perfect in every way except it doesn't have NFC?
    • It does to some extent. You can share your screen in the voice mode. And it can see what you are working on.
    • Jony Ive is reportedly working on multiple AI devices for OpenAI, including a mobile gadget by Hamid Ganji Last month, OpenAI announced acquiring Jony Ive's startup, io, in a $6.5 billion deal. Ive, who served as Apple's design chief for over two decades, moved to OpenAI to work on the company's AI hardware projects. While the details of these projects have remained relatively untold, Mark Gurman's Power On newsletter revealed some exciting insights about Jony Ive's work at OpenAI. According to Gurman, Apple's former design chief is now spearheading a series of groundbreaking AI hardware products for OpenAI. One of these under-development devices is described as a "mobile gadget" that takes the form of a "pendant" and can be worn around the neck. This device could allegedly allow users to access ChatGPT with voice commands. Another of Ive's works at OpenAI is a home device that functions similarly to a smart speaker. Users can put the device on a table and perform various tasks using OpenAI's ChatGPT. Interestingly, OpenAI also has a robot device under development. As Gurman says, this robot "will likely be a machine that develops a relationship with a human using AI." However, OpenAI's robot is still far from being made available on the market. After acquiring Jony Ive's startup, OpenAI CEO Sam Altman described Ive as the best designer in the world, adding that they can now work on the next generation of AI-powered computers. More details about OpenAI-Ive hardware products could emerge over the next few months. OpenAI was already rumored to be working on a mysterious AI gadget, presumably a screenless AI phone, which might be the same mobile gadget that Gurman revealed. While details of this alleged AI mobile are yet unknown, such a device could pose an alternative to conventional smartphones, raising the alarm for smartphone makers such as Apple, Samsung, and Google. Meanwhile, Apple might already be expecting such a device, as its services chief Eddy Cue allegedly said during his testimony at Google's antitrust case that iPhones might no longer exist 10 years from now.
    • Seems Nintendo have already thought of that after the Joy-Con drift in the Switch 2 EULA: Clause 16 of the EULA reads: "This arbitration provision precludes you and Nintendo from suing in court, having a trial by jury, or participating in a class action. You and Nintendo agree that arbitration will be solely on an individual basis and not as a class arbitration, class action, or any other kind of representative proceeding. You and Nintendo are each waiving the right to trial by a jury."
    • Cool glass phone you have in that silicon case bro
  • Recent Achievements

    • First Post
      brynmot earned a badge
      First Post
    • Reacting Well
      brynmot earned a badge
      Reacting Well
    • Week One Done
      Al_ earned a badge
      Week One Done
    • Week One Done
      MadMung0 earned a badge
      Week One Done
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      477
    2. 2
      +FloatingFatMan
      274
    3. 3
      ATLien_0
      243
    4. 4
      snowy owl
      209
    5. 5
      Edouard
      185
  • Tell a friend

    Love Neowin? Tell a friend!