Forcefully Unmount Partition

Asked by Phillip Bryant

I want to unmount my Linux partition (which is a ext2 mounted under /), but I have read every shred of help out there, and its all basically the same exact thing as this: http://www.debianperu.org/archives/320

How can I forcefully unmount my Linux partition to edit its size and can the answerer of this question PLEASE dumb it down?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu util-linux Edit question
Assignee:
No assignee Edit question
Solved by:
PeterPall
Solved:
Last query:
Last reply:
Revision history for this message
Phillip Bryant (the-icebud) said :
#1

ANd by the way, if it matters, I'm running Ubuntu 10.04

Revision history for this message
Best PeterPall (peterpall) said :
#2

Unmounting the partition your system is on is quite a beast:

If you completely unmount the partition there is no partition yo can read the program from that can resize it.

Not unmounting means that the program resizing the partition as well as any system service which might be running in the background (the printer driver, avahi that tells every one inside your network which service your computer is able to offer,...) might - if it wants to read a file - read a file that is currently moving. Or even worse still uses the old position of the file when it has already moved somewhere else.

This obviously is bad because even a rather stable system is not *designed* to deal with this.

The official way to resize the root partition (the one mounted at / ) would be to use a ubuntu live CD like the one you installed the system from. It contains everything you would need for doing things like this.

Having said that - if you are really determined to risk making your system go haywire whilst trying to change the internals of your main data storage - for example you really need to resize your partition right now, you have at least one complete Back-up if everything goes wrong, but there there is no way of getting a live CD - it is possible, and I've done it twice:

First stop all processes you can afford:
 - Log out of the graphical console
 - Press Ctrl+Alt+F1 to go to a text console instead
 - log in there
 - tell the system to shut down all processes it can afford to doing a
   sudo init S

 The information about which file systems are mounted relies in the file /etc/fstab. So edit this file (use sudo nano /etc/fstab or something similar, if you don't know how to do this on a console do a sudo gedit /etc/fstab as the last thing before you log off from the graphical system) ...and remove the line mentioning the file system mounted as /

Now the partition resizing program will no more know that your root partition is mounted - but will still be able to write to files on it - which is bad: Linux doesn't watch the hard disk for changes all the time. If it knows which structure is to be found where - it will just use this file/directory entry/ something else without looking if anybody has used direct access to the hard disk to alter a partition *that is still mounted*: Normally nobody would risk doing this.

To at least forbid the system to change the contents of the partition whilst your tool is resizing it do a
sudo mount (name of the partition) / -o remount,ro
to at least forbid it to write to this partition. If that doesn't work not all is lost: Press Alt+Print Screen+S to do an emergency sync (which makes the kernel write all the stuff to the disk it always wanted to but never had time to write), then Alt+Print screen+u (to emergency change all file systems to, well not unmounted, but at least mounted read-only) - and wait till your system has stopped writing to the disk.

Normally it will output a "Done." somewhere when it has. If the "somewhere" is not your console - you can tell it to tell you all it has output in the last few minutes by typing in:
dmesg

Now you have prepared your system to no more be able to alter your hard disk's contents whilst you are resizing it, - and you can still access to files until they or their directory entry have been moved. If you are enlarging your partition the changes are above 50 percent that nothing vital is moved until your partition is resized, if you shrink your partition - this involves moving a lot of stuff.

But if you are really daring you can try now to resize your partition.

Revision history for this message
Phillip Bryant (the-icebud) said :
#3

Thanks PeterPall, that solved my question.