Unix recovery legend
ee.ryerson.ca
ee.ryerson.ca
This is an profanity-laden blog I wrote immediately after I figured out how to fix it and got everything back up and running:
(I'll be the first to admit that I sound like an obnoxious teenager in this blog, and that some of the things that I tried to fix it were very naive...it was a few years ago that it happened and as stupid as it is to admit, trying to get everything back up and running made my adrenaline pump pretty hard, so...I apologize in advance...)
The VAX 11/780 had no portable boot device, and BSD unix had no "installation media". You bootstrapped to a system monitor, loaded a second stage off of tape header into memory manually, and hand-build your root filesystem. And that's assuming you still have your original tapes from Berkeley in storage somewhere.
I actually tried doing this on the simh simulator a while back, out of sheer curiosity. I gave up before managing to make it work.
I wish! This was done on a VPS located god knows where and run by a company that was owned by people who didn't seem to speak any English. I remember emailing them and asking them if they could just move my dirs back using a chroot, but they had no clue what I was talking about. If I had allowed my SSH session to time out, I would have most-certainly lost the server and everything on it.
I have since switched to a combination of slicehost and linode.
Switching to a different VPS provider is not the right way to prevent data loss. Doing backups is the right way to prevent data loss. :-)
Even still, I would much rather be able to just mv the dirs back to their proper location from a chroot than having to do a restore from scratch over the network.
Still, you had some good points. The information on explicitly indicating the library directory is good. Most important of all is the lesson to double check any mv, rm, and splat-completing command that is run as root (or under sudo, for you sudo junkies out there). Personally when I'm using a * in a root command, I first add "echo " to the beginning of the line so that I am sure of what is going to happen before I execute it.
pscp *.jpg root@gibsonandlily.com:/
This was monumentally stupid, I know. Looking on the bright side of things, however, I learned my lesson :).On a separate note, I tend to disable root SSH access on my servers. I SSH as a user and then when necessary, I'll su to root. Not only does that kill the temptation to use root as the default login, it also makes it doubly-hard to get to root as far as password-stealing goes.
I never just
sudo rm *
First, I do echo sudo rm *
inspect the output, and then use CLI editing to recall the command, and delete the "echo"I do this for damn near everything that involves a wildcard. It's a lifesaver.
alias rm='rm -i'
to my .bashrc. Sure its a pain when i have to delete whole directories but saves my ass.
and while i'm at it, "set noclobber" has saved me a few times from doing something like "grep file > someotherfile" when i meant to do "grep file >> someotherfile".
I was starting to write a UUDECODE function in pure bash (I'd saved my ass before by pasting uuencoded binaries into terminal emulators) — but then I remembered that bash has built-in tcp support!
At least when called from the exec builtin to spawn a file descriptor, you can open /dev/tcp/$host/$port psuedo-devices. It's existence would have saved me countless more times, if the spoilsports at Debian/Ubuntu hadn't disabled it at compile-time.
You have to be careful making that assumption anymore, though; the version of bash that's included with Debian (and downstream variants, e.g. Ubuntu) has /dev/tcp and /dev/udp support disabled.
So it's not something you can count on having available in any random environment you log into.
I disagree with Debian's decision to disable it, but they seem pretty firmly set on it -- people have been arguing with them to reverse it for the better part of a decade, to no avail, so I doubt it's going to change. It's a declining minority of users who probably care. But you could do some neat 'party tricks' with it.
and this is why my "rm" is replaced by this script... just moving stuff to another directory (trash) and I clean my trash manually (with at least 2 confirmations)...
With all these precautions, if I delete something important, I don't deserve admin rights :-)
randstring=`date "+%Y-%m-%d_%H-%M-%S"_bak`
while [ ! -z "$1" ]; do mv -b -S "$randstring" "$1" ~/.local/share/Trash/files shift done
-hbt
It would be nice to know I'm about to do something that I don't intend. As long as the system doesn't ask me "are you sure you're sure you're sure?"
What we really need are transactions or a versioned filesystem. rm -rf *? rollback!
[1] Command Line User Environment
For me, this is sort of like standing at the edge of a big cliff; you just have this weird feeling that you might accidentally, compulsively jump.
It sort of sucks that in SQL you first say what action you want to perform and then say what you want to perform it on. I end up writing the WHERE part of every query first anyways.
from where select
I like it that way; it happens to already match the way my mind plans a relational query.BEGIN;^M<potentially dangerous query>;^M<look at results>[COMMIT|ROLLBACK];^M
$ rm *
zsh: sure you want to delete all the files in /home/viraptor/tmp/zsh [yn]?Bookmarked! :)
(we actually have a huge pile of old old machines in a store room at the office here - Im not sure if there is a VAX in there or not.. there could well be)
I wasn't being too serious though :)
You unix kiddies finally got a versioning filesystem now I hear ?
They had about 25 users on a 386-25 - quite a decent system in its day.
grep '.*' > /etc/password
instead of cat > /etc/password /usr/bin/grep ".*" /path/of/file /usr/bin/grep '^' > output
Or even better, grep can be an editor with line filtering - if you make an mistake, have it throw away the line: /usr/bin/grep -v '%' > output
(Any line with a %, throw away, keep the rest - good for multi-line files) grep '.*' fileI may be way wrong here, but I thought the symlink would still work with the original being deleted, because the file system won't actually mark the file as gone until all links are gone.
Would (or does) this work? Haven't got access to a unix box right now, so can't try myself, but thought it might be a naive failsafe (at least until you actually wait for rm -rf * to finish...)
Symlinks are symbolic links (soft links), potentially-relative references to fungible user-facing filesystem paths, that work across filesystems and respect the permissions of the original. They're a special kind of file.
It would work with hard links, but you'd have to make and maintain a whole separate real directory structure with an individual link to every file. People used to do this to efficiently maintain branches of the Linux kernel in the days before bitkeeper, depending on their editor to replace files by rename+copy instead of rewriting in-place.
Hard links to directories were removed in an early unix for being hostile to reality and fsck, but were added again in Mac OS 10.5's HFS+ implementation to implement Time Machine's storage.
# cd
# rm -rf *
I'm wondering why they can delete files under /bin and /dev?Perhaps they need to alias rm to 'rm -I' (-I : prompt once before removal)? I remember one of the MandrakeLinux versions had that enabled by default many years ago. It saved me a couple of times when I was still a Unix noobie.
Just because you are root doesn't mean you should be able to do whatever you like to the filesystem at any time. Most modern unix variants (including linux) support file attributes such as immutability, see the man page for chattr(1) if you want more. In BSD land there is additionally the concept of Secure Levels which limit the ability of root to change file attributes under different circumstances; generally you have to reboot into single user mode to overwrite files or directories marked as immutable or delete ones marked as append_only.
The chflags command first appeared in 4.4BSD.
Which puts it about seven years after this story.While i waited i opened netscape and went to read something. Then while it was coping irc was flooded with bad omens and curses about what would happen if i did that on a live system.
The only thing i noticed was that the icon state (the desktop shortcuts changed picture if there was any process open for their target files) would some time blink. But that was it.
Not a thing happened. Even the bookmarks i saved on the netscape bookmark file opened before the move ended up on the right place.