[131050650010] |How do I test to see if an application exists in $PATH? [131050650020] |I'm trying to write all of my sh startup/env scripts to work with as much DRY and as much: "works on every *nix I clone it to", as possible. [131050650030] |This means making sure that if I try to run code that's not there, that the code fails gracefully. [131050650040] |To that end I need to be able to test if programs exist. [131050650050] |I know how to test if a file exists, but I'm not sure how to test to see if an application is executable within the path. I'd rather use the $PATH, as some of these need to work on arch, ubuntu, and centos. [131050650060] |Some might be installed in my homedir, on systems where I don't have root, others might not be installed, and others yet my be installed in system paths. [131050660010] |Use type commandname. [131050660020] |This returns true if commandname is anything executable: alias, function, built-in or external command (looked up in $PATH). [131050660030] |Alternatively, use command commandname which returns true if commandname is a built-in or external command (looked up in $PATH). [131050660040] |There are a few sh variants (definitely pre-POSIX; I know of /bin/sh under OSF1 ≤3.x and some versions of the Almquist shell found in early NetBSD versions and a few 20th-century Linux distributions) where type always returns 0 or doesn't exist. [131050660050] |I don't think any systems shipped with these this millennium. [131050660060] |If you ever encounter them, here's a function you can use to search in $PATH manually: [131050660070] |This function is generally useful if you want to exclude built-ins and functions and look up the name in $PATH. [131050660080] |Most shells have a built-in for this, command -v, though it's a relatively recent addition to POSIX (still optional as of POSIX:2004). [131050660090] |It's basically a programmer-friendly version of type: it prints the full path for an executable in $PATH, the bare name for a built-in or function, and an alias definition for an alias. [131050660100] |Ksh, bash and zsh also have type -p to look up only executables in $PATH. [131050660110] |Note that in bash, the return status of type -p foo is 0 if foo is a built-in or function; if you want to test for an executable in $PATH, you need to check that the output is not empty. type -p is not in POSIX; for instance Debian's ash (which is /bin/sh on Ubuntu) doesn't have it. [131050670010] |If you are only looking for external programs, you can also use which. [131050670020] |Don't know how portable that is though. [131050680010] |Why is plymouth-log-viewer starting up? [131050680020] |I've been using Fedora 14 for about a month on my primary system (converted from Win2K). [131050680030] |My secondary system was converted to Fedora 12 from Win2K, and was updated sequentially to Fedora 14 (using package-update both times). [131050680040] |Recently, my primary system started showing an alert icon in the notification area immediately after login - a yellow triangle with an "!" in it. [131050680050] |When I click on the triangle, I get a window titled "Boot Messages" with the following content: [131050680060] |This content corresponds exactly to the full content of /var/log/boot.log. [131050680070] |Some poking around determined that this was the process plymouth-log-viewer, and that it is a graphical boot log viewer. [131050680080] |I can understand this occurring if there's a boot problem. [131050680090] |However, reviewing the content of the log does not seem to reveal any problems. [131050680100] |Also, it's somewhat disconcerting that my only option once the viewer appears is to right-click the "!" and select "Quit". [131050680110] |Can anyone provide any information on why this is happening, and how to stop it? [131050680120] |This does not happen on my secondary system at all, and I cannot identify any significant discrepancies between the two systems. [131050680130] |The only information that appears to indicate a potential cause is the following fragments from /var/log/messages: [131050680140] |UPDATE The message content below also appears in the same log file on my secondary system, where plymouth-log-viewer is not triggered on login. [131050680150] |Repeats several times: [131050680160] |Occurs once: [131050680170] |Occurs once: [131050680180] |Thanks in advance! [131050690010] |How do I permanently increase the font size in mrxvt? [131050690020] |The Ctrl+= hotkey increases the font size for the current session in mrxvt. [131050690030] |What configuration option will increase the font size permanently? [131050700010] |If you are refering to the font size in the terminal in general, add these lines to your ~/.Xdefaults file: [131050700020] |Replace my font example (DejaVu Sans Mono) with your desired font and size. [131050700030] |Keep in mind that you can use * to define the font in all terminals (VT ones like aterm, *rxvt, xterm, etc.) with code like this: [131050700040] |Personally I use the second method, but you can define different fonts in different terminals if you like. [131050710010] |How to find which processes are taking all the memory? [131050710020] |I'm looking for somthing like top is to CPU usage. [131050710030] |Is there a command line argument for top that does this? [131050710040] |Currently, my memory is so full that even 'man top' fails with out of memory :) [131050720010] |Once top starts, press F to switch to the sort field screen. [131050720020] |Choose one of the fields listed by pressing the key listed on the left; you probably want N for MEM% [131050730010] |From inside top you can try the following: [131050730020] |
  • Press SHIFT+f
  • [131050730030] |
  • Press the Letter corresponding to %MEM
  • [131050730040] |
  • Press ENTER
  • [131050730050] |You might also try: [131050730060] |This will give the top 5 processes by memory usage. [131050740010] |If you have it installed I like htop once launching it you can press f6, down arrow (to MEM%), enter to sort by memory. [131050750010] |In Solaris the command you would need is: [131050750020] |This will list all processes in order of descending process image size. [131050750030] |Note that the latter is based on memory committed to the process by the OS, not its resident physical memory usage. [131050750040] |There are supposedly versions of "top" available for Solaris, but these are not part of the standard installation. [131050760010] |One nice alternative to top is htop. [131050760020] |Check it, it is much more user friendly than regular top. [131050770010] |On Linux, is there an rc.local equivalent for shutdown? [131050770020] |I've got a few commands that I run in rc.local so they are run last in the startup sequence. [131050770030] |I would like to know if there is a similar facility for undoing the results of those commands at shutdown, like an rc.shutdown. [131050770040] |Ideally, it would be run before any of the other /etc/init.d scripts. [131050780010] |Not really (at least, to my knowledge). [131050780020] |If you've got SystemV style init scripts, you could create something along the lines of /etc/rc6.K00scriptname and /etc/rc0.d/K00scriptname, which should get executed prior to any of the other scripts in there. [131050790010] |If you have upstart, you can catch the shutdown event and run a script when it is caught. [131050800010] |ArchLinux does have a /etc/rc.local.shutdown file for this. [131050800020] |I'm not sure about other distros [131050810010] |In Gentoo the "local" script does exactly what you ask for: It runs certain user specified commands upon 'start' and another set of commands upon 'stop'. [131050820010] |RAID 1 in linux [131050820020] |I'd like to setup RAID 1 with two drives in linux. [131050820030] |I don't have a hardware RAID controller and don't want to buy one, so what is the best software RAID option for linux? [131050820040] |Note: If it makes a difference, I'm running Gentoo. [131050830010] |You can use mdadm to manage software raid on linux. [131050840010] |Use mdadm, check the manpage. [131050840020] |However, I will list one gotcha here. [131050840030] |If you do this and really want reliability, you should make sure your master boot record is copied to both drives. [131050840040] |By default it will likely only get copied to one drive. [131050840050] |If that drive dies, you cannot boot from the other drive, even though all your data is safe. [131050840060] |To copy the mbr to both drives, use something like dd to copy the first 446 bytes of one drive to the other. [131050840070] |If you're building the RAID on top of the devices (/dev/sda) rather than on top of partions on the devices (/dev/sda1), then you probably shouldn't do what I am suggesting because you're writing data directly to the device underneath the md driver. [131050840080] |At least, I've never tried it that way. [131050850010] |How can I determine if someone's SSH key contains an empty passphrase? [131050850020] |Some of my Linux &FreeBSD systems have dozens of users. [131050850030] |Users will use some of these "ssh gateway" nodes to SSH into other internal servers. [131050850040] |We're concerned that some of these people use an unencrypted private SSH key (A key without a passphrase. [131050850050] |This is bad, because if a cracker ever gained access to their account on this machine, they could steal the private key and now have access to any machine which uses this same key. [131050850060] |For security reasons, we require all users to encrypt their private SSH keys with a passphrase. [131050850070] |How can I tell if a private key is not-encrypted (e.g. Does not contain a passphrase)? [131050850080] |Is there a different method to do this on an ASCII-armored key vs. a non-ASCII-armored key? [131050850090] |Update: [131050850100] |To clarify, assume I have superuser access on the machine and I can read everybody's private keys. [131050860010] |If you have access to the private key, I suppose, you can use it without passphrase to authenticate against the public key. [131050860020] |If this works you know it has no passphrase. [131050860030] |If it had, it would give you an error message. [131050860040] |If you don't have access to the private key, I doubt you can detect this. [131050860050] |The passphrase's purpose is to "unlock" the private key, it has no function in regard to the public key. [131050860060] |In fact, if it would, it would make the system less secure. [131050860070] |One could use the public key, that is available to try to mount brute force or other attacks trying to crack the passphrase. [131050870010] |You can't do this with just the public key and even if you could, it would be largely useless because they can always remove the pass phrase from their private key without you knowing. [131050880010] |Well, OpenSSH private keys with empty passphrases are actually not encrypted. [131050880020] |Encrypted private keys are declared as such in the private key file. [131050880030] |For instance: [131050880040] |So something like [131050880050] |should do the trick. [131050890010] |Open a command line window in GNOME Desktop [131050890020] |In GNOME Desktop, when I type /usr/bin/firefox, the Firefox browser will open. [131050890030] |How can I open a command line window in the same way? [131050900010] |Use GNOME Terminal: [131050900020] |/usr/bin/gnome-terminal [131050910010] |GNOME-keyring KWallet integration? [131050910020] |I use some GNOME apps, and some KDE apps, so some of them use G-keyring and some KWallet... [131050910030] |What I would like to have is a single place for managing passwords. [131050910040] |Is there a way to integrate G-keyring and KWallet? [131050910050] |Or is there maybe a way to force GNOME apps to use KWallet or KDE apps to use G-keyring? [131050910060] |OR is there maybe a way to force them all to use KeePassX or something similar (automaticaly using it after entering the master password)...? [131050910070] |suggestions? thanks! [131050920010] |I found this [131050920020] |One annoyance of the free desktop at present is the use of incompatible systems for storing sensitive user data such as passwords. [131050920030] |Every web browser may have its own password store and anyone using both KDE and Gnome applications will likely have to open both KWallet and Gnome Keyring in every desktop session. [131050920040] |Michael Leupold presented a collaboration between KDE and Gnome to develop a unified standard for storing secrets. [131050920050] |The aim is that KDE and Gnome applications will both be able to share a common secrets architecture but still have separate graphical interfaces. [131050920060] |A KDE user will be presented with a KDE interface if they need to unlock an account in Empathy (the Gnome instant messaging application) while a Gnome user will see a Gnome interface for password management even if they prefer to chat using KDE's Kopete. [131050920070] |It is also hoped that the standard will attract the support of other vendors, such as Mozilla. [131050920080] |this seems older, but might be a link to the actual project? [131050920090] |After having hinted at it now and then, I can finally gladly announced that we (GNOME Keyring + KDE Wallet) managed to kick off a joint freedesktop.org project with the goal of creating a common infrastructure (or more technically: protocol) for managing passwords and other secret values. [131050930010] |802.3ad on FreeBSD and Linux using crossover cables? [131050930020] |I have setup a NFS server on FreeBSD 8.1, which will be serving one Linux client. [131050930030] |Each box has a dual-port 1gig fiber card, and each box is directly connected to the other over this link. [131050930040] |There is no switch involved. [131050930050] |I suppose that my question is, since both FreeBSD and Linux support 802.3ad, is the following the right way to configure this, when not using a switch? [131050930060] |Or is there a better way? [131050930070] |Is this even supported? [131050930080] |With this setup, I am able to ping between the hosts, transfer files over NFS, etc. [131050930090] |I have configured em2 and em3 for 802.3ad (lacp): [131050930100] |And eth2 and eth3 for 802.3ad bonding: [131050930110] |EDIT: I've found that, on the FreeBSD box, the MAC addresses of em2 and em3 are the same, where-as on the Linux box, the MAC addresses of eth2 and eth3 are different. [131050940010] |How can I count the number of different characters in a file? [131050940020] |I would need a program, that outputs the number of the different characters in a file. [131050940030] |Example: [131050940040] |Exists any tool, that do this? [131050950010] |The following should work: [131050950020] |First, we insert a newline after every character, putting each character on its own line. [131050950030] |Then we sort it. [131050950040] |Then we use the uniq command to remove the duplicates, prefixing each line with the number of occurrences of that character. [131050950050] |To sort the list by frequency, pipe this all into sort -nr. [131050960010] |Steven's solution is a good, simple one. [131050960020] |It's not so performant for very large files (files that don't fit comfortably in about half your RAM) because of the sorting step. [131050960030] |Here's an awk version. [131050960040] |It's also a little more complicated because it tries to do the right thing for a few special characters (newlines, ', \, :). [131050960050] |Here's a Perl solution on the same principle. [131050960060] |Perl has the advantage of being able to sort internally. [131050960070] |Also this will correctly not count an extra newline if the file does not end in a newline character. [131050970010] |TTY On External Monitor [131050970020] |When using my laptop at home, I usually use an external monitor, keyboard, and mouse with my laptop's screen as a second monitor. [131050970030] |This is all easily configured using a nice GNOME utility that I assumes uses xrandr on the backend. [131050970040] |Sometimes I enjoy using my computer via a TTY. [131050970050] |I would like to be able to switch over to TTY1(using ctrl+alt+f1) and have the tty appear on my external monitor at the resolution of my external monitor. [131050970060] |Rather, it usually either appears on just my laptop screen, or on both monitors but at the resolution of my laptop's screen. [131050970070] |Is there anyway to do this seamlessly on Ubuntu 10.10? [131050970080] |(I'm guessing it doesn't matter, but I've set it such that screen launches automatically from ~/.profile). [131050980010] |Since Im a newb, I am only allowed one hyperlink. [131050980020] |Here is a Google Doc with the correct links. [131050980030] |No proven solutions, but here are some ideas: [131050980040] |The kernel framebuffer draws the console if there is no X11. [131050980050] |Perhaps you can exclude the second display from you X config? [131050980060] |I think the way to go (think because I havent done this myself, I like the full screen term) is to configure your external monitor as a separate framebuffer. [131050980070] |Now you'll have one fb for the console and one for X11. [131050980080] |I have found several con2fb, which maps a tty to a framebuffer, something like "con2fb /dev/fb2 /dev/tty5" but can not find where to download it. [131050980090] |Another fan had a similar search and the source is posted here. [131050980100] |Also check out this doc, especially 14.9 and this multihead howto that both discribe con2fb. [131050980110] |Im thinking you could then take turns sending a tty to /dev/fb2 or extending your desktop... maybe xrandr? [131050980120] |Another way to try could be a multiseat set up. [131050980130] |This typically has separate multiple kb and mouse for each display, but you could use Synergy2, and external kvm switch, custom config with hotkeys....? xorg xfree [131050980140] |Good luck! [131050990010] |Ex and Vi: buffers and regexes [131050990020] |I want to put regex matches to buffer but cannot get even simpler example y :.put myNewBuffer return msg [line] [put] [buffer] working ie how to put something to buffer? [131050990030] |So to regular expressions and ex [131050990040] |
  • what does (.,.)~ replaces the previous regular expression with the previous replacement pattern from a substitution mean? [131050990050] |Some example helpful, source of the quote.
  • [131050990060] |
  • please, give some examples how you use regexes with ex. [131050990070] |For example, how can you buffer areas between starting word having h as the first character until the word ending to s character?
  • [131050990080] |
  • What about if the last thing only on a line ie ending word is the word ending to s or the end of line $?
  • [131051000010] |The vim manual may be a better and more up-to-date than that old Ex manual. [131051000020] |Most likely, you will be using ex that comes with vim on most modern Linux distributions. [131051000030] |To get help in Vim use :help, to get help on a specific command like the Ex command ~, use :help :~. [131051000040] |All Ex commands are preceded with a : in Vim. [131051000050] |I think (.,.) is simply used to denote a range may be specified as in 2,8 to mean lines 2 through 8 or 1,$ ($ represents last line) for every line in a file. [131051000060] |In Vim, typing :1,$~ means run the Ex command ~ on every line in the file. [131051000070] |
  • Vim say :~ is "Repeat last substitute with same substitute string but with last used search pattern." [131051000080] |A substitution is normally written as :s/pattern/string/ This looks for a pattern on a line and replaces it with string. :~ repeats last substitute command, but uses the most recent search for pattern.
  • [131051000090] |
  • Try this pattern: /\
  • [131051000100] |/ is used to start a search in Ex/Vim, \< means match start of word, h matches h, .* where . matches any single character and * repeats that zero or more times so .* means match zero or more characters. s matches s, \> matches end of word. [131051000110] |
  • Try this pattern /words\?$
  • [131051000120] |$ means end of line when used in a pattern match, and \? means previous character is optional. [131051000130] |This will match word or words at the end of a line. [131051010010] |SSH to decrypt encrypted LVM during headless server boot? [131051010020] |When I installed Ubuntu 10.04 and, now, 10.10, I was offered the option of enabling "encrypted LVM" for my hard drive. [131051010030] |After choosing that option, I am prompted for my password during boot to decrypt the LVM. [131051010040] |Now, I am thinking about setting up a headless server that runs Linux (not necessarily Ubuntu), but I am worried that since the server is headless I won't be able to decrypt it during startup. [131051010050] |Would I be able to SSH in during boot to enter my password for the encrypted LVM? [131051010060] |If so how do I set it up? [131051010070] |Or is there another solution? [131051010080] |Again this question is NOT specific to Ubuntu. [131051010090] |Thanks. [131051020010] |I think early-ssh provides what you're searching for: [131051020020] |There is already a .deb package available, so you're probably fine with Ubuntu. [131051030010] |What are your favorite *painful* Unix moments. [131051030020] |How about sharing your favorite lessons learned moments? [131051040010] |When I first started working as a user consultant for the university I was attending, I was given limited sudo rights to help students who had lost/forgotten their passwords. sudo passwd was my new friend. [131051040020] |An hour after my orientation, my curiosity got the better of me and I typed in sudo passwd and stared in horror at the prompt for a new password. [131051040030] |I was a bit scared to ^C my way out of it, thinking (erroniously it turns out) that I might leave the account in question in a transient state, so I entered a password and immediately walked up stairs to the hallowed 2nd floor domain of the campus SuperUser and asked if he would like to know the root password of the main system. [131051050010] |Back in the mid to late 90s, a friend of mine and I were discussing the folly of rm -rf * and at what point a Linux box would go belly up. [131051050020] |We got into statically linked versus dynamically linked libraries and I posited that the system could live quite well without /lib and then proceeded to rename it on my workstation. [131051050030] |Bad things happened, but we were left with several open console windows with which to try and fix the damage (shutdown wasn't an option anymore). [131051050040] |None of the editors would run. [131051050050] |It is amazing the esoteric uses you can find for the echo command. [131051060010] |Trying to get the Xwindows driver for my Nvidia card working when Fedora initially released the Nouveau driver. [131051060020] |I had downloaded the Nvidia source to compile and install myself as I had many times in the past, but this release, I could just not get it to work. [131051060030] |Therewas quite a few steps to find in the Fedora Forums to completely disable the Nouveau driver, and get the Nvidia driver working. [131051060040] |Quite painful to say the least. [131051070010] |Well, I've tried several things that probably shouldn't be tried. [131051070020] |For example: [131051070030] |
  • I tried to compile my own kernel on Ubuntu. [131051070040] |I used make oldconfig &&make menuconfig &&make and ended up with lots of kernel panics because I'd done all sorts of things in the make menuconfig stage. [131051070050] |I also tried to apply the PaX/grsecurity patch at one point. [131051070060] |I did successfully run a kernel when I copied my config from /boot to /usr/src/linux but that's the only time it has ever worked well... warning: Ubuntu especially patch kernels and sometimes other things don't work if you run a vanilla kernel.
  • [131051070070] |
  • I tried to get packet injection working on an intel wireless 3495 card. [131051070080] |Basically it's impossible (or was at the time) but I did all sorts of things including replacing kernel modules and compiling experimental subsystems. [131051070090] |Another warning: patience is a virtue. [131051070100] |Wait for your distributor to ship it, then use it, or alternatively, find a LiveCD like Backtrack!
  • [131051070110] |But by far the most disastrous thing I have ever done was to try to install SELinux on Ubuntu. [131051070120] |I tried this because I've never liked AppArmor (and it wouldn't let me print). [131051070130] |It should be just a few apt-get's but the result is you end up unable to log in because the policy wouldn't let me. [131051070140] |The only way out of it was to disable selinux via the kernel command line and to leave it that way. [131051070150] |Turns out debian weren't massively interested in packaging it... [131051080010] |Not really my moment, but someone else's. [131051080020] |Back when I worked at a nuclear sciences research facility we used to run a number of SunOS, Ultrix and Linux computers and researchers had to share the CPU on those machines. [131051080030] |As individual research groups got their own research grants they purchased their own computers, mostly SparcStations and they did the system administration themselves. [131051080040] |SunOS used to ship with the OpenView desktop and a nice file manager, this is what it looked like: [131051080050] |Most of our researchers were running as root, and more than once we had to reinstall their operating systems because someone had decided to tidy-up the root directory and moved /bin, /etc, /tmp and everything else that cluttered the view into either the Trashcan or some subfolder. [131051080060] |Other users chose to tidy up the /bin directory and remove any command they did not know. [131051080070] |The lucky ones had back ups, most had purchased a tape drive, but did not have a tradition of running backups themselves. [131051090010] |Makefile: [131051090020] |Which, of course, makes make clean wipe your source code instead of just object files. [131051090030] |Lesson: use version control. [131051100010] |I deleted /etc and then recovered it. [131051100020] |I don't think I learned my lesson... [131051100030] |I've had to recover from a deleted /bin too. [131051100040] |Seems to happen when I've been working with a chroot. [131051110010] |Had a friend run :() { :|:&}; : on a remote server where we didn't have console access to. [131051110020] |Couldn't reboot it, completely frozen, production server. [131051110030] |Broken down (by request) to make it a bit more readable. [131051110040] |It might be easier to look at it as [131051120010] |A long time ago, I was installing MkLinux on my Mac, and I wanted to replace the file that governed command processing (not the shell, something more basic, don't remember quite what anymore). [131051120020] |The instructions said to do mv x y, so I decided to be cautious and started with rm y. [131051120030] |The intention was to mv x y afterwards, but of course that didn't work. [131051120040] |I reinstalled. [131051130010] |Not that painful... [131051130020] |But a fun little moment: [131051130030] |I've mistyped ls as sl and found out that the sysadmin had something installed for such case. [131051130040] |(already available in Debian, Ubuntu, Gentoo,... repositories) [131051140010] |When my University decided to switch the wireless network to use proprietary Cisco LEAP authentication... [131051140020] |Started a very long battle that ended well enough. [131051140030] |Wrote up documentation for others who wanted to run Linux and have access to the internet. [131051140040] |Six months later they decided to add PEAP support as well. face slap [131051140050] |It is my favorite because I won. [131051140060] |I got it to work. [131051150010] |vi and CAPS-LOCK vs. /etc/passwd [131051150020] |
  • Connect to an old Solaris box using and old serial terminal which doesn't refresh the screen correctly.
  • [131051150030] |
  • su -
  • [131051150040] |
  • vi /etc/passwd. [131051150050] |There is no vipw, and "we're just making minor edits" anyways.
  • [131051150060] |
  • Hit CAPS-LOCK key and don't notice.
  • [131051150070] |
  • Hit 'j' a couple times to scroll down. [131051150080] |Ignore the fact that you actually just typed J ("Join"), which combines this line with the next line. [131051150090] |The serial terminal screen was not refreshing correctly, so you didn't see that you just combined the first 5 lines into one Loooooong line, thereby corrupting the first 5 users ('root', 'daemon', etc).
  • [131051150100] |
  • Finish your OTHER intended edits to the file, way down at the bottom.
  • [131051150110] |
  • Save file.
  • [131051150120] |
  • Log out.
  • [131051150130] |I did this once. [131051150140] |Amazingly, the system remained functional for months. [131051150150] |Cronjobs ran fine, no errors stood out in the logfiles. [131051150160] |We didn't notice this problem until we rebooted the system months later and couldn't log in at the console. ps showed a bunch of jobs owned by UID '0' not by user 'root'. [131051150170] |You could not log in as root, nor run su or su -, and there was no sudo on this box. [131051150180] |There was no floppy drive, the CD-ROM was busted and no USB ports (so no external CD-ROM). [131051150190] |Single user mode did not work, because you need to type in the password for root, and that comes from /etc/passwd . [131051160010] |While on 2nd year of studying computer science we were given a homework to write a program in C that would spawn a number of subprocesses with fork and make them communicate with pipes in a "circle" and figure out which one should be the "leader". [131051160020] |We were still quite noobs back then and most of peple didn't have any linux machines, so we worked on our accounts on our faculty's main server (which was hosting official site and staff accounts and sites as well). [131051160030] |Most of people wrote forkbombs at some stage of trying to do the homework. [131051160040] |Over a half of my group got to the abusers file. [131051160050] |That was the highest load on that server in a looong time :) [131051170010] |I had two drives installed at one point and had the root filesystem of the second drive mounted in a directory within /mnt. [131051170020] |I was in that directory and tried to delete var but ended up typing rm -rf /var instead. [131051170030] |Some instinct seemed to kick in that said var must be preceded with a slash! [131051170040] |When I realised what I'd done I immediately hit Ctrl-C but it was too late. [131051170050] |My rpm database had long since left the building. [131051170060] |I spent ages getting everything back to normal. [131051170070] |Now for the painful part. [131051170080] |I go back into that directory in /mnt to resume what I'd been doing. [131051170090] |What do I type? [131051170100] |Well, let's just say that instinct kicked in again. [131051170110] |At least I was able to restore the system a lot quicker the second time ;) [131051180010] |Surprised nobody else has mentioned this one yet: [131051180020] |(While attempting to remove all hidden files and subdirectories, completely forgetting that it will recurse into . and ..) [131051190010] |I meant well, I really did. [131051190020] |Trying to chmod recursively a directory and ended up swapping ./ with /. [131051190030] |As root of course, because only with root can true pain (and thus enlightenment) be achieved. [131051200010] |As root of course.... [131051210010] |and [131051210020] |when DIR was not set! [131051220010] |Or another experience, how to feel really stupid in a few easy steps that don't seem all that stupid individually. [131051220020] |Step one: establish an account for the kid, in case he wants to use a Linux box. [131051220030] |Give it a trivial password, since after all this is a home system and isn't exposed to the net. [131051220040] |Step two: allow time to elapse, so you don't remember step one. [131051220050] |Step three: open the SSH port in the firewall (actually the NAT on the router) in order to ssh in. [131051220060] |After all, my accounts have pretty good passwords, and it isn't like there's anything tremendously valuable. [131051220070] |Step four: get notification from ISP that there's some sort of DOS activity going to a Swedish site. [131051220080] |Assume it's probably the Windows boxes, and examine and harden them. [131051220090] |Step five: get notification from ISP that it's still going on. [131051220100] |Ask for some detail, get IP address of Swedish site, fire up Wireshark, find which box the attack is coming from. [131051220110] |Step six: clean up Linux box, feeling stupid. [131051220120] |Find the login came from a Romanian address. [131051220130] |Remove accounts without good passwords. [131051230010] |On a Debian installation back in 1999. [131051230020] |14 floppy disk for the basic installation. [131051230030] |I tried to get xfree86 working. [131051230040] |But X didn't start. [131051230050] |I had to find out the settings of my graphics card (memory, horizontal and vertical refresh rate) which was completely undocumented. [131051230060] |It turned out, 'superprobe' found out the correct amount of internal graphics card memory (1024 kB). [131051230070] |But it took me nearly a week to find out that the resolution setting (1024x768) didn't work. [131051230080] |I had to switch it to 640x480 until the graphics card finally worked (at 1024 x 768... buuuuuug....). [131051230090] |I tried to get the serial port mouse to work on COM1. [131051230100] |So I tried to get the mouse to work. [131051230110] |Reading a book (back then had no usable hispeed internet), tried with [131051230120] |And it didn't work and didn't work. [131051230130] |It took me nearly another week to find out this was because i needed to type the S is uppercase, not lowercase... [131051230140] |It was about then when i finally realized what 'case-sensitive' really means. [131051240010] |A simple halt recognizing some seconds later that I'm not on a local shell and having no possibility to power on the production server again. [131051240020] |Lessons learned? [131051240030] |The prompt of the machine now looks like [131051240040] |[ --> root <-- @kompost:/home/echox] # [131051240050] |with some nice red markup ;-) [131051250010] |I wiped the partition table of my main drive by accident, thinking I was working on another drive. [131051250020] |Scrollback, careful use of df, memory, and luck I was able to recreate it exactly, rewrite it, reboot, and hope... [131051250030] |And it worked. [131051260010] |I remember trying to send a SysRq key sequence to a remote machine... [131051260020] |...but it was captured by the local one. [131051270010] |Company that i used to work for had its product running on SCO. [131051270020] |I was doing some debugging about application getting very slow on our demo server and at the same time there was a bunch of customers being given a demo / lecture about upcoming new features. [131051270030] |So, i ran the application that used to get stuck.. did my stuff on it to verify the root cause but since it was still "stuck", i tried to kill it: [131051270040] |pkill -9 mytestapplication [131051270050] |What i did learn was that pkill doesn't do exactly the same on sco as it does on linux =) [131051270060] |... [131051270070] |It basicly kills everything the user has access to, and with root .. its everything =) [131051280010] |Back in the day you had to do erase the first 512 bytes of a partition to properly format FAT drives from Linux. [131051280020] |This is done using the dd command. [131051280030] |dd if=/dev/zero of=/dev/hda1 bs=512 count=1 [131051280040] |Except the FAT partition was /dev/hdb1 [131051280050] |I didn't realize what happened until after I rebooted. [131051280060] |Luckily I was able to recover it by re-installing Lilo, or something. [131051290010] |Twenty minutes ago, I was painstakingly recreating a complex directory structure from files I had one my other PC. [131051290020] |I decided to run du to see if it was near completion. [131051290030] |Given the size, I knew it would take few minutes, so went to get some coffee. [131051290040] |On my return I noticed, to my severe dismay, that instead of running [131051290050] |I had absent-mindedly run [131051300010] |I was once developing a device driver for Unix. [131051300020] |It had a pointer problem and during testing it started to write off the end of an array in kernel memory. [131051300030] |I was slow to spot this and didn't hit the reset button immediately. [131051300040] |The driver had scribbled all over the disk buffer cache which was then flushed to disk before I hit reset. [131051300050] |A lot of the blocks were inodes and directories, and I ended up with a totally trashed filesystem. [131051300060] |I think 6000 orphaned files were put into lost+found before I gave up and reinstalled. [131051300070] |Fortunately, this was only a test system, not my workstation with all my files on it. [131051310010] |This happened to me last year. [131051310020] |I was removing some files from the server using a temporary variable: [131051310030] |rm -rf ${prefix}* [131051310040] |Guess what?? [131051310050] |The variable $prefix was not defined! [131051310060] |You can imagine the disaster... it resulted in some very critic files deleted. [131051310070] |I almost broke the Control-C and ran to the CPU to remove the network cable!! [131051310080] |Hahaha I'm sure someone had already done this... [131051320010] |Mine was chmod -R 777 /: after that I couldn't figure out how to restore the permission on the whole filesystem and then I reinstalled the OS. [131051320020] |Never did that again (and still don't know how to restore such a situation). [131051330010] |I was a lab assistant for a linux class. [131051330020] |One of the students, called me over because she could no longer su - because she was getting permission denied. [131051330030] |OK, she's misremembered/mistyped the password. [131051330040] |Reboot into single-user mode and reset. [131051330050] |What?! su STILL doesn't work?! [131051330060] |It MUST bow to my will! [131051330070] |So I reboot into single user mode to find out what she did. [131051330080] |I realized that she ran chmod -R 777 /var/www/html/drupal-6.19 / [131051330090] |Note the space between the directory name and the final slash. [131051330100] |After a few minutes of "I really don't want to have her reinstall, so what is this doing and how.", I managed to find that /bin/su now had file permissions of 777. [131051330110] |That can also be read as file permissions of 0777, which removes the setuid bit from /bin/su. [131051330120] |A quick chmod u+s /bin/su and I was a hero. [131051340010] |I was curious if chmod 000 / would work. [131051340020] |Well, flawlessly. [131051340030] |Few minutes later I was searching for rescue CD. [131051350010] |The first time I installed GNU Linux on my desktop... [131051350020] |I installed Debian, no help, I only installed the basic system, no GUI... and I was like: [131051350030] |"OMFG OMFG WHAT I HAVE TO DO NOW?... [131051350040] |I will need to back to Windows" [131051350050] |but then I remembered how to install packages (first time in GNU Linux, only a jose@debian:$ output and only readed some things from Debian) and the name of an IRC Client: IRSSI and the name: GNOME and then I installed them... since that day, I install IRSSI and GNOME in every machine... [131051350060] |It feels... good being experimenting with your computer xD [131051360010] |First one [131051360020] |One time, I had defined an alias to help me cleaning temp files : [131051360030] |and of course one day, when I had forget what the alias was doing I mistyped : [131051360040] |I think I've lost a good couple of seconds to realize what was happenning... :( [131051360050] |Second one [131051360060] |I was working as usual with my Mac laptop and my Ubuntu desktop. [131051360070] |When I plugged the external HD of the Mac (HFS+ filesystem) in Ubuntu, I noticed that the owner was ????? : my UID was different on my Mac and on my desktop so since I wanted a nicer output with ls -l, I decided to change that. [131051360080] |So I modified the UID on the mac and launch a big chown -R * on the HD from Ubuntu. [131051360090] |The only thing that I didn't know was that the HFS+ driver for linux was not stable. [131051360100] |From this day, I hadn't been able to mount this HD on linux or on mac again... [131051370010] |I mapped the CapsLock to ESC on the entire system. [131051370020] |When I did it, the Capslock was on. [131051370030] |A reboot removed the permanent state of CapsLock. [131051370040] |It was mapped to ESC [131051370050] |It wasn't really painfull but I felt stupid when I realized what I've done! [131051380010] |My switch from Debian to Ubuntu started the day I tried to delete some files and directories, meaning to type [131051380020] |Unfortunately, I inserted a space between "/var/tmp/" and "*" and even worse, I was in the root of the filesystem. [131051380030] |Please don't try that at home! [131051390010] |In the computer labs when I was in college, they had a screen saver that simulated a bunch of balls that would float back and forth. [131051390020] |They pulled on each with simulated gravity. [131051390030] |Once, while I was messing around with the settings, it crashed with the error Error: force on balls too great [131051400010] |Somehow managed to unmount /dev and thought I would be screwed forever if I rebooted the machine. [131051400020] |Nerve wracking hour ensued trying to figure out if it would be safe to reboot it. [131051400030] |It was, nothing bad happened. [131051410010] |Many web apps like magento or eZ Publish have a var/cache/ folder and a way to clear the cache that is faster than going in the app backend is to do this: [131051410020] |After doing this a couple of times, it is scientifically proven that you always end up: [131051410030] |
  • either doing this in the root of your server;
  • [131051410040] |
  • or add a / before var Lesson learned : create an alias for this command with an absolute path in it.
  • [131051420010] |As root on Solaris, [131051420020] |...and everything went down. [131051420030] |My friend got fired because of this. [131051430010] |Last year, a colleague of mine was using one of our linux workstations to create copies of flash disks using the dd command. [131051430020] |He accidentally typed something similar to the following: [131051430030] |By the time he realized his mistake - overwriting the machine's hard disk instead of the flash drive - the machine was already hosed. [131051430040] |We had to rebuild the box, which incidentally was also the machine hosting all of our development VM's at the time... [131051440010] |There's a neat trick to do the equivalent of dirname and basename, respectively, in Bash: [131051440020] |Not so funny when $path contains a trailing slash... [131051450010] |My favourite moment was, when a co-worker, who is an emacs user, wanted to edit an important file. [131051450020] |Because emacs is too much to type he had setup an alias for emacs: [131051450030] |Under the influence of not enough or too much coffee he of course mis-typed em ... [131051450040] |Well, this is just another reason to use vi ... ;) [131051460010] |I don't keep track of errors on my own boxes, but from the last 15 years here are my two work fatalities: [131051460020] |1995: Standard 'rm -rf as root' failure on a single box (not my design!) acting as a combined NIS master server + sole DNS server for the company + primary SMTP/POP3 server for the company. [131051460030] |It was SunOS 4.1.3_U1 as I recall. [131051460040] |Unsurprisingly, like the witness to a horiffic crime, I do not remember the ensuing 48 hours. [131051460050] |1998: Ran newfs (SunOS) on a production AFS (now OpenAFS) file server instead of the replacement we were standing up. [131051460060] |Spent the afternoon and night restoring from tape. [131051470010] |Wanted to make an archive: [131051470020] |Of course, mydir/* expanded to mydir/myfile.cpp mydir/myfile.h [131051470030] |Remember that the archive name follows the -f option of tar! [131051480010] |My favorite is when I was building the new Solaris system for an Oracle database installation. [131051480020] |Everything was in place including the high priced oracle consultant right in the middle of the DB optimization work he was doing. [131051480030] |I was in the server room checking on another server, when I tripped over the power cord to the server. [131051490010] |1st ex employee: how do I do (something trivial)? [131051490020] |2nd ex employee: sudo rm -rf / 1st ex employee: haha ok ... [131051490030] |1st ex employee (having forgotten that he'd just sudo'd something else, so it didn't ask for his password again) : oh F**K!!! [131051500010] |A while ago, I needed to do some extensive configuration on one of my machines, that mostly involved editing bunch of files in /etc. [131051500020] |I decided to be really careful about it, so I created an etc directory in my $HOME, copied the files that needed editing in there, spent couple hours doing the edits. [131051500030] |I carefully checked all the files, made sure that all the edits were exactly the way they were supposed to be, logged in as root and copied the edited files back to /etc. [131051500040] |By then, it was very late at night. [131051500050] |Still as root, I decided to clean up, and instead of rm -rf etc, I typed in rm -rf /etc. [131051500060] |I did not get much sleep that night. [131051510010] |I was on the phone with a colleague who was out at a customer site. [131051510020] |She was working on their systems and I was telling her stroke for stroke what to type, she misheard me when I told her rm -rf .??* and typed rm -rf .?*. [131051510030] |But she wasn't in the directory she had told me, she was in the root directory. [131051510040] |Wiped not only the dot files, but the entire OS. [131051510050] |Back when I was "learning as a sysadmin", I was writing my own adduser script (didn't have it on early SysV). [131051510060] |A shell error in the script (cat /etc/passwd; echo ...) >/etc/passwd which of course wiped the passwd file and then, by accident, I hit Ctrl-D to exit the su shell. [131051510070] |Had to go in to the office at 1am Saturday morning to get the boot diskettes. [131051520010] |I was once trying to zero out a USB thumbdrive using dd. [131051520020] |Needless to say, when tty1 started spitting out ReiserFS errors from my root partition, I had to reinstall... [131051530010] |Debian dist-upgrade to unstable (or was it testing?) on a remote production server. [131051530020] |Ignored warning about libc switching to nptl threads. [131051530030] |Not sure where installation actually failed, but I left with one root console on dial-up line with every single app exploding. [131051530040] |Just one running ssh and bash. [131051530050] |Had a lot of fun of recovering it. [131051530060] |Uploaded statically linked dpkg, rolled back libc, built custom kernel with RAID support. [131051530070] |I think that took around 3 hours with my dial-up line. [131051530080] |When I finally rebooted it, fsck took like 10 minutes. [131051530090] |Quite painful 10 minutes I should say. [131051540010] |This does not remove the repository. [131051540020] |This removes everything that is not in the repository. [131051540030] |After trying to get rid of the existing repo and then start source control again (on the completed first version of a project), these two commands nuked my entire code. [131051550010] |Installing debian (with net-install) on a computer and realise after rebooting that I had somehow skipped the part where one is supposed to choose which packets to install. [131051550020] |Sure, a non-graphical system with basically only pwd, ls and cd is working just fine ;). [131051560010] |Installing OpenJDK on a Netbsd Sparc64 Server [131051560020] |I am currently working on a project that involves running the lift framework on a sun sparc64 architecture. [131051560030] |Due to limited support from more popular unix distros, I am running NetBSD 64-bit on the system. [131051560040] |Before i can even tackle trying to install lift, I have to be able to install java on this system. [131051560050] |I found that OpenJDK is what I should be using. [131051560060] |Through all my digging, I can't seem to get a straight answer on compatibility or installation for this specific setup. [131051560070] |Also if i am to find a compatible version, what kind of route am I to take in terms of installation (i.e. pkg_add, pksrc or compiling the code myself) Can anyone shine a light on the subject or am I just on a wild goose chase to nowhere? [131051570010] |Best Linux productivity tools [131051570020] |In your hands-on experience, what are the best Linux productivity tools, in particular I'm looking for tools (command-line) that can help me aggregate a lot of log files in one view (something like tail -f x 20 ). [131051570030] |I am also looking for a tool, or tools for effectively monitoring tenths of processes without having to run "jobs" or "ps" command every n secs x num of procs. [131051570040] |Any other tool recommendations that help automate sysadmin tasks on Linux are very welcome. [131051580010] |Passing a variable to a bash script when sourcing it in another bash script? [131051580020] |Suppose I have in main.sh: [131051580030] |and in install.sh: [131051580040] |This is supposed to echo /home/user/, but it echoes nothing. [131051580050] |Why? [131051590010] |I see three errors: [131051590020] |
  • Your assignment line is wrong: [131051590030] |When you assign to a variable you don't include the $; it should be: [131051590040] |
  • You're missing then; the conditional line should be: [131051590050] |
  • You're not quoting $NAME, even though it has spaces. [131051590060] |The source line should be: [131051600010] |Michael Mrozek covers most of the issues and his fixes will work since you are using Bash. [131051600020] |You may be interested in the fact that the ability to source a script with arguments is a bashism. [131051600030] |In sh or dash your main.sh will not echo anything because the arguments to the sourced script are ignored and $1 will refer to the argument to main.sh. [131051600040] |When you source the script in sh, it is as if you just copy and pasted the text of the sourced script into the file from which it was sourced. [131051600050] |Consider the following (note, I've made the correction Michael recommended): [131051610010] |Creating bootable usb stick with NetBSD installer on Linux [131051610020] |How can I create bootable usb stick with NetBSD installer on Linux? [131051610030] |I tried to use UNetBootin, but on download list there is only 4.0 version and when I select my ISO with 5.1 version it doesn't work (it create only few config files) . [131051610040] |Other instruction that I found was NetBSD specific and I don't have NetBSD installed... [131051620010] |If you have Ubuntu installed, try [131051620020] |Select your ISO and the USB drive, push the button... done! [131051630010] |How to place an application on the second monitor with awesome-wm? [131051630020] |I recently got a second monitor at work and want to configure all with my window-manager: awesome. [131051630030] |I run into a problem to put some applications on a tag on a screen. [131051630040] |For example I have a rule for urxvt, to put it into tag one on the first screen: [131051630050] |That works fine, as long my mouse-cursor is on the first monitor. [131051630060] |If I move my cursor on the second screen and start an instance of urxvt, it will be placed into the actual tag on the second monitor. [131051630070] |Same, if I configure the app for an tag on the second screen, when it don't work if my mouse-cursor is on the first screen. [131051630080] |How can I fix this? [131051640010] |This depends on the version of awesome you're using: [131051640020] |

    awesome 1.x

    [131051640030] |Set the screen variable in the rule: [131051640040] |

    awesome 2.x

    [131051640050] |Set the screen property on the client in the hook_manage function: [131051640060] |It appears from your code sample that you're using awesome 1.x; as a sidenote, 1.x is now really old, so you might want to look into upgrading to 2.x, which uses Lua instead of a custom configuration format [131051650010] |How can I serve a Kickstart file over the network without a DHCP server? [131051650020] |I want to install CentOS 5.5 on two systems. [131051650030] |I have a kickstart file. [131051650040] |I would like to install CentOS on a system using this kickstart file. [131051650050] |I'm reading the instructions provided by fedoraproject.org and RedHat.com, but they suggest using a DHCP server. [131051650060] |I don't want to set up a DHCP server right now, and I can't have DHCP traffic on this LAN. [131051650070] |How can I make this kickstart available over the network without using DHCP to point to the file initially? [131051650080] |I've heard that I can make the Kickstart file available using HTTP, FTP or NFS. [131051650090] |How can I configure the RedHat installer to have an IP address on the network and grab the kickstart file from a remote server? [131051660010] |The dhcp server doesn't actually serve the file. [131051660020] |The dhcp server assigns an IP address to a host (pxe client) which lacks an operating system when it boots. [131051660030] |In addition to the IP address, the dhcp server can tell the pxe client that it should contact a separate server for a boot loader and then the pxe client downloads the boot loader (usually using tftp) loads it, and the boot loader can be configured to download the actual kickstart file using one several protocols, including http and nfs. [131051660040] |If you don't want to use dhcp, you could always boot the host off of a cdrom, and at the prompt where you usually just type linux to start the attended installation process, you can pass in your kickstart file as a kernel option along with a static networking configuration. [131051670010] |Trouble getting busybox switch_root to work [131051670020] |I'm working on an embedded ARM Linux system that boots using initramfs. [131051670030] |(Here's some background from a couple earlier questions, if you're interested.) [131051670040] |So far, thanks in part to help received here, I can boot the kernel via TFTP with an embedded initramfs. [131051670050] |The MMC driver detects an SD card containing a new root filesystem, which I can then mount. [131051670060] |However, I cannot get the final step, using busybox switch_root to switch to the filesystem on the SD card, to work. [131051670070] |At the initramfs shell prompt, I think this should make the kernel switch to the new filesystem: [131051670080] |However, it just makes busybox (to which switch_root is aliased) print its man page, like this: [131051670090] |I think the -c option is correct, since it's the same as what is contained in the example, and /dev/console exists. [131051670100] |/mnt/root also exists. [131051670110] |The init executable exists: [131051670120] |But here's something strange: [131051670130] |That's totally mystifying. [131051670140] |I'm not sure where I'm going wrong. [131051670150] |I've looked at the source, which is at http://git.busybox.net/busybox/tree/util-linux/switch_root.c?id=1_17_4 [131051670160] |It's not just the init.sysvinit executable. [131051670170] |I can't execute anything from the SD card. [131051670180] |For example: [131051670190] |Anyone have a clue what's amiss here? [131051670200] |I thought it might be some problem with mounting the card noexec, but I believe exec is the default, and I tried passing the exec option explicitly at mount with no success. [131051680010] |The reason that switch_root is not working on the command line is this code in busybox: [131051680020] |You are not PID 1, so you are falling though into this bb_show_usage. [131051680030] |The implication is that the switch_root command in your initramfs init script should run switch_root with exec. i.e. [131051680040] |The other issue with your "not found" errors is likely because the shared libraries needed by the executables are not found, because the initramfs root filesystem does not have them. [131051680050] |If you can get switch_root to work with exec, then is likely the "not found" error will go away. [131051690010] |where to start open-source work? [131051690020] |This one got closed: freeBSD or linux or something else? [131051690030] |But I have a sincere question here. [131051690040] |I want to know from the pros what is better for a newbie to start working on. [131051690050] |I want to learn/contribute. [131051690060] |If not the exact answer, please provide some rationale. [131051700010] |I think reading the following two books may be a good start. [131051700020] |Classical Shell Scripting(http://oreilly.com/catalog/9780596005955) UNIX Programming Environment(http://www.amazon.com/Unix-Programming-Environment-Prentice-Hall-Software/dp/013937681X) [131051710010] |The book 'Producing Open Source Software - How to Run a Successful Free Software Project' from Karl Fogel is a good introduction to someone, who wants to start or join an OSS-project. [131051710020] |The book is available on it's website - also as free download. [131051720010] |How to create a new partition on a hard disk? [131051720020] |How do I create a new partition on a hard disk, from the terminal? [131051720030] |I've been reading the man pages for fdisk and mkfs, but they're confusing. [131051720040] |I need to know how to create a new partition on a blank drive, as well as on a drive that already has partitions. [131051720050] |Some colleagues told me the latter isn't possible and I need to format; is that accurate? [131051730010] |If you install GNU parted (libparted), you get an extra command line progam parted. [131051730020] |GNU Parted manipulates partition tables. [131051730030] |This is useful for creating space for new operating systems, reorganizing disk usage, copying data on hard disks and disk imaging. [131051730040] |The package contains a library, libparted, as well as well as a command-line frontend, parted, which can also be used in scripts. [131051740010] |
  • Backup every piece of data you can't afford to lose and don't do this on a mission-critical server.
  • [131051740020] |
  • umount the partition you want to split into two or more parts.
  • [131051740030] |
  • Use resize2fs to free up the desired amount of space at the end of partition.
  • [131051740040] |
  • Launch fdisk.
  • [131051740050] |Unfortunately, this tool doesn't have an option to change the size of partition. [131051740060] |You'll need to delete it first and then create the desired new partitions on the unallocated space left from it. [131051740070] |First re-create the partition you've just deleted with lower amount of allocated space. [131051740080] |Be sure to specify size enough to hold your resized filesystem. [131051740090] |Allocate the rest of unused space as you see fit. [131051740100] |The fdisk tool doesn't touch your partition table unless you specifically say it to do so. [131051740110] |In case of mess up, just terminate it with ^C and start over. [131051740120] |
  • Now that you have you new partitions setup, use an appropriate mkfs command to create new filesystems. [131051740130] |Don't run mkfs on the original partition number -- only on the new ones!
  • [131051740140] |
  • Take extra care at every step as you risk the need start over in case of mistyped command.
  • [131051750010] |Gentoo default application for opening files [131051750020] |On my Gentoo box running without a desktop environment, every time I try to open a file the system tries to open it with Firefox. [131051750030] |I understand that without a desktop environment "open file" cannot function correctly, but why is everything opened with Firefox? [131051750040] |If I want to, can I change it to something else? [131051760010] |Usually this information is handled in 2 places: [131051760020] |
  • Application .desktop files advertise what program can open
  • [131051760030] |
  • MIME database which specifies what application should be used to open file with specific MIME
  • [131051760040] |The MIME database can be customized by editing .local/share/applications/mimeapps.list and .local/share/applications/mimeinfo.cache. [131051760050] |The tool which allows to edit it is xdg-mime from x11-misc/xdg-utils. [131051760060] |Please beware that man states it can be used only from inside desktop session. [131051760070] |Edit Please note that some applications, like Firefox, do not respect the MIME database settings. [131051770010] |Why dm-crypt does not handle write caching properly [131051770020] |One of the well-known properties of dm-crypt is that it do not handle write caching properly and hence it have to be turned off to prevent corruption of filesystems. [131051770030] |As far as I understend it is not shared by all other dm devices (like LVM w/out snapshoting). [131051770040] |My question is wheather it is inherit property of dm-crypt for any reason (I cannot find any but it is possible) or is it simply not implemented (yet?). [131051780010] |extracting "tag" information from git with a shell script. [131051780020] |The vc bundle is a neat little package that extracts information about a git repo for easy insertion into a LaTeX document. [131051780030] |It doesn't currently extract information about whether the current commit is tagged and what the tag name is. [131051780040] |How would I edit the vc script to do this? [131051780050] |And then how would I edit the vc-git.awk script to add an extra line to the generated vc.tex file? [131051780060] |Presumably I want a line that looks like: [131051780070] |but I need an earlier line that tells awk what " Tag " means? [131051780080] |This isn't a question about LaTeX, it is about git, awk and bash... [131051790010] |You can get what commit tag points to by: [131051790020] |Unfortunatly I'm afraid that the only way of checking if commit is tagged it to check all tags. [131051800010] |You can get from a commit to a tag name by using name-rev. [131051800020] |An example: [131051800030] |So to get only the tag: [131051810010] |If commit (HEAD if omitted) has tags, the commit hash will be followed by (tag: name) (and possibly multiple other symbolic references too). [131051810020] |You can pick this out more specifically with [131051820010] |Best way to upgrade vim/gvim to 7.3 in Ubuntu 10.04? [131051820020] |I have to use Ubuntu 10.04 at work, and cant upgrade it. [131051820030] |I'm using Vim/gVim 7.2. [131051820040] |I want to upgrade it to 7.3 (with python and ruby extensions support). [131051820050] |Which is the best way? [131051820060] |Add an entry in sources.lists and install a 7.3 vim/gvim package from it, or build from source? [131051820070] |Which disadvantages I have from each approach? [131051830010] |Build from source. [131051830020] |It will be quicker. [131051830030] |Trying to both find and enable a repository for a one-off install like that will just cause you headaches further down the line. [131051840010] |The first place to check is if there's a backport, but there isn't, which isn't surprising since maverick has vim 7.2 too. [131051840020] |The next thing to try is if someone's put up a repository with vim 7.3 packages somewhere, preferably a PPA. [131051840030] |There are many PPAs with vim, including several with 7.3 (not an exhaustive list). [131051840040] |If you don't find a binary package anywhere or don't like the ones you find, the next easiest step is to grab the source package from natty, which has vim 7.3. [131051840050] |Download the source package (.dsc, .debian.tar.gz and .orig.tar.gz), then run [131051840060] |If all goes well, you'll have binary packages for your distributions. [131051840070] |If you run into missing dependencies or compilation errors, this has to be solved on a case-by-case basis. [131051840080] |The next thing to try is to compile the upstream 7.3 source with the packaging from your Ubuntu version. [131051840090] |This gives you a nice and clean package, but it's a little more involved, so if you don't feel confident in doing this without instructions I recommend you just compile the upstream source. [131051840100] |If you end up compiling the upstream source, by default, you'll end up with the files under /usr/local, and it won't be easy to uninstall them, or even to know what you have. [131051840110] |Whenever you install something without using the package manager, I recommend installing into a separate directory structure and creating symbolic links in /usr/local (or ~/usr or whatever). [131051840120] |Stow is nice for that: [131051840130] |
  • Install under /usr/local/stow (or ~/usr/stow or wherever). [131051840140] |With many programs, you can use something like ./configure --prefix=/usr/local/stow/vim-7.3. [131051840150] |This will put the main binary at /usr/local/stow/vim-7.3/bin, and so on.
  • [131051840160] |
  • Run stow vim-7.3 from the /usr/local/stow directory. [131051840170] |This creates symbolic links in the “normal” directories, e.g. /usr/local/bin/vim -> ../../stow/vim-7.3/bin/vim.
  • [131051840180] |
  • If you ever want to uninstall this program, just run stow -D vim-7.3 to remove the symbolic links, and delete /usr/local/stow/vim-7.3.
  • [131051840190] |There is also xstow which is a similar, but more powerful programs (one of its benefits is that it can deal with conflicts). [131051850010] |Can someone diagnose this JACK error message? [131051850020] |OK. [131051850030] |I start JACK without starting the JACK server. [131051850040] |I get: [131051850050] |Then I press the 'play' button. [131051850060] |I get: [131051850070] |If I press nothing, the above read error message repeats infinitely. [131051850080] |I installed JACK from repositories and this is what I got. [131051860010] |Wireless card wont connect right away [131051860020] |Hi, [131051860030] |I have a netgear wg311 wireless card on my debian machine. [131051860040] |I have it connected using wpa_supplicant. [131051860050] |When i type this. [131051860060] |i get this [131051860070] |but connection doesnt work for 5-10 minutes. [131051860080] |Anyone know what might be causing this [131051860090] |/etc/network/interfaces [131051860100] |error message on startup [131051860110] |and it trys to DHCP DISCOVER 255.255.255.255 at 6 different ports. [131051870010] |As last quote says, you have "dhcp", when you should have "manual" for wlan0. [131051870020] |Try changing [131051870030] |iface wlan0 inet dhcp [131051870040] |to [131051870050] |iface wlan0 inet manual [131051870060] |in /etc/network/interfaces. [131051870070] |Another choice is to use manager for network connections, for example Gnome's Network Manager or WICD. [131051880010] |Gnome - windows always open top left [131051880020] |I find this a highly annoying "feature" on a wide screen monitor that my mostly used apps - terminal and gedit always open directly under the top-left corner of my screen and I have to drag them to my eye position each and every-time. [131051880030] |I have tried installing the CompizConfig Settings Manager and using the feature to position windows centre, but this has had no effect - the force feature here isn't working for me either: [131051880040] |Window Management -> "place windows" -> Fixed Window Placement -> Windows with fixed positions example: gedit 200 200 keep-in-work-area-to-yes [131051880050] |I can use e.g. gnome-terminal --geometry=140x50+50+50 for the terminal but this doesn't work for gedit. [131051880060] |Any ideas? [131051880070] |Thanks [131051890010] |The Compiz “place windows” feature works for me. [131051890020] |It won’t work if you just use gedit, though. [131051890030] |Try title=gedit: [131051900010] |Execute a file in an application based on the file's extension in bash [131051900020] |After reading this answer about a zsh feature: [131051900030] |If a given extension has a suffix alias, you can execute a file with that extention directly, and ZSH will launch the given program and pass the filename as an argument. [131051900040] |Is there something similar to bash? [131051900050] |That is, if a given file has an extension, how to directly execute that file, automatically launching a program just by calling the file's name? [131051900060] |So doing [131051900070] |program /path/to/foo.ext [131051900080] |/path/to/foo.ext [131051900090] |would equivalent to the same zsh feature? [131051900100] |Is this feature available in newer versions of bash? [131051910010] |While I am not familiar with every feature of Bash, I do not believe this is a built-in feature of the Bash shell. [131051910020] |I was unable to find this feature in the relevant sections of the Bash manual. [131051910030] |You may be able to cobble something together using trap. [131051910040] |From help trap: [131051910050] |Trap signals and other events. [131051910060] |Defines and activates handlers to be run when the shell receives signals or other conditions. [131051910070] |Thus by using the command: [131051910080] |I can ensure that my_function is called whenever a command fails. my_function could be a function that parses the previous command, looking for known extensions and calling the appropriate command based on that extension. [131051910090] |Depending on your interest, writing such a function may be more or less interesting than moving to the z shell. [131051920010] |You could use fish instead of Bash. [131051920020] |It has the functionality you're searching and lots interesting more. [131051920030] |For your example. [131051920040] |Just type in [131051920050] |and it opens the pdf file with the associated program. [131051930010] |If you are on Linux, you could try setting up binfmt misc. [131051940010] |cursor position after pasting in vi / vim [131051940020] |One thing that has always bothered me in vi / vim: [131051940030] |If I "yank" (a.k.a. "copy") some text, then move to another place in the file and do a "paste", my cursor remains at the beginning of the text I just pasted. [131051940040] |This is different from what most modern editors do, which is put the cursor at the end of the text I pasted. [131051940050] |For example, assuming the "copy buffer" contains the word "awesome" which I want to paste after the word "an" in the phrase: [131051940060] |In, for example gedit, after the paste: [131051940070] |In vi: [131051940080] |Can I change vi to act like (for example) gedit in this regard? [131051950010] |I'm pretty sure this is by design. [131051950020] |If you paste using "p" (lower case P), it's supposed to paste after the current position or line. [131051950030] |However, if you paste using "P" (capital P), then it pastes before the current position or line. [131051950040] |If your desired behavior is to have the cursor be at the end of your newly pasted text, try getting in the habit of using "P" instead of "p". [131051950050] |I bet if you dug deep enough, you could find a vim recipe to put in your .vimrc that would always move the cursor to the end of your paste, even if you use "p". [131051960010] |In vim, use gp and gP instead of p and P to leave the cursor after the pasted text. [131051960020] |If you want to swap the bindings, put the following lines in your .vimrc: [131051960030] |Strangely, in vim, p and P leave the cursor on the last pasted character for a character buffer, even in compatible mode. [131051960040] |I don't know how to change this in other vi versions. [131051970010] |What would cause "crossover" between two USB2 webcams when using motion? [131051970020] |I am using the Motion package for linux to act as a security system with two Microsoft LifeCam HD-5000 webcams. [131051970030] |In general it's working very well but I'm experiencing a weird issue. [131051970040] |Every now and then the feed from one cam will exhibit "crosstalk" or "crossover" from the other cam, in sweeping bars, best described in this image (highlighted in red): [131051970050] |As you can see, the image is a mixed mess of the inside and the outside camera feeds. [131051970060] |I believe this article from Motion's wiki is describing the same issue, however there is no solution there besides: [131051970070] |If you need more than 1 USB camera add extra USB PCI cards to your computer [131051970080] |However that is talking about USB 1.1, and these are USB 2.0 cameras. [131051970090] |Also, I do believe this system has two UCB cards and that the cameras are connected to two different USB busses: [131051970100] |So my questions are: [131051970110] |
  • Does anyone know what could cause crossover like this?
  • [131051970120] |
  • Any other troubleshooting suggestions?
  • [131051970130] |
  • I am guessing I will need to ask the developers of Motion for support, so before I do, can anyone confirm that I do have the cameras connected to two different PCI cards as they suggested?
  • [131051980010] |To the first point: USB1.1 was a lot slower than USB2.0, in most cirumstances. [131051980020] |Note that devices can still connect at the lower 1.1 speed of 12Mbps instead of the faster 480Mbps, but usually when this occurs it's either because the port is autonegotiating low or it is because one of the two devices is really 1.1. [131051980030] |Try disconnecting and reconnecting if you experience this and are sure both are 2.0 and your OS has support for 2.0. (general advice, ya?) ~~ Anyways, that was why they recommended a new card. [131051980040] |So that you could use the full USB1.1 speed per individual camera since the PCI bus is way faster than USB1.1. [131051980050] |But with 2.0 that's not necessary. [dead horse flogged, going on to next topic] [131051980060] |Now onto your device specifically. [131051980070] |You've a Core i5 by most ostensible metrics, namely: Intel 5 / 3400 series PCH and 82801 PCI bridge. (side note: confirmed that he has a Dell Core i5) This particular PCH is also code-named Ibex Peak. [131051980080] |You no longer have an independent southbridge (as it is my understanding) so you're possibly open to new behavior that didn't exist before. [131051980090] |The integrated chipset now handles the USB much closer to the DMA, so I expect that the issue is EITHER with the 5/3400 chipset or that the issue is with the driver. [131051980100] |Either are easy to test, but they do require an initial capital outlay, so that sucks. [131051980110] |Here's my reasoning why I think it's the chipset and not the cameras or drivers: There are known issues with the Intel PCH (I'm going to quote now to save back and forth clicking: [131051980120] |
  • USB ports hang with bulk and control traffic (erratum 7 &Microsoft KB9820911)
  • [131051980130] |
  • Bogus USB ports will be detected at desktop PCH equipped with 6 USB ports (3420, H55) on the first EHCI controller. [131051980140] |This can happen when AC power is removed after entering ACPI S4. [131051980150] |Adding AC power back and resuming from S4 may result in non detected or even non functioning USB device (erratum 12)
  • [131051980160] |
  • Bogus USB ports will be detected at mobile PCH equipped with 6 USB ports (HM55) on the first EHCI controller. [131051980170] |This can happen when AC power and battery are removed after entering ACPI S4. [131051980180] |Adding AC power or battery back and resuming from S4 may result in non detected or even non functioning USB device (erratum 13)
  • [131051980190] |This leads me to believe that adding a new PCI card will improve performance by removing load on the particular USB controller logic, but as a test try moving both the camera's to the same USB hub (matching stacked slots on the motherboard should be sufficient) and see if they exhibit the same problem. [131051980200] |Dollars to pesos says that you'll have the EXACT same issue when you do this. [131051980210] |However, I think it's more likely an issue with UVC drivers on Linux in general with multiple cameras handled by the same controller (as yours is), and not something specific to the hardware. [131051980220] |I just thought I would start with the hardware first to address that particular bit (since it's entirely possible it could be at fault). [131051980230] |Here's a string of related URLS: [131051980240] |
  • http://answerpot.com/showthread.php?1074387-Running+multiple+webcams+on+the+same+hub
  • [131051980250] |
  • http://www.mail-archive.com/linux-uvc-devel@lists.berlios.de/msg05235.html
  • [131051980260] |
  • http://sourceforge.net/projects/mjpg-streamer/forums/forum/739917/topic/2042468 (actually something else to consider)
  • [131051980270] |
  • http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2009x04x30x053208 (old)
  • [131051980280] |
  • http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2009x08x04x191406 (similar problem, new PCI USB)
  • [131051980290] |
  • http://lists.berlios.de/pipermail/linux-uvc-devel/2009-May/004806.html (direction for searching)
  • [131051980300] |
  • http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2009x05x28x183617 (from motion, but older)
  • [131051980310] |Ok, that's enough rambling for now. [131051980320] |Reply comments? [131051980330] |tl;dr: get a USB PCI card and put one camera on there. [131051990010] |Guest Additions in VirtualBox [131051990020] |I'm setting up a development server with VirtualBox. [131051990030] |I've installed Ubuntu 10.10 Server. [131051990040] |I want to use filesharing to setup the files that I need to develop on but it seems that the CD drive is not mounting to install the Virtualbox guest additions. [131051990050] |How can I configure this to setup the file sharing. [131052000010] |If you have Ubuntu in a VirtualBox VM, you can install the guest additions as an Ubuntu package. [131052000020] |Either grab virtualbox-guest-additions or virtualbox-ose-guest-utils and virtualbox-ose-guest-x11 . [131052000030] |The OSE guest utilities are compatible with the proprietary VM and vice versa (at least with respect to common features such as file sharing and pointer grabbing). [131052010010] |No core dump on Ubuntu on a Parallels shared folder [131052010020] |I have an application that I'm working on, and I'm having trouble getting a core dump when it segfaults. [131052010030] |In fact, I'm having trouble getting real core dump files at all. [131052010040] |A simple test case will generate a core dump file, but it's zero length. [131052010050] |I've got ulimit -c unlimited set. [131052010060] |This is 64-bit Ubuntu Maverick. [131052010070] |Any hint what to do next? [131052010080] |Edit: More information [131052010090] |I've just realized that the filesystem the core file is being generated on is a Parallels Shared Folder. [131052010100] |(This Ubuntu instance is running on a Parallels VM on my Mac). [131052010110] |When I run the app from a directory that's on local disk, core file is generated as expected. [131052010120] |So I'll change the question slightly: why isn't it generating the core file on the prl_fs filesystem? [131052010130] |Just curious... [131052010140] |Edit #2: [131052010150] |You'll note that when it generates the zero length core file, it does not print (core dumped). [131052010160] |I did double check my sanity, and yes the zero length core file is really being created. [131052020010] |I couldn't clearly find the underlying reason why, but the zero length core file was caused by trying to create the core file on a Parallels Shared Folder. [131052020020] |I solved the problem by running the application from a local directory. [131052020030] |I suppose another alternative would be to set /proc/sys/kernel/core_pattern to dump core files into a local directory. [131052030010] |What is the difference between CentOS and Windows? [131052030020] |Possible Duplicate: How do I choose between Unix / Linux and Windows in a Server environment? [131052030030] |I need a VPS, and a supplier is providing me a CentOS one at a cheap rate, but I'm a Windows user normally. [131052030040] |I need to know: [131052030050] |
  • What is the difference in usage between CentOS and Windows?
  • [131052030060] |
  • Do all Windows applications run on CentOS as well?
  • [131052040010] |Are you kidding? CentOS is a community-supported, mainly free software operating system based on Red Hat Enterprise Linux. [131052040020] |No, Centos is not windows, CentOS is free, exactly 0 windows applications run on CentOS (without wine). [131052050010] |Windows and CentOS are operating systems - that's pretty much where the similarity ends. [131052050020] |CentOS will not natively run windows programs although you may be able to run some using wine. [131052050030] |You have a steep learning curve if you got with the CentOS vps, you should probably pay the extra and get a windows vps it will likely save you lots in the long run. [131052060010] |How do I choose between Unix / Linux and Windows in a Server environment? [131052060020] |I need a server, and I'm used to windows at home and in the office, but it seems that Unix / Linux is an option, but I don't really know what it is. [131052060030] |I don't know which one to get, how do I choose? [131052060040] |What kinds of questions do I need to ask my host (if applicable)? my system administrators? my programmers? is there anything else I should know? [131052070010] |Ask your programmers what language you need to be using, this is the most important part. [131052070020] |Not all languages work on Unix and Windows. [131052070030] |Take the language information to your Host, and ask them what environment it's supported in. [131052070040] |You, also, need to ask your host whether the Sever will be Managed or Unmanaged. [131052070050] |Managed means if you have any server problems the Host will fix them for you, if you put in a ticket with support (my $dayjob). [131052070060] |Unmanaged means you're on your own. [131052070070] |In the Managed scenario, you will get some kind of web interface control panel, such as cPanel or Plesk. [131052070080] |If you're unmanaged, you should have actual employed system administrators, ask them what they want. [131052070090] |Or you need to be able to be a system administrator yourself. [131052070100] |If both windows, and *nix turn out to be suitable for your needs, go with the cheaper of the 2, if they both cost the same, find out what the admins (including the ones at the host) know better, or which department (windows or *nix) has more admins. [131052080010] |The most important question to ask: [131052080020] |Do you have experience with Linux servers? [131052080030] |If the answer is NO across the board, then go with Windows server. [131052080040] |In this case maintenance costs will outweigh licensing costs. [131052090010] |Is knowing Linux required to learn Unix [131052090020] |Is it required to know Linux to learn other Unix. [131052090030] |I don't know Linux but I am planning to learn Sun Solaris. [131052100010] |From the user perspective, all *nix like systems (Linux, Ubuntu, Red Hat, Sun/Solaris, AIX) are essentially the same. [131052100020] |By this I mean that the commands a user uses most (vi, cat, more, cd, mkdir, rmdir, rm, cp, mv, man) are available and have mostly the same options. [131052100030] |If, however, you want to do system administration they are different; sometimes very different. [131052100040] |As for Unix courses, you'll have to check the course descriptions or ask your teachers. [131052110010] |No, they are similar but there is no dependencies between the two. [131052110020] |So you can learn Solaris without knowing anything about Linux. [131052110030] |On the other hand, I don't think it's a bad thing to know a little bit about how the different versions of unix behave.... [131052120010] |Strictly speaking Linux is a kernel and knowing it won't help that much when targeting Solaris. [131052120020] |However, I guess by Linux you mean Gnu/Linux based distributions. [131052120030] |In such case, Solaris and most of these operating systems share a lot of common or similar code, like Xorg, Gnome, most Gnu utilities, Java, OpenOffice, Apache, openssl, perl, python, sudo, firefox, thunderbird, the gimp, MySQL and plenty of other open source code. [131052120040] |The administration side is where you'll find some major differences between Solaris and Linuxes but you'll find a lot of differences too between various families of Gnu/Linux based OSes too. [131052130010] |If you’re a UNIX user, all UNIX are pretty much the same. [131052130020] |If you’re a UNIX programmer, all UNIX are a little bit different. [131052130030] |If you’re a UNIX system admin, all UNIX are completely different! [131052130040] |— Bob Koehler Hubble Space Telescope Payload Flight Software Team [131052140010] |Do any package managers come installed default in NetBSD? [131052140020] |I am using NetBSD - I know ports and pkgsrc are available as package managers, but do these or any others come pre-installed in NetBSD? [131052150010] |I believe everything needed for binary install of pkgsrc is bundled as default, but if you want pkgsrc source you have to check out the code. [131052150020] |I do not think ports is a default for NetBSD. [131052150030] |http://www.netbsd.org/docs/software/packages.html#docs [131052160010] |fsarchiver error [131052160020] |I'm running the following fsarchiver command: [131052160030] |I get the following error: [131052160040] |What is errno 22? [131052160050] |How do I fix it? [131052160060] |I'm using Red Hat 5.4, Linux kernel 2.6.18-164.2.1.el5PAE [131052170010] |How to enter into BusyBox when booting? [131052170020] |I have occasionally installed cloud-init package in Ubuntu, which blocks me from booting. [131052170030] |Neither recovery mode works. [131052170040] |Because cloud-init installed some upstart job configuration. [131052170050] |So I want to enter into busybox to remove /etc/init/cloud-init*.conf, but it seems like no way to do it. [131052170060] |I can press Ctrl+Alt+SysRq which brings on a rough hack menu, but there is no busybox option. [131052170070] |So is it possible? [131052170080] |My CDROM is broken so I can't use Live CD too. [131052180010] |You can try adding the string init=/bin/sh to the kernel line in grub. [131052180020] |This should bring you into a shell. [131052180030] |Then mount the root filesystem read-write with [131052180040] |and make your changes. [131052190010] |Where to find a PKG or RPM of fsarchiver? [131052190020] |I want to download the latest version of fsarchiver (I need a PKG file or RPM). [131052190030] |Where can I find that? [131052200010] |Quoting http://www.fsarchiver.org/Installation: [131052200020] |

    installation on fedora (using yum)

    [131052200030] |Recent Fedora releases provide an official package for fsarchiver where all the optional features are enabled (lzma compression, encryption, ...). [131052200040] |You can just use the following command to download and install fsarchiver and all its dependencies. yum install fsarchiver [131052210010] |What is a spinlock in Linux? [131052210020] |I would like to know about spinlocks in detail? [131052210030] |Could someone explain that to me? [131052220010] |A spin lock is when a process continually polls for a lock to be removed. [131052220020] |It is considered bad because the process is consuming cycles (usually) needlessly. [131052220030] |It is not Linux-specific, but a general programming pattern. [131052220040] |Example of a spinlock: [131052220050] |There is frequently a way to avoid a spin lock. [131052220060] |For this particular example, there is a Linux tool called inotifywait (it's not usually installed by default). [131052220070] |If it was written in C, you would simply use the inotify API that Linux provides. [131052220080] |The same example, using inotifywait shows how to accomplish the same thing without a spin lock: [131052230010] |A spin lock is a way to protect a shared resource from being modified by two or more processes simultaneously. [131052230020] |The first process that tries to modify the resource "acquires" the lock and continues on its way, doing what it needed to with the resource. [131052230030] |Any other processes that subsequently try to acquire the lock get stopped; they are said to "spin in place" waiting on the lock to be released by the first process, thus the name spin lock. [131052230040] |The Linux kernel uses spin locks for many things, such as when sending data to a particular peripheral. [131052230050] |Most hardware peripherals aren't designed to handle multiple simultaneous state updates. [131052230060] |If two different modifications have to happen, one has to strictly follow the other, they can't overlap. [131052230070] |A spin lock provides the necessary protection, ensuring that the modifications happen one at a time. [131052230080] |Spin locks are a problem because spinning blocks that thread's CPU core from doing any other work. [131052230090] |While the Linux kernel does provide multitasking services to user space programs running under it, that general-purpose multitasking facility doesn't extend to kernel code. [131052230100] |This situation is changing, and has been for most of Linux's existence. [131052230110] |Up through Linux 2.0, the kernel was almost purely a single-tasking program: whenever the CPU was running kernel code, only one CPU core was used, because there was a single spin lock protecting all shared resources, called the Big Kernel Lock (BKL). [131052230120] |Beginning with Linux 2.2, the BKL is slowly being broken up into many independent locks that each protect a more focused class of resource. [131052230130] |Today, with kernel 2.6, the BKL still exists, but it's only used by really old code that can't be readily moved to some more granular lock. [131052230140] |It is now quite possible for a multicore box to have every CPU running useful kernel code. [131052230150] |There's a limit to the utility of breaking up the BKL because the Linux kernel lacks general multitasking. [131052230160] |If a CPU core gets blocked spinning on a kernel spin lock, it can't be retasked, to go do something else until the lock is released. [131052230170] |It just sits and spins until the lock is released. [131052230180] |Spin locks can effectively turn a monster 16-core box into a single-core box, if the workload is such that every core is always waiting for a single spin lock. [131052230190] |This is the main limit to the scalability of the Linux kernel: doubling CPU cores from 2 to 4 probably will nearly double the speed of a Linux box, but doubling it from 16 to 32 probably won't, with most workloads. [131052240010] |A lock is a way for two or more tasks (processes, threads) to synchronize. [131052240020] |Specifically, when both tasks need intermittent access to a resource that can only be used by one task at a time, it's a way for the tasks to arrange not to be using the resource at the same time. [131052240030] |In order to access the resource, a task must perform the following steps: [131052240040] |Taking a lock is not possible if another task has already taken it. [131052240050] |(Think of the lock as a physical token object. [131052240060] |Either the object is in a drawer, or someone has it in their hand. [131052240070] |Only the person holding the object may access the resource.) [131052240080] |So “take the lock” really means “wait until no one else has the lock, then take it”. [131052240090] |From a high-level point of view, there are two major ways to implement locks: spinlocks, and conditions. [131052240100] |With spinlocks, taking the lock means just “spinning” (i.e. doing nothing in a loop) until noone else has the lock. [131052240110] |With conditions, if a task attempts to take the lock but is blocked because another task holds it, the newcomer enters a wait queue; the release operation signals to any waiting task that the lock is now available. [131052240120] |(These explanations are not enough to let you implement a lock, because I haven't said anything about atomicity. [131052240130] |But atomicity is not important here.) [131052240140] |Spinlocks are obviously wasteful: the waiting task keeps checking whether the lock is taken. [131052240150] |So why and when is it used? [131052240160] |Spinlocks are often very cheap to obtain in the case where the lock isn't held. [131052240170] |This makes it attractive when the chance for the lock to be held is small. [131052240180] |Furthermore, spinlocks are only viable if obtaining the lock is not expected to take long. [131052240190] |So spinlocks tend to be used in situations where they will remain held for a very short time, so that most attempts are expected to succeed on the first try, and those that need a wait don't wait long. [131052240200] |There is a good explanation of spinlocks and other concurrency mechanisms of the Linux kernel in Linux Device Drivers, chapter 5. [131052250010] |When a thread tries to acquire a lock, three things can happen if it fails, it can try and block, it can try and continue, it can try then go to sleep telling the OS to wakle it up when some event happens. [131052250020] |Now a try and continue uses a lot less time then a try and block. [131052250030] |Let's say for the moment that a "try and continue" will take i unit of time and a "try and block " will take a hundred. [131052250040] |Now let us for the moment assume that on the average a thread will take 4 units of time holding the lock. [131052250050] |It's wasteful to wait 100 units. [131052250060] |So instead you write a loop of "try and continues". [131052250070] |On the forth attempt you will usually acquire the lock. [131052250080] |This is a spin lock. [131052250090] |It's called that because the thread keeps spinning in place till it gets the lock. [131052250100] |An added safety measure is to limit the number of times the loop runs. [131052250110] |So in the example you make a for loop run eg six times, if it fails then you "try and block". [131052250120] |If you know that a thread will always hold the lock for say 200 units, then you are wasting the computer time for each try and continue. [131052250130] |So in the end, a spin lock can be very efficient or wasteful. [131052250140] |It is wasteful when the "typical" time to hold a lock is higher then the time it takes to "try and block". [131052250150] |It is efficient when the typical time to hold a lock is much smaller then the time to 'try and block". [131052250160] |Ps: THe book to read on threads is "A Thread Primer", if you can still find it. [131052260010] |How does one atomically change a symlink to a directory in busybox? [131052260020] |I am trying to (as close as possibly) atomically change a symlink. [131052260030] |I've tried: [131052260040] |That just put the new symlink in the directory that existing_symlink pointed to. [131052260050] |That did the same thing: it moved the symlink into the directory. [131052260060] |It refuses because it's a directory. [131052260070] |I've read that mv -T is was made for this, but busybox doesn't have the -T flag. [131052270010] |I don't see how you can get atomic operation. [131052270020] |The man page for symlink(2) says it gives EEXIST if the target already exists. [131052270030] |If the kernel doesn't support atomic operation, your userland limitations are irrelevant. [131052270040] |I also don't see how mv -T helps, even if you have it. [131052270050] |Try it on a regular Linux box, one with GNU mv: [131052270060] |I think you're going to have to do this in two steps: remove the old symlink and recreate it. [131052280010] |This can indeed be done atomically with rename(2), by first creating the new symlink under a temporary name and then cleanly overwriting the old symlink in one go. [131052280020] |As the man page states: [131052280030] |If newpath refers to a symbolic link the link will be overwritten. [131052280040] |In the shell, you would do this with mv -T as follows: [131052280050] |You can strace that last command to make sure it is indeed using rename(2) under the hood: [131052280060] |Note that in the above, both mv -T and strace are Linux-specific. [131052280070] |I don't know of a shell equivalent of mv -T on FreeBSD, for instance.