LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2016, 12:49 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
Run a command line then shut down when it finishes


I want to run a wipe on a hard drive before I give it away, but I don't want to wait around for it to finish before I turn off my computer. How could I run the wipe command then when that completes have my computer shutdown -h now?
 
Old 09-18-2016, 02:13 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Umm... quick pseudo-code (as root obviously):
Code:
dd if=/dev/zero of=/dev/sda bs=1M && shutdown -h now
Will this suffice?
 
2 members found this post helpful.
Old 09-18-2016, 02:19 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Make a little shell program with the commands in it, make it executable (chmod 755 progname) and run it as root.

When you run the program it will execute whatever wipe you're using and when that finishes it will execute the next line (your shutdown, which could also be init 0).

When you're wiping the disk you'll have enough system left in RAM to do the job.

However, you don't need to wipe it (as in walking directories and the like), just reformat the thing, much faster.

Hope this helps some.

Last edited by tronayne; 09-18-2016 at 02:21 PM.
 
Old 09-18-2016, 02:22 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by HMW View Post
Umm... quick pseudo-code (as root obviously):
Code:
dd if=/dev/zero of=/dev/sdx bs=1M && shutdown -h now
Will this suffice?
I'm not sure what "dd" will do once it gets to the end of the drive. Will it exit with success or fail for an exit code? You'll catch any errors that occur and that is good, but it is possible that running to the end of the drive will also be considered an error and the shutdown aborted. Making the shutdown unconditional would fix that, but then any error messages would be lost:

Code:
dd if=/dev/zero of=/dev/sdx bs=1M; shutdown -h now

Last edited by Turbocapitalist; 09-18-2016 at 10:49 PM. Reason: reduced risk for copy-paste
 
2 members found this post helpful.
Old 09-18-2016, 10:02 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
While you're at it, may as well be aware of what dd reported (if there were errors) as shutting down will make those go away.

Code:
# dd if=/dev/zero of=/dev/sdx bs=1M &> ~/dd_wiped_sda.log; shutdown -h now
Goes without saying this is a very bad command to copy and paste right?
OP, please triple check the directory /dev/sdx before running any of the commands posted here
 
3 members found this post helpful.
Old 09-19-2016, 07:39 AM   #6
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks everybody. that's a good idea to have it actually log so I can see what it did. so is dd the best way to wipe your data so it can't be recovered. I see examples online for dd, wipe, and some other stuff.
 
Old 09-22-2016, 06:25 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
There are some pretty extreme opinions on secure erasing, but I'd say up 3 'dd' passes should be plenty eg all zeros, all 1's, random (choose your own order).
'shred' is pretty good but I think (?) it only does existing dirs + files.

Have a google around before deciding; you could even use more than one method.
 
1 members found this post helpful.
Old 09-22-2016, 06:36 AM   #8
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by Sefyir View Post
While you're at it, may as well be aware of what dd reported (if there were errors) as shutting down will make those go away.

Code:
# dd if=/dev/zero of=/dev/sdx bs=1M &> ~/dd_wiped_sda.log; shutdown -h now
Goes without saying this is a very bad command to copy and paste right?
OP, please triple check the directory /dev/sdx before running any of the commands posted here
Which is why I got into the habit of posting something like:

Code:
# dd if=/dev/zero of=/dev/your_device_name_here_replace_this bs=1M &> ~/dd_wiped_sda.log; shutdown -h now
Then explain what they're to replace that verbose non-sensical device name with.

If the person copying and pasting (we know it's a bad idea but that doesn't exactly stop people, does it?) copies the above with sdx, if there happen to be an "sdx", it's toast.
 
1 members found this post helpful.
Old 09-22-2016, 07:31 AM   #9
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks all. I've run in to a problem with dd though, apparently if it hits a bad spot on the drive, it totally dies rather than just reporting it and moving on. unless I'm missing a switch or something to make that happen.
 
Old 09-22-2016, 08:29 AM   #10
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
How about then creating a large file, then deleting it, before shutting down? Granted the filesystem will still be in place, but the actual data within the filesystem will be gone. The fs should be able to compensate for those bad blocks.

The only switch I can find for dd to ignore a bad block is on reading.

Last edited by goumba; 09-22-2016 at 08:50 AM.
 
Old 09-22-2016, 08:58 AM   #11
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
I couldn't find a ignore on write either, but I wouldn't put it past me to miss a switch reading a man page haha
Yeah, might have to go the big file/delete/big file/delete... method, that's the only thing I could think of too
 
Old 09-22-2016, 09:19 AM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by rjo98 View Post
Thanks all. I've run in to a problem with dd though, apparently if it hits a bad spot on the drive, it totally dies rather than just reporting it and moving on. unless I'm missing a switch or something to make that happen.
ddrescue ?
 
1 members found this post helpful.
Old 09-22-2016, 09:30 AM   #13
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
So looks like
ddrescue --fill-mode=+ --force /dev/zero bad_drive mapfile
may take care of that?
 
Old 09-22-2016, 09:44 AM   #14
jens
Senior Member
 
Registered: May 2004
Location: Belgium
Distribution: Debian, Slackware, Fedora
Posts: 1,463

Rep: Reputation: 299Reputation: 299Reputation: 299
Quote:
Originally Posted by rjo98 View Post
Thanks all. I've run in to a problem with dd though, apparently if it hits a bad spot on the drive, it totally dies rather than just reporting it and moving on. unless I'm missing a switch or something to make that happen.
While I agree that it's dangerous to do this ... using dd conv=noerror should allow it to continue.
 
Old 09-22-2016, 09:46 AM   #15
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by jens View Post
While I agree that it's dangerous to do this ... using dd conv=noerror should allow it to continue.
According to the man page, that's for read errors, the problem being encountered is on writing.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Automatically Shut Down Your Computer After A Download Finishes LXer Syndicated Linux News 0 04-27-2011 05:20 PM
[SOLVED] Shut down Puppy Linux 4.20 from command line or keyboard shortcut without freezing ubume2 Linux - Newbie 2 09-18-2009 12:27 PM
How to enter graphical mode (run level 5) command line (run lenel 3) edmondgyampoh Linux - Newbie 3 05-15-2009 06:33 PM
trying to fix xwindows or just run command line... changing run levels dave247 Debian 2 11-18-2008 06:11 PM
Straightforward way to shut down graphical display on Fedora 7 from command line Sheridan Linux - Newbie 8 02-11-2008 10:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration