Monthly Archives: March 2014

Umount manual page explained

I’m planning on a series of articles in order to help some people that either do not yet have the habit to look through man pages or simply are reading my blog in order to find those sudden pieces from information that have the habit to appear in some of the articles you read. I’ll be answering some questions I often see on Linux forums.

  • What does “umount” do?
  • Why do we need to unmount drives?
  • Why “umount”, but not “unmount”?
  • How do you unmount drive in Linux if it’s busy?

umount

What does “umount” do? Simple – it u(n)mounts what you have mounted.It could be, for example, flash drive, or, maybe, internal hard disk drive… or network drive, that doesn’t matter. In other words, “umount” is exact opposite of “mount”.

Why we need to “umount” drives before we need to unplug them? Because the way system writes to disks can be compared to the job that people at big warehouses have. Let’s say one of their jobs is to pack big boxes with some materials and then put them into a truck to drive them away to somewhere else. Some people pack the things inside the boxes, some carry those boxes to the truck and put them inside. That should be clear. There’s a warehouse, warehouse workers, boxes with materials and a truck that workers need to fill with boxes. We also know that they don’t transport the boxes carrying them in their bare hands. They probably use some kind of motoric trolley that has the power to transport heavy things. Is there any sense in putting just one small box on the trolley if some more boxes are expected to be ready for transportation in a small amount of time? Sure there isn’t. Workers might as well just put this small box away for a while, and wait for some more – just not to waste time by driving the trolley to the truck and back more times than needed.

Now boxes packed with materials become data, warehouse is your main drive, truck is your removable drive and workers are the Linux system that does all the job. System doesn’t see any sense in moving just one small piece of information when you can wait a little bit and move much more at the time. So it saves that small piece of information, waiting for more to appear, then sends them all at once. This is what we call “buffering”, even though this principle is just one meaning of this word. System “buffers” these little bits of information until it has enough to write them in efficiently, or it is asked to “clear the buffer”, let’s say, because somebody wants to unmount the drive right now.

And then, let’s say, a truck driver, employee of other company than the one that manages the warehouse just drove away the whole truck in the middle of the process, leaving the workers with some boxes still in the warehouse. That sure is a stupid situation, isn’t it? The driver is unaware of the fact that he just lost part of the materials, and he’s screwed when he realizes that. That’s what sometimes happens when you unplug your flash drive without unmounting it – you just lose some of your data not even realizing this, as it was left in the buffers of the system. You’re the driver of the truck, as you can see, and you’re not doing a good job =). Yes, I’ve lost data this way. Just for you to know that this actually happens =( To sum up – ejecting your drive without unmounting is just not wise. And be it Linux or Windows – basic principles of mounting/unmounting drives are the same everywhere. The only thing is that you have no possibility to control how Windows mounts drives – but you are still the only one that can and has to give the signal to unmount the drive! It’s called “Safely remove” or like that – can’t remember now, but you must know what I’m talking about.

Basically, you have to “umount” every drive you mounted with write permissions, and especially if you edited or created some file on it since the time you mounted it. And even though it might be that you haven’t actually edited/created a single thing on it or even mounted it read-only, you better unmount it. Why?

To understand, why, we have to look at what does the “mount /dev/drive /media/partition” actually do.
It:
1) Actually mounts your drive where you said it to mount it. That’s clear, but…
2) It also writes the entry in some system files and other locations. For example, file “/etc/mtab” is one of those files – it contains info about all the partitions currently mounted.

See, there’s one more thing that we usually don’t know about – entry in /etc/mtab. Moreover, some other programs also use /etc/mtab for their own purposes, and part of those programs are system utilities that hold the system alive. Of course, they do need to know about what’s mounted right now – and the only way for many seems to be reading /etc/mtab.

Seems that “umount” should also delete the entry “mount” added – it’s the exact opposite, remember? And, of course, it does. Once the entry is removed, programs are safe to assume partition isn’t mounted anymore, and they’re usually right. But what if the entry stays after partition is physically unmounted? Programs assume otherwise – they think that everything’s alright, but it isn’t. And if they try to somehow work with that partition – well, things happen. Most programs are OK to hold such a situation. Others may not be – those programs crash, potentially making you lose some of your data you that were just editing with this program. System and those system utilities also are oblivious, and even though they’re usually better prepared for any exceptional situations – you wouldn’t want to test them, see, people are people, and bugs are bugs, and some bugs stay hidden waiting exactly for some kind of exceptional situation. I hope that’s clear for you =)

As you can see, “umount” is a very useful program, helping us stay safe. But how does one use it?

Let’s assume we have mounted a partition /dev/sda5 under /media/Partition. Now we want to unmount
it, and we just do…

>umount /dev/sda5

Simple as that. Moreover, both mentioning mountpoint (/media/Partition) and partition block device path
(/dev/sda5) will do the trick. So,

>umount /media/Partition

also works. But – the official man page says that the latter way will fail in case partition is mounted twice at different paths. There will hardly be a reason for you to do that under normal circumstances (I mean, for you to mount one partition twice under two different paths), but keep this in mind.

And there’s more behind this command!

  • What if you want “umount” to tell you more? Just type “umount /dev/sd-whatever -v”, adding option “-v” at the end. This turns on so-called verbose mode, which does tell you more in case you are interested – and, given that you’re reading this, you probably are 😉
  • And what if you want just to see what happens if the entry in /etc/mtab stays? Well, there’s another option for you, just add “-n” at the end then. I won’t promise lots of fun though =) If you want to delete entry in /etc/mtab later – use the same command as you used previously, but put “–fake” instead of “-n”. See, using “umount something -n” actually unmounts but keeps the entry. Using “umount something –fake” doesn’t actually unmount but deletes the entry – simple as that.
  • Feeling angry at your system? Use “umount -a”. This unmounts every single partition mounted, including root. Must be fun watching your system search for files that are not there – and this, unlike “rm -rf /”, does almost no harm =)
  • Last option might be actually useful together with “-t filesystem_type” option. For example, “umount -a -t ntfs” will unmount only those partitions that are of NTFS type, yet all of them. Or, if you wish to unmount all the read-only filesystems, use “umount -a -O ro”, where “ro” is an option you earlier gave to “mount”. This applies to all options of course.
  • One more “umount” option is truly amazing. Let’s say – you have a filesystem which is currently busy – and you don’t know why! You’d forget about this, as a FS may be busy for a number of reasons, but you need to unmount it, and cannot. You get a message:
  • umount: /path: device is busy.
  • That’s the thing about Windows I hate – if something uses the flash drive, be it Windows Explorer or antivirus program performing a quiet scan when it wasn’t asked to, you’ll just be given a message like “Drive’s busy. Wait, please.” Ooh, it’s OK – I’m so happy to wait when I need my f***ing drive now because the bus will arrive after ten minutes and it won’t wait. User-friendly, they said. It’ll be comfortable, they said.
  • … Anyway, your drive is busy – some program is working on it. What do you do on Linux? Use “-l” option. It makes “umount” wait until drive won’t be busy for at least a little while – and then unmount it right on time while that program takes a rest before moving to another file! No more waiting for some unknown program to fully complete its work when you just need your goddamn flash drive, just add “-l” at the end. Amazing, isn’t it?

Or, and one last thing – why “umount”? Why not “unmount”? Well, first versions of Linux kernel were limited to 8-letter filenames, and developers needed to shorten the name so that source code for “umount” filename  (with extension .c added – so two more letters) could fit in the limitations. Explanation taken from here 😉

That’s all for today. Hope you enjoyed it and filled in some gaps of your knowledge base. Now, I’ll move on to creating some other article =) Good luck to all of you, Linux beginners!

Advertisements

Where and how should Linux begginers start

I have constantly been working with Linux for over 2 years from now. I remember how I started, messing up my system from the very first try to get to know Linux (my PC OS was indeed a little bit fragile back then), and how I continued from there, experimenting, messing things up and restoring them to their previous states – and gaining experience in huge portions through all the way forward. Now I’m the one who’s capable of teaching people about how things work and how to work with things.

I’ve decided to write a short guide from my experience for those who are trying not only to use, but also to understand what lies behind a nice-looking desktop of Linux PC and what all those words people type in console to solve problems are about. So, if you’d like to understand how a Linux system works and thus are ready to dive into a world of Linux – I’ve prepared some tips for a good start.
1) Get yourself a dedicated Linux machine.

One of the options to choose from…

…and here’s another one worth considering.

Seriously, buying yourself an old PC/laptop/RPi/something else has never been so easy. Why not using a virtual machine? Well, VM is OK – unless you’re trying to experiment, which is what I’m talking about now. Of course, both VM and separate PC are similar – you can mess everything up but nothing happens to your main PC, so they free you of fear of experimenting 😉 But VM doesn’t somehow motivate you, at least, that’s what my experience is.
Why? It hasn’t got any real use. All the Linux PCs have one or multiple. And VM relies on the host PC – that means the same downtime. Downtime ain’t that good for your Linux server – not because it’s a word many system administrators in bigger companies are afraid of 😉 It’s just because your server has less time for performing some tasks. Thus, it’s much harder to give your server a real use.
Why should yours have one?

2) Make it do something useful.
Useful things are the outcome of your practice and experimenting that you really see. Your best indicator of how your training goes. If you have set up your Linux PC as a router, it will work for you. If you make your VM a router, you’ll turn it off to conserve energy and plug in your Linksys router instead. That’s not exactly useful. Make this machine do something in your home that doesn’t yet exist or make it replace something that already works. Making yourself rely on this machine is good – you’ll be trying to improve it to make it suit your needs. What tasks could one possibly have with a dedicated Linux machine?

  • Home router (gateway)
  • File server (All your files still belong to you, but you can access them from everywhere)
  • Backup machine (never losing your files again! Or, at least, having more or less recent copy =) )
  • Torrent server (breaking the law with so much ease)
  • Audio streaming server (your favourite radio station playing your own music…)
  • Audio streaming client (…or your favourite internet radio station always playing at home)
  • Audio playing client (imagine speakers connected to one machine and this machine receiving sound from all other PCs)
  • Web-server (platform for your practice in developing web-sites, or, maybe, even for your own public blog or 9Gag clone)
  • Info station (like laptop always turned on and showing weather conditions on its screen)
  • Alarm clock (your wakeup is no longer defined by those default 10 alarm tunes in your mobile phone)

Could be this, or….
[Madskillz] Home automation centre (imagine turning on the teapot while you’re 5 miles away from home!)
[Logan’s Loophole] Robotic barista mixing drinks as you wish to
[Control freak] Surveillance camera control centre
[IMPOSSIBRU] Device automatically hacking every network available out there (no link, sorry)
[Super Intelligent] Your own Artificial Intelligence Unit, just one Debian package away! [Lie]

Ok, you got the point. You could also combine things, like torrent&file server, hacking
neighbours’ networks in free time – how is that to you? But one thing is definite – it should do something. You’ll be pleased by your results, you’ll get more experience and those cool real-life features that no VM could provide will make you want more of those features.

Being in a never-ending circle of getting experience – does it get any more cooler?

3) Be prepared for the mistakes

Things break. Happens to everybody, sometimes it’s the user’s fault, sometimes it’s all about developers’ typos –  but still, you will make mistakes, and if you’re new to Linux –
mistakes will be unavoidable, Linux needs some additional knowledge. Either way, you’ll be sometimes forced to fix things. Sometimes it will be much better to just start everything again, waiting for an hour as OS is being reinstalled…
BTW – great power of Linux is that even in case of major problems it hardly needed to reinstall OS itself, but the thing is you’ll need to do this if you experiment as you’ll learn to mess things up much earlier than you’ll learn to do them right, and sometimes learning to repair and repairing is much harder than to recognise just why this happened and learn to never do this again, so you need to decide if that all debugging and fixing is worth it. Not to mention that trying to fix a problem for hours
makes you frustrated – if you have the possibility to somehow roll back, either by restoring a backup or simply reinstalling, you’ll save your nerve cells.

As a conclusion for this – don’t throw out your
installation CDs 😉

4) Make backups as long as you do something good

Well, under this picture there’s one more story hidden.

Backups are not necessarily large files containing full snapshots of your system. Sometimes it’s OK just to save link to instructions that helped you set up Linux gateway. Sometimes it’s good to backup your command-line history as this will remind you which commands you’ve used to do this or that. Sometimes you’d want to backup your /etc/ directory somewhere else – it’s your server and you have some configs there that you worked on for hours, combining options to ensure the solution is perfect. Why’d you want to lose them? And, provided that you experiment, you might lose them, so ensure you don’t.

Simple cp command in cron to always attached flash drive should be enough.

5) Don’t be afraid of command line

Picture not necessarily related

See, Linux is kind of based on command line and heavily depends on it, unlike Windows, where you can hardly do anything from it. So if you want to learn Linux, you need to learn all those commands. As we all know, practice is the best kind of learning – so remember that GUI shouldn’t always be your assistant in doing things. In Linux, GUI utilities that help you do stuff can’t do anything that can’t be done from the CLI – keep that in mind when you, for example, configure “pulseaudio” and need to download many, many GUI tools that’d help you do that.

It doesn’t necessarily mean that you need to use only CLI in the beginning – it’s hard to just switch. Yet commands aren’t that hard to learn. It’s possible that after some time you’ll be willing to learn some new awesome commands that your system is able to process. Also, feeling when you don’t need to move your hands from the keyboard to the mouse is awesome, at least for me 😉
Not even mentioning your increased typing speed after mastering command-line tools.

I guess that’s all by now. The next article you’ll probably find useful will be telling about Linux distribution that I am using – Debian. I’d like to tell you about the most important things – why I chose Debian, why I’m still using it, and why I think you should at least try it, as well as give some basic overview of Debian as a system. And, should you have questions about this article – just ask!

Did you know that… – notes about Asus EEE PC 701

An Asus EEE PC 701 4G runs perfectly on 12V power supply instead of 9,5 V one. Checked on two EEE 701 4G of different revisions, no overheating of power components and everything works for over a year by now. So – EEE PC 901 supply of 12 volts / 3 amps fits 701 model both by connector and voltage/amperage. Saying this because couldn’t find any information on the Web when I myself searched for this question, but now it’s clear.

Sometimes, on Asus EEE 701 4G keyboard keys misbehave: F2 becomes F1, | and ~ disappear… It’s simple to repair it: just turn off your EEE, close the lid, eject the battery, open the lid and press the power button for some 5 seconds. All the glitches seem to disappear after this.

Also, screen can start flickering in a strange manner all of a sudden. Just closing the lid and opening it again should help then.

To be continued if I find something more worth sharing about it =)

Intro

My name is Arsenij Pichugin, I’m from Latvia. I’m 18 years old and I think that knowledge and experience are one of the things you should leave behind as you grow up. People usually save those little bits of knowledge writing them down somewhere.

And here comes another of my values – sharing knowledge with others. I think everybody should do it – it is just that life becomes much more easier. If everybody would be sharing a solution to some problem he solved, many, many things would be done much faster in everyday life.

Of course, here comes the question of “How do we find the solution”, but I assume that Google is everybody’s friend. If he isn’t your friend, well, you better make him. Chances are he will eventually point you to some solution you would be searching for yourself for ages instead.

So, I’ll be sharing my solutions here. Sometimes also boasting, expressing my opinion and making tutorials – I love tutorials. Once you write one, you don’t need to write much on that topic anymore. But it takes time and work, for sure. 

What topics I’ll be writing about?

  • Linux in general
  • Electronics in general
  • Raspberry Pi
  • Arduino
  • Some custom circuits
  • Making PCBs
  • Python
  • Architecture of programs
  • “Smart house” topic
  • Useful sites
  • DIY
  • Computer and peripheral repairs
  • Modding
  • Organising workplace
  • Electrics
  • Writing itself
  • and much more of the things I eventually will add to my knowledge database.

What will be posted here?

  • Info about any finished projects
  • Info about any unfinished projects, including both those which will continue and those which won’t
  • Tips on some topics – both general and small
  • Just some ideas – even those I won’t even get close to implementing myself.
  • Bugfixes – both those I found on the net and invented myself
  • Opinions on some topics – don’t expect my opinions to be objective even though I try =)
  • Information that I might find useful for anybody on any topic
  • and, again, much more than this.

I think future is for those, who will read, and depends on those, who will write. I’ll hope this blog really helps somebody in going towards his dreams – the same way as it helps to go towards mine.

Also, I’m considering translating every article into both Latvian and Russian. Those are languages that I know, and I think using those two languages in addition to English will be broadening the auditory of those people that I might help by writing =) But it’s not something I’ll do now.

To sum this up, I’m going to dump lots of stuff here, trying to help people by providing information, which has in the recent years became even more powerful than before. Let’s hope this works 😉