LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01:49 PM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Rep: Reputation: 46
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, 03:13 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
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, 03: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,476

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
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 03:21 PM.
 
Old 09-18-2016, 03:22 PM   #4
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 954
Blog Entries: 3

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
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 11:49 PM. Reason: reduced risk for copy-paste
 
2 members found this post helpful.
Old 09-18-2016, 11:02 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 385

Rep: Reputation: 158Reputation: 158
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, 08:39 AM   #6
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
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, 07:25 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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, 07:36 AM   #8
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian Sid. Arch. In the process of converting to and learning FreeBSD
Posts: 1,023
Blog Entries: 6

Rep: Reputation: 237Reputation: 237Reputation: 237
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, 08:31 AM   #9
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
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, 09:29 AM   #10
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian Sid. Arch. In the process of converting to and learning FreeBSD
Posts: 1,023
Blog Entries: 6

Rep: Reputation: 237Reputation: 237Reputation: 237
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 09:50 AM.
 
Old 09-22-2016, 09:58 AM   #11
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
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, 10:19 AM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,026

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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, 10:30 AM   #13
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

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

Rep: Reputation: 225Reputation: 225Reputation: 225
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, 10:46 AM   #15
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian Sid. Arch. In the process of converting to and learning FreeBSD
Posts: 1,023
Blog Entries: 6

Rep: Reputation: 237Reputation: 237Reputation: 237
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:20 PM
[SOLVED] Shut down Puppy Linux 4.20 from command line or keyboard shortcut without freezing ubume2 Linux - Newbie 2 09-18-2009 01:27 PM
How to enter graphical mode (run level 5) command line (run lenel 3) edmondgyampoh Linux - Newbie 3 05-15-2009 07:33 PM
trying to fix xwindows or just run command line... changing run levels dave247 Debian 2 11-18-2008 07:11 PM
Straightforward way to shut down graphical display on Fedora 7 from command line Sheridan Linux - Newbie 8 02-11-2008 11:20 AM


All times are GMT -5. The time now is 12:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration