Tag Archives: linux

Zero (One) writing a disk in Ubuntu

Or in any other Linux, from what I know.

Do a search and most of what you’ll find is this:

dd if=/dev/random of=/dev/sdX bs=1M

The intent is for that to fill a drive with random garbage.  You are also supposed to be able to use /dev/null or /dev/zero as the input to zero-write the drive.

Quite simply, that did not work for me.  I’ve had this problem before and again I spent too long getting around to the approach that actually worked.  As for the part that didn’t work, for all I can tell this command wasn’t actually doing anything even if I let it run for hours or pointed it to a specific partition (e.g., sdh1).

The command that worked!

tr ’00’ ‘\377’ < /dev/urandom | pipebench | sudo dd of=/dev/sdX

This required installing “pipebench” (sudo apt-get pipebench …).

Essentially, this fills a drive with ones instead of zeroes.  I think the idea of that — mostly “just because”.  Piping the translation of the zeroes to ones through “pipebench” gives a benchmark of the data rate.  That allows you to estimate how long until you are done.  Finally, the output is sent to the outfile (of) which is the mount for the drive (sdX).  In about 2.5 hours that wrote a 60GB drive with all 1’s.

This command ends with a “device out of space” error, which is fine.

So, my steps were:

  1. delete all partitions
  2. create one partition for the whole drive (to change the file table)
  3. write 1’s to the entire drive

In theory, said drive is now not possible to recover short of using a professional data forensics lab.  But who’s really that interested in me anyway?

UNIX find writeable files – more creative

In a follow-up to my previous post, I got tired of typing things.  And so I came up with this script:



# Put arguments into an array

# If no arguments, set firt value to current dir.
if [ -z "${args[0]}" ]; then

# Loop over supplied paths and find writeable files
for arg in $args; do

  find $arg -type f -perm /u=w  | grep -v "\.class" | grep -v tmp-bin | \
grep -v aTest | grep -v fixToStuff | grep -v build/ | grep -v gensrc/ | \
grep -v Reference | grep -v "~" | grep -v "classes" | grep -v "buildtree"



My only detail to sort out was exactly how to refer to $@.  Apparently if you quote it (being exactly “$@”) that takes all the arguments as a single string.  Unquoted, it takes them separately and gets what I’m looking for.

As you can see, I also have a lot of cruft I don’t want to see in my results, so I use good ol’ “grep -v” to weed it out.  Yes, I know there is a way to use egrep to make that all one command, but for some reason it doesn’t always want to play nicely for me.  So in a classic “eff it, let the script deal with it” I just chain some pipes.  I think if I had thousands of files to sort through, this would suck.  But I don’t, so it doesn’t.

Linux aliasing changing directories

Not terribly complicated or clever, but I wanted to try something different… and learn something.

alias u="cd .."
alias uu="u;u"
alias uuu="uu;u"
alias uuuu="uuu;u"
alias uuuuu="uuuu;u"
alias uuuuuu="for (( i=1; i<=6; i++ )) ; do cd .. ; done"
alias uuuuuuu="uuuuuu;u"

All this because I change directory levels like crazy, and often, in the shell. I worked out #6 when I was trying to figure out a way to count the number of U’s I typed. But then I reckoned that was too complicated, but didn’t want to completely lose it.

At least it is amusing to me.

I may try to figure out how to script this at some point and count the number of U’s or pass in a parameter.

UNIX find writable files

Way back when, I posted about using find and grep.  I have learned a couple of things since then.

1) find your critiera | xargs grep your grep criteria … is nicer to your processor, memory, and quickly returning the results.

2) finding writable files.  This has been particularly useful when using a really backwards SCS that doesn’t integrate nicely, cleanly, or usable with an IDE.

My command:  find . -type f -perm /u=w

So simple. So elegant. So simply says “find all files in this directory, recursively, that are writable by the user/owner”. The one confusing thing I had about this was /u instead of /o. I figured “owner, group, world”, but it is actually “user, group, other(s)”.

Anyway, this has improved my programming life.  Yeah, I’m gonna say it… take that, Windows.

diff in ‘nix environments

After a long silence… he surfaces!  I have a couple of things to say, but I’m going to start with a very simple pleasure: diff.  First, let me clarify that I generally love the command line.  But in a world of many different pieces that all have different importance, I have come to appreciate what GUI tools have to offer.  I find the compare functionality in something like eclipse to be handy in an efficiency++ way.  So when I go back to the command line for something like this, it is because nothing else can truly replace it… like the beauty that is vi.  ;D

The short story is this:  diff -w -B -y -W 200 {file1} {file2}

Now some of you are reading that and saying, “No kidding.  Welcome to the real world.”  The rest of you may be saying “gonk… gonk… goo gonk.”  So to quote the help on diff:

  • -w:  ignore all white space (like tab expansions and changes to white space)
  • -B:  ignore changes whose lines are all blank (just in case the above is finicky)
  • -y:  output in two columns
  • -W 200:  make the output 200 columns wide (this permits both files to be displayed in full width, with room, assuming 80 char width)

I have yet to find a graphical diff tool that can manage that so nicely.  The side-by-side output is very clean and I can redirect it to a file if I want to.  Smooth, simple, elegant.  And if there’s a way to improve on this, I hope a casual passerby will comment!


Upgrade Windows XP to Window 7 on a SATA drive

I chose to go the route of a Windows 7 Upgrade to save a little money.  I think perhaps the full install would have been worth the money to spare me the aggravation.  I will not try to recount this as an epic horror but instead list the series of steps that made this work.  It is worth noting that the “epic” nature of this event was incurred due to switching to a SATA hard drive.  Windows XP is not terribly friendly with these drives if you are installing anything older than Windows XP SP2.  As I understand it a slipstreamed SP2 installer should work fine, but I have not tested that.

Slipstream SATA Drivers to Windows XP Install Disk

There are blogs and directions out there for how to make this work.  Simply put, this didn’t work for me.  That was kind of annoying, but what I am glad about is that I found something that did work.  But for reference here are a couple of places that talk about this process (here and here).

Setting SATA Controller to IDE in BIOS

This is the process that worked for me.  I will note that I was shocked at first to see less than my full drive, but I was installing WinXP SP1.  There is a known issue with WinXP and SP1 where the drive only shows up with about 131 GB of space.  You can expand the partition post-install.  I started to recall past experiences with this issue when configuring my previous hard drive.

Step 1:  Set SATA controller in BIOS to IDE mode.

Step 2:  Install Windows XP, and don’t worry about the drive size being “wrong”

Step 3:  Install Windows 7 Upgrade … and this is where I resized the Windows partition (I halved the disk out of habit).

Step 4:  Set the AHCI parameter in the windows registry.  This was a problem under WinXP that required a lot of dancing around to make it work.  Being a bit of a Linux fan, I have to say that seeing this work so nicely under Win7 impressed me.  The “worst” part about this was the required reboot; and if that’s the worst, then I’m pretty happy.

Step 5:  Reboot and let drivers install

Step 6:  Be happy that Windows 7 installed!  Success is success.

Other Hurdles I Cleared

Sound Blaster Audigy (yes, Audigy) sound card with digital speakers:  Because I’m too cheap to get a new sound card in addition to all this, I had to download drivers, download updates to drivers, and fiddle around with settings to get my digital out to work.  But it works!  The unfortunate thing is that the toggle for the digital out is well hidden — which means switching to my headphones is going to be a process each time I was to do it.

nVidia GTX 460 SE drivers:  The only “hurdle” here is EVGA being unclear on the box that their card is an “SE” not a standard 460.  But, hey, the drivers installed and it works.  What is there to complain about?

Reconnecting my Linux drives:  Because I don’t entirely trust OS installers (any of them), I disconnected my Linux drives.  I had to make sure my SATA controller setting was set properly for them to work.  Once it was set back to AHCI, as apposed to “Standard IDE” or “RAID”, reconnecting the drives resulted in things starting up nicely into Linux.  All hail boot order in the BIOS!  So handy.

Reconfiguring GRUB:  I still use GRUB (not grub2) and setting up new entries is a simple matter of editing the /boot/grub/menu.lst.  And, viola, back to dual-boot.  Of course, there’s a little trial-and-error to figure out the proper drive reference for GRUB.  I was lucky and it was only a matter of uncommenting my Windows XP entry and renaming it — the basic drive reference had remained the same.

No Primary IDE Master:  This was resolved automatically by having my Linux drive connected to SATA-1 again.  I put my Linux drive on that and since I disconnected it for the install, this gave the BIOS something to complain about.  I really like “problems” that resolve themselves…!

And there you have my little journey.

Synergy Plus

I feel very behind the times.  One of my favorite tools has not been maintained for years.  BUT, there is a fork of it that is maintained:  http://code.google.com/p/synergy-plus/

Even with a KVM, this additional tool is great.  I have a dual-monitor setup where one monitor is on a KVM.  The second monitor on my desktop system and my laptop screen are dedicated to those systems.  With the KVM I can make either desktop bigger, but since I spend most of my time with my laptop (for work), Synergy+ lets me quickly drift over to my desktop and deal with anything displaying on the secondary screen (IRC, music, etc.).