Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Linux Software

Can Linux Work Without Shutdown? 61

Glen Raphael submitted this odd question a while ago: "Suppose I have a test tool running under Linux in an environment where the power is expected to die often and for long periods of time without any warning (and buying a UPS isn't an option). How can I make it safe to just turn off the power to the PC running Linux without properly shutting down?" So what is one to do when they want to run a Linux box and they can't trust their outlet?
Glen continues...
"It's okay for fsck to run at startup but I want to minimize the damage it has to repair and I want to entirely avoid the need to boot as root in order to repair major damage. What can I do to accomplish that goal? Performance is not an issue. I thought of doing a "sync" every minute or so, but that seems silly. Is it possible to turn off disk caching instead and if so how do I do that? What else can or should I do in software to ensure that you can turn off the Linux machine by hitting the power switch or cutting power to the building and not expect major repairs when the power comes back up?

(Side note: If this problem can't be solved, the favored alternative is to give up on Linux and rewrite the tool using DOS. Right now I'm using RedHat 5.1 or 5.2 on a generic Pentium notebook.) "
This discussion has been archived. No new comments can be posted.

Can Linux Work Without Shutdown?

Comments Filter:
  • Actually, I have a power supply, AT, not ATX unfortunately, that does have a builtin UPS. Looks kinda old, got it secondhand. I'll try to look for the source of it sometime..
  • by oGMo ( 379 )

    The reason you have to shut down is because you have mounted partitions as rw. If you don't need to write to them, you could always mount everything ro and then it shouldn't even fsck on boot. I think. I'm not going to try it. :)

    It's obvious you will need to write something, and you might be able to turn off the caching for that particular partition.

    It's really too bad you can't buy a UPS. Then you could hook it up to init to shut down the computer when it gets a powerfail signal...

  • I don't know, I haven't actually used one. I would assume given a halfway decent one (read: not the cheap consumer-quality kinds) they come with all the hardware and information you need. I believe there is documentation either with the kernel or with init that talks about this... I believe it was with the kernel... check it out.

  • No kidding, he was talking about NOT using a UPS but having the battery built into the INTERNAL power supply of the case.

    I think the problem with this is that full size units consume a LOT more power than a laptop and thus eat battery power candy. I have a 250VA UPS on my 233MMX, 3HD, 1CD, 17" an it only last like 2 min before it is dead. I don't think the batteries from laptops have that much capacity.
  • Not that much. One that will outlast the momentary power losses, and then allow an orderly shutdown can be had for about USD100. Unless you are a student you can afford that.

  • In your fstab, and any place you mount a drive, use the sync option. This should disable the cache, and make all writes synchronous. It WILL hurt performance, but you shouldn't have to worry about disk state.
  • > have a pentium notebook, which when the battery > is about to die (about 1% life remaining)
    >it enters save to disk mode. This feature >requires a fat or fat32 partition.. (because of >the program that creates the file in which the >data is stored)
    >
    >what happens is the ram (32mb) is saved to that >file. it isnt supported in linux.


    Untrue! Linux 2.2 either supports, or there is a patch for, suspend to disk. It's been discussed on linux-kernel a bit, and I know some generated a patch which supposedly works well. I don't know if it got added to the official kernel, though. Try looking in the kernel list archives.
  • Do you have a box *anywhere* that you can trust to stay up?

    I run a NFS-Root workstation that boots from floppy and then gets its disk over NFS. It *can't* cleanly shut down, since it doesn't know what to do after the filesystems are unmounted. I've been just turning it off for a year, haven't had any problems (but hopefully someone will tell me if I'm being lucky). The server deals with keeping the disks happy.
  • If you get an APC BACKUPS PRO, it comes with the cable you need.
  • by tgd ( 2822 )
    We had a discussion about this back in January on the autolinux mailing list (www.bangsplat.org/autolinux).

    The best way to handle it is to mount everything you can read-only. I've been experimenting with mounting everything read only and then mounting a ramdisk as an overlay filesystem allowing the system to be written to, as long as the files you write to don't need to be saved.

    Another way is to mount a ramdisk as a partition, copy off a read only partition, and periodically mount the original partion read/write, sync the two, and remount it read only.

  • The reason that you can shut off at any DOS
    prompt is because SMARTDRIVE will sync the
    disks before the prompt is displayed.

    That's easy nuff to do in bash :-)
    PS1="`sync`\$ " or whatever...

    --

  • Mount RW only the part of filesystem where you want to store some things permanently. Use ramdisk
    for temporary storage. Mount the rest RO or run everything from RAM as suggested.

    If you have e2fsck in your start-up scripts, add
    "-p" option to it.
  • Buying a UPS isn't as expensive as you think About 6 weeks ago, I bought a MGE Pulsar ES 2+. It will hold my system up for about 7 minutes, and has a serial cable and LINUX SOFTWARE (on the company's website) to shut it down when the UPS goes low. And the price... $50, not bad if you ask me. I was able to get it on sale at Fry's Electronics or it would have been about $100. Sounds like a good inexpensive solution to your problem. Give a UPS a try, you won't be dissapointed.

    Check out MGE's site here [mgeups.com]
  • Just create a fat partition slightly larger than the linux partition at the beginning of the disk and the BIOS of the laptop will use that to store it's suspend file. Works perfectly.

  • Because if you avoid it only because it won't last long enough, that's ok; just rely on the UPS long enough to do an orderly shutdown, then power everything off, including the UPS. Then when the UPS detects power back on, it will start up your box.

    --
  • As you said you are using a notebook. If it has advanced power management (APM) support, and I am not sure of a notebook that doesn't, you could take advantage of it. When the power goes out then the battery will power it. It that last for a few hours and the battery dies the the apm support will suspend the computer with out any problems. I also belive you could initiate a shutdown. a man on "ampd" should help.

  • I've been in an environment where we we had a lot of power failures (and we had a faulty UPS that took a few weeks to get replaced). Whenever we lost power and then regained it, the 3 or 4 NT boxes would come up again, occasionally run CHKDSK automatically, fix anything, and boot up normally. The Linux box (RH 5.1) would need fsck run on it every time, and on one occasion, a power failure *while* fsck was running trashed the disk quite badly, requiring two or three hours of work to get the whole lot working again. NT's journalling file system is actually damn reliable, and on a decent machine, the whole system can be quite reliable.
  • We've hooked things up like this before, but had the occasional problem where the machine got the POWERFAIL signal from apcd, shut itself down properly, then power came back on before the UPS battery went dead. The machine ends up sitting there, properly shut down, until somebody drives to the site and flips the power off and on. Anybody got any ideas for working around this?
  • It probably does send the POWEROK signal, but by that time, the OS is already shut down. Maybe I could create a special init state that mounted everything readonly and then just watched for POWEROK, and switched init states...
  • Well, whenever my boss is pissed-at me, he yanks the plug on my own server. So, to avoid big fs damage, I use the following /etc/fstab which does the job fine:

    /dev/hdb1 /home ext2 rw, suid, dev, exec, auto, nouser, and sync 1 1
    /dev/hda1 / ext2 rw, suid, dev, exec, auto, nouser, and sync 1 1

    -- ----------------------------------------------
    Vive le logiciel... Libre!!!

  • I've often wondered abou this. Laptops don't have the problem of dying when disconnected from the mains because they have a battery (obviously seeing as they're portable :-)

    How about a powersupply with a battery built in, so that a powerloss will switch to battery, which in turn can be detected (laptops tell you when they're on mains or bat) and which could then force an immediate shutdown. The battery for this type of powersupply wouldn't even need to be real big. 5-10 minutes would surely be enough. In other words, batteries out of ancient laptops would suffice...

    Does anyone know of such a project already having been attempted? What is wrong with this idea? Would it be possible to build such an animal to just replace a normal power supply in a desktop box? Or does a desk top box just simply suck way too much juice for a battery to even cope for an immediate shutdown?

    Ralf
    http://www.dstc.edu.au/~ralf [dstc.edu.au]

  • What about using the Linux Router Project distribution? According to an article I read in the most recent Linux Journal, when this system boots, it loads the system into a ram disk...so, if you lose power, oh well, just reboot... and no disks to fsck!
  • A while ago, rob posted an article about making a component stereo piece to play mp3 cd's. They used a pc running linux inside a cd player box to do it. Their solution to the fast power off problem was something like this:
    during boot, create some ramdisks.
    copy the contents of /etc, /var, and any other dir that has to be writeable to appropriate ram disks.
    remount all disk partitions ro.
    remout /etc, /var, blah blah blah from the ram disks.
    That solution works, but requires ram, and requires not needing real write access to the harddrive ever.
  • 1) you never said how big your system is. If is is small enough you can as other say run from ram
    2) have you though about 'embedding linux'? it is possible to embed the linux os in a device. I saw in the LJ (I think it was the linux journal) that the car mp3 player had 3 linux embeded oses running (2.0.35, 2.0.18, and cannot remember the other one) a mini cluster there (hehehe).
    does it have to be a desktop computer or can it be an embeded device?
    3) why is ups an unacceptable solution?
    4) what is this tool doing as it runs? (reading files, reading info from a port, writing data to files)?

    on a solution note
    1) it is possible to spin down disks (on most systems that is) hdparm /dev/hd? will tell you the disk paramters that are set I use -d1 -c1 -k1 or something like that to keep settings turn 32bit access on, and turn spindown on after 20minutes of inactivity
    2) it is also possible as many have said to use ram disks..
    3) and lastly have you thought about running the filesystem from a cdrom linuxpro has a distro that this can be done, then it is automatically mounted read only.. it would be interesting to have the / filesystem on cdrom, and the home directory in a ram disk and set up a diskless system.... or a system with a very small hard drive..
  • I have an MGE 220 plus and it came with a cable and CD with unix/linux software. There is no problem with that.

    And I purchased it for quite cheap at www.egghead.com
  • What about solid state disks. Flash isn't that expensive. It isn't particularly fast, but it might be fine.
  • From what I understand, the problem isn't a home system, or a computer... it's an imbedded system, of some kind, in many spots a USD100 component is far too costly, ie. if the price point for the entire machiene is under $300, typical markup is 50% in situations like this. Another reason it may not work is size problems, this may be a device that is required to be transportable easaily, or needs to fit into a small compartment somewhere. In either situation a UPS is far too expensive or large to be used.
  • Here are two ways to do it:

    1. To disable swap until you re-enable it, comment out any lines in your /etc/fstab that designate swap partitions (insert a '#' at the front of the line). Upon next reboot, swap will not be used (you can also turn it off with swapoff). Remove the '#' to re-enable (reboot or swapon required).

    2. To disable swap until the next reboot, just use the swapoff command: swapoff -a
    To turn it back on, issue a swapon.
  • Hello,

    Dtfs is an ext2fs based log-structured filesystem.
    (something like journaling filesystems). It logs all modifications of the fylesystem in an efficient way so that only the latest instructions that occurred during power failure are lost. And you can also undelete, undo some operations so that you can set the disk back to a safe state.
    http://www.complang.tuwien.ac.at/czezatke/lfs.ht ml
    The driver is still incomplete though.
  • What a prick...

    It doesn't sound like he likes the idea of you getting work done. Too bad for him that his temper gets in the way of business.
  • It's always struck me as suckish that UNIXes need
    to be told to flush data to disks before taking
    them away. I can accept having to unmount NFS shares and the like, but why my floppy drive, or even worse, READ ONLY CD DRIVE!

    IMHO it'd be good if the OS still didn't block on writes, in that cp asdfsdf /mnt/floppy still came straight back to the prompt, but if there was any writes outstanding on any block device it would write until there were none - not even system areas; from observation Linux certainly seems to eagerly flush data blocks, but I suspect not the system areas of a disk. Anyway, it should indicate in some way what volumes were "safe", by turning off the floppy drive motor perhaps, so we can always eject a disk if the light's off. Just like DOS :-)
  • Really. There is never an excuse to use any Microsoft product whatsoever. Unless, of course you want to end up in Hell!

    I don't see your problem. fsck is a very smark programme and whatever fixes it does genereally does not destroy anything. In may case, I designed a system that is running in an environment that is subject to power failures. When it comes back on line it generally reports only a new missing blocks and i-nodes. My software is smart enough to know how to this sort of thing.

    As for your particular application, if you need the data to be on the disc as soon as it is written, youn programmes can always call sync(). Not only is it a command, but it is part of the interface library.

1 + 1 = 3, for large values of 1.

Working...