|
The surface of the Earth can be divided up with imaginary lines of latitude and longitude so that co-ordinates on a map can be recorded and used to describe the exact location of a real feature or object on the ground, at sea or even in the air. A hard disk is similarly divided up, but hard disks are shaped like flat platters and not spherical or geodal. Early hard disks used to be divided into cylinders, tracks, blocks and sectors. They used to call that 'CHS Addressing'. For the last ten years or more we use LBA, 'Logical Block Addressing' meaning the sectors are just numbered from the start of the disk to the end something like frames in a roll of movie film. Data in a hard disk is stored in sectors. Each sector can hold up to 512 bytes of data. They're numbered from the outside edge in starting at 0, (the MBR). It is possible but not very practical to use 'dd' commands to write data to a hard disk without having any file system. If we did that we would need to be able to remember the exact sector numbers where we stored certain files or else we would have a hard time looking that information back up again. Maybe we would write the sector numbers down on a piece of paper. That paper(s) could then be said to be serving as our file system. That would be a very slow and tedious way of doing things. We'd probably need a filing cabinet to store all the paperwork. That would be a physical file system. Why not make the computer do the work for us? Well that's pretty much what happens. We 'format' a partition with a file system. We dedicate part of the disk itself for storing the information about where the files are stored, kind of like a map of the disk. The kind of file system I'm talking about now is a digital file system and includes an elaborate set of rules for the operating system's kernel to use for writing files to disk and automatically record where it left them so it can look them up and find them again later. Linux operating systems can work with many different kinds of file systems, FAT16, FAT32, NTFS, ext2, ext3, ext4, reiserfs, reiser4 and jfs, xfs and so on. In order to do this, we need some sectors reserved for the file system itself and there are special sectors reserved for recording 'metadata'. 'Metadata' is 'data about data', and is used to record details about the files we're going to store. Metadata includes exactly where each file is located on the hard disk, as well as other properties such as the file's size, time and date the file was first created, when it was accessed and when it was modified, who owns the file and what file permissions are set for that file and so on. When it's time to read the files again, the kernel refers to these metadata blocks to learn the file's location on disk. If the file is modified it writes the changes to disk and updates the metadata. I am trying to be very brief here. If you want to learn more a good place to start is here, Understanding UNIX / Linux file system - Nixcraft If you want to do an experiment to see how much room a file system takes up in a partition, just use GParted to create a partition in a spare disk of some kind, maybe an empty USB flash memory stick for example. Format the partition with a file system and you will see that even though it is empty, GParted will show you a graphical representation showing that some of the space is already occupied. That's the amount of room used by the file system itself. This is called 'file system overhead', and different file systems have different file system overheads, (useful to know if you need to install in a very small disk). You will also find that there are limits to the minimum size you can shrink partitions with variuos file systems in them too. To the user, a file system appears as a directory tree structure, with directories containing more directories and files. The top level is called 'root', and it is usually symbolized with a 'slash' symbol, like so: / There are around 20 directories in / (root), and they each contain different sorts of files. A 'directory' is just another name for 'folder', in case your new here. Here's a link about that: Linux's directory structure - Tuxfiles. And another link: The Linux filesystem explained - FreeOS.com That's my attempt at explaining what a file system is. 'In a nutshell'. I'm not sure if I'd get full marks for that in an exam if I had to pass one, but that's the best I can do so far. |
| Click-Icon Mounting Mounting file systems is now a lot easier since Ubuntu Hardy Heron than it used to be in earlier versions of Ubuntu. The easy new way to mount a file system in mdern versions of Ubuntu is to just go looking in the 'Places' menu and click on the icon for it. ![]() If your icons appear with generic names like '13.2GB Media', don't despair, see my next article about how to label your ext2, ext3 or ext4 Linux file systems, Make a label for your ext3 file system. You'll be given an icon for it on your Desktop when it is mounted. ![]() If you only want regular GUI access, just right-click on the icon and click 'Open'. You can still use Linux commands in your terminal to access your file system if you want. ![]() It should open for you right away when you click 'Open' if you're using a Ubuntu live CD. If you're working in a hard disk installed Ubuntu operating system you will be asked for your password. Once the partition is open if it's just a data partition and it belongs to you then you can normally do what you like, (read/write, copy/paste). Otherwise if it's not yours, access may be restricted subject to Linux file ownership and permissions rules. If it contains an operating system, you can access your own data files with it, in your /home/username directory and you can easily make a file rescue or backup or restore all your own files. If you need to make important system changes you can, but since file system permissions may limit what you're allowed to do you will probably need to use Linux commands in your terminal to obtain 'root' or 'superuser' access, see: Rescue your Linux system with a Live CD. Set File System Labels with GParted ![]() Recent versions of Gnome Partition Editor have a great new feature! You can easily set a volume label for most file systems without needing to use Linux commands. This feature can be found in Intrepid Ibex and later versions of Ubuntu, or in recent versions of GParted Live CD. Just right-click the partition you want to set a label for and click 'Label', and give your file system a name. You can find Gnome Partition Editor in your Ubuntu Live CD under 'System'-->'Administration'-->'Partition Editor', and you can install it in your Ubuntu operating system with 'Applications'-->'Add/Remove (Programs)'. ![]() This is great for those of us who multi boot and those who use USB devices too. The mount points in /media will be automatically given the name we chose for the label from now on, and therefore the icons will also appear on our desktops with the right labels too. |
|
Running a filesystem check with Gnome Partition Editor Even someone who doesn't know anything about file systems or how to use the command line can easily run an effective file system check with Gnome Partion Editor. Some people seem to be frightened and nervous about running file system checks, especially those of us who are new to Linux. There's nothing to be afraid of and it's a good idea to run a file system check in your Linux file systems whenever you have some spare time. It only takes a few minutes and you should do this every once in a while as a matter of routine. Regular file system checks keep your file system(s) in top shape so your operating system will keep running like a well oiled machine. Quoted from Linux ext3 FAQ:
File systems always need to be unmounted before working on them. We can't run a file system check in an operating system partition while the operating system is running. Most modern programs will not allow you to do it or will at least give you warning messages. Do not ignore the warnings. Working on a mounted file system would be something like trying to change a tire on a car while the wheel is still turning. It's not recommended and will most likely cause a lot of damage if you try it. If you're using GParted and you're trying to check a file system in your computer tha doesn't belong to Ubuntu, you can usually just right-click on the partition and click 'unmount' first. If you're using the command line instead and you're not sure if a file system you want to check is mounted or not, the old fashioned method was to check with the 'mount' command with no additional arguements.
One of the easiest ways work on file systems is to boot a Live CD and work on the file systems in the hard disk from the live CD operating system. Most Live CDs won't mount your hard disk's partitions unless you command them to do so. Ubuntu Live/Install CDs tend to contain very old but stable and well tested versions of GParted. The Ubuntu Live/Install CDs run a large operating system and therefore they do automatically look for and use any Linux swap area partition that may exist in a hard disk. Sometimes that means you can't work on an extended partition when it contains a swap area that's in use. If that's a problem and you're using GParted you can right-click on the swap area and click 'swapoff'. The old fashioned method was to use the 'swapoff' command swapoff when we needed to work on a swap area partition from a Linux Live CD. If you have a computer with lots of RAM as most modern computers do, that won't matter, but in an old, low specced machine made back when RAM was expensive it could freeze the system or slow it to a crawl. GParted -- LiveCD is a Live CD operating system which is nice and small and light so it does not need to mount any swap area in your hard disk, (or any file system either unless it's explicitly told to). It's made for working on partitions and file systems and contains a relatively up to date version of GParted. You should always make sure you're using the most up to date version of GParted Live CD. Parted Magic is undoubtably and without question the best Live CD for file system and partitioning work. It always contains the most up to date version of GParted and other softwares too. You should always make sure you're using the most up to date version of Parted Magic Live CD. I highly recommend using the most recent available version of Parted Magic Live CD if you're serious about your disk partitioning and file system work.
To avoid this happening at an inconvenient time, you can induce a quick startup file system check early, anytime you like, by opening up a 'terminal', (Applications, Accessories, Terminal), and typing in the following code:
The startup file system checks don't fix much though, they're more just to take a quick look and make sure everything's still okay. If your file system has been damaged by an improper operating system shutdown, such as might be caused by a sudden power loss or the like you will be notified. |
|
Automatic filesystem checks on bootup The operating system looks at the /etc/fstab file automatically at each boot-up just before the '/' (root file system) and other file systems are mounted. The hard disk is scanned for the 'Superblock' of each filesystems listed in /etc/fstab and marked with a '1' or a '2' in the 'pass' column. The superblock contains information such as a counter that counts the number of times the file system has been mounted since the last time it was checked. Normally, file systems are scheduled to be checked around once every 30 mounts, or every six months, whichever comes first. (Some Linux systems, such as servers, may be left running for extremely long times between reboots. I have read of Linux servers running for three years or more without a reboot). How to take a look at your ext4 superblock. If you have had a power interruption, or turned your computer off the wrong way, the filesystem will be marked as 'unclean', and your operating system will do a filesystem on re- booting for sure, regardless of how recently it has been checked previously. With ext4, the file system check is very quick and you won't be kept waiting very long. Always be patient and wait until the file system check completes. Cancelling a file system check that's in progress or rebooting can cause severe file system damage. Minor errors will be automatically corrected, but if there are any bad problems it lets us know to run another filesystem check manually to fix them. How to do that is explained a little further down this page, see Running a filesystem check on an ext4 filesystem. If the filesystem is corrupted or missing we get an error message to say 'Bad magic number in superblock when trying to open /dev/sdx,y'... Most often this just means that you or I forgot to edit the etc/fstab file with the changed file system UUID numbers after the last time we used disk partitioning software to add or remove one or more file systems. The filesystems that the operating system expects to be there is gone and maybe there is a different one there instead. Just press 'Ctrl+d' to exit the shell and continue booting, update your /etc/fstab file and most of the time that will solve the problem. Here are two a great links from 'Tips For Linux Explorers', you should read: |
| Why Linux filesystems never need defragging Linux file systems like a file system check now and again, but they never need defragging. Okay, maybe 'never need defragging' is an exaggerating a little. They can begin to get fragmented when more than around 80% of the available space is used up. Make sure your Linux partition is large enough to contain all the files you want and still leave at least 20% spare. If it gets too full, either delete some files or resize your partition. OneAndOneIs2 - Why doesn't Linux need defragmenting?
ITworld.com - Fragmentation and Unix file systems |
|
The Old Fashioned Methods for Filesystem Mounting
|
| What does 'mounting' a file system mean? When your computer boots up, the boot loader finds your Linux kernel and loads it into the RAM. The kernel runs boot-up scripts and checks the file system before mounting it. I think of it as something similar to mounting a horse. In that analogy, you're getting on top of it, (in the saddle), and you're controlling it. (or trying to). So, the Linux kernel is taking control of the file system on the hard disk. When we 'mount' another file system under the file system we're already using, we are attaching it somewhere, (at a 'mount point'), and the Linux kernel takes control of the next file system too. Now we can read and write to it maybe, or whatever is appropriate. |
There are two traditional ways to mount filesystems in Linux, these are,
Tuxfiles is a great website with an excellent page on How to mount filesystems in Linux - 1.1 That can be read in addition to this page, it often helps to read things explained in slightly different ways. |
| The 'mount' command method for mounting How to mount Linux ext3 or Reiserfs, Windows FAT or NTFS, .iso files and floppy disks from the command line. Advantages and when to use this method
How to use this method (a) find filesystem details (partition number, filesystem type) (b) make a mount point if one doesn't already exist (c) run an appropriate mount command in terminal (a) find filesystem details (partition number, filesystem type) One way is to use the sudo fdisk -lu command to list partition details if you are doing this from a Live CD, this is the most popular, example:
A different command you can use is 'blkid'. The 'blkid' command is slightly more informative. Code:
Another way to see which partition, or more correctly, file system, you want to mount is to take a look with a graphical partition editor like GParted. (b) make a mount point if one doesn't already exist Use the ls command to take a look in /media to see if there's already a mount point you can use, Code:
Example:
If there isn't one use the mkdir command to make a new directory in /media as your mount point
If you are making a mountpoint for a Windows partition, you might want to call it 'Windows'. (c) run an appropriate mount command in terminal You are welcome to pick out one of these that best fits your needs and copy and paste it into your terminal to save typing. You might need to modify it to suit your computer first before you enter it though. For a partition with a FAT32 filesystem
Where: the mount point you made for it is named /media/windows Where: your windows has the fat32 file system If not, please alter the command to suit your particular computer's setup. We can do anything we like with the FAT32 Windows filesystem. We can open files with Ubuntu applications and work on them and save the changes, copy files out, and paste files into the FAT32 filesystem. Any 'other' operating system with the FAT32 filesystem is ideal for dual booting with Ubuntu. For a partition with an NTFS filesystem What is NTFS? - ntfsprogs website, www.linux.ntfs.org
Where: the mount point you made for it is named /media/windows Where: your windows has the ntfs file system If not, please alter the command to suit your particular computer's setup. Note: The NTFS filesystem is mounted 'read only', so we can only copy things out of it, we cannot paste things into it or alter any files while they are in the NTFS filesystem. Thanks to: How to mount you NTFS volume - ntfsprogs website, www.linux.ntfs.org For a partition with an EXT3 filesystem
Where: the mount point you made for it is named /media/ubuntu Where: your Ubuntu has the ext3 file system If not, please alter the command to suit your particular computer's setup. For a partition with a reiserfs filesystem
Where: the mount point you made for it is named /media/ubuntu Where: your Ubuntu has the ext3 file system If not, please alter the command to suit your particular computer's setup. |
To mount an .iso file
Where: the name of the file is 'mycdrom.iso' Where: the mount point you made for it is named '/media/mycdproject' If not, please alter the command to suit your particular computer's setup. Note: We can read and copy from a mounted .iso file but we can't write to one. At least I haven't been able to find out how. To alter an .iso file we mount it so we can copy the contents to a regular directory. Then we do whatever work we need to do, and then make a new .iso file out of the directory with a genisoimage command. Click the following link to look further down this page for some information about genisoimage commands. If you want to see a worked example of this process in action, look at this link, How To Build a Super GRUB Disk/GParted/Puppy Linux CD / DVD, you can try it out too if you want! |
| Mount a floppy disk Before you try to mount a floppy disk, don't forget to slide the little plastic square in the corner to close the hole first before you insert it in the drive if you want to write to the disk. These days with Hardy Heron and later versions of Ubuntu, it looks like we can just go 'Places' --> 'Removable Media'-->'Floppy Drive', as illustrated in Filesystem mounting basics. Here is the traditional way, using the command line, Code:
Be sure to 'write-protect' your floppy disk as soon as you are finished by sliding the little plastic square to open the extra hole in the corner, so both corner holes are open. How to Write-Protect a Floppy Diskette - HelpDesk (external link). Another way to mount and unmount a floppy disk is to install a little program called 'disk mounter' with an icon in your top panel. Just right click on your top panel (Ubuntu for 'tool bar'), and click 'add to panel'. In the window that opens, scroll down and look for 'Disk Mounter', it has an icon that looks like a floppy disk. |
| Rescue your Linux Operating System with a Live CD Linux is immune from viruses but it isn't immune from operator error. If you 'borked' your system and have problems booting, you can usually rescue your Linux operating system with your Live CD, here are two ways to gain access to your important files to fix them. NEW: GUI method for Hardy Heron and Later 1) Boot your Ubuntu 'Desktop' LiveCD 2) Click 'Places' -->' Removable Media', and click on an icon.
3) Click 'Applications'-->'Accessories'-->'Terminal', and after the terminal prompt, type 'gksudo nautilus'.
4) Click the Up arrow to go to the top of the live CD's file system tree. 5) Open the /media directory. You'll see any mounted file systems in /media as directories. (Mount points). If your file system has a label, the mount point you're looking for will be easy to identify. If your file system isn't labelled, look in 'disk', disk-1', 'disk-2' and so on until you find the file system you need to work on. 6) Some vital files people might need to use the LiveCD to edit would include:
=================================================== TRADITIONAL METHOD: for Ubuntu Gutsy Gibbon and Earlier 1) Boot your Ubuntu 'Desktop' LiveCD 2) 'Applications', Accessories,'Terminal'. Enter the 'sudo fdisk -lu' command to get detailed information about your hard disk partitions. This information will be needed for making up the 'mount' command correctly. code:
3) Pick out the partition you think is the right one to mount. For example, this time I have decided I want to mount /dev/hda2 . I know that that is my Ubuntu install, and I remember it has the ext3 filesystem. 4) Make a 'Mount Point'. Either type, or copy and paste the following code into your terminal, Code:
5) Mount your disabled Ubuntu operating system in the Live CD, Code:
Where: the /dev/hda2 partition contains an ext3 file system. If your Ubuntu partition is not /dev/hda2, you will need to edit the above command before you can use it for your particular system. Okay, now my hard-disk installed Ubuntu operating system is mounted in my Ubuntu Live CD operating system. To check, I went up two levels the top of the filesystem and opened my /media folder. (In GUI mode). Inside that was my new 'ubuntu' folder. I opened my /media/ubuntu folder to see my Ubuntu root files. We can take a look around in GUI mode and copy stuff alright, but we are not to allowed to save any system changes. For any serious work, we need to use the terminal. 6) Some vital files people might need to use the LiveCD to edit would include:
/boot/grub/menu.lst Here's how to open and edit the /boot/grub/menu/lst file in the Linux (Ubuntu) partition we just mounted, just in case anyone finds that handy. code:
This website's GRUB Page has a lot of information about how to edit your menu.lst file. /etc/fstab In some cases a problem in your /etc/fstab file can make your installed operating system unbootable too, this livecd mounting method shown above an also be used for gaining access to that.
/etc/X11/xorg.conf
This website's Xserver Page has some links about /etc/X11/xorg.conf. Remember to make a backup copy before editing any file. /home/username/*
In this example, they will be copied to a USB external hard drive. See also this website's SSH Network for Linux File Rescues to a networked computer. |
| Edit /etc/fstab Method for Mounting The /etc/fstab file in Ubuntu is an important operating system configuration file that is made when Ubuntu is installed, and is needed for Ubuntu to boot. The /etc/fstab file controls what file systems are mounted automatically when our computer boots up, how to mount them, what rules to mount them with and whether they will be given a file system check first or not. We can modify our /etc/fstab files to customize the behavior of our operating systems to our liking or needs. Usually we might decide to do that after we have added new partitions and file systems to our computer. Advantages of mounting your other filesystems by listing them in /etc/fstab is that they will be checked and automatically mounted during each bootup. You won't have to bother doing it manually. You might use this method if you need to access other file systems all the time. It's very quick and convenient. Disadvantages of mounting your other filesystems by listing them in /etc/fstab are that if a filesystem check is enabled during bootup before the other filesystems are mounted (recommended), it can slow down your boot up or maybe even stop you from being able to boot normally if there is a problem. From a security point of view, if you decide to keep confidential files, (and who doesn't?), you might find it a little bit safer to keep those in a partition that will not be automatically mounted all the time. You can mount it yourself, but only when you need access to the sensitive data. That way people with network access to your computer or even physical access will need to work a little bit harder to get at the protected information. Depending on the nature of the information you should possibly look at other security measures too, but at least not having the file system mounted all the time in the first place is a step in the right direction.
Normally the columns are not very neat or straight, which makes it a little harder to make sense of, but that's the way they are.
Here is some general information about what commands or info goes in each column in /etc/fstab and what it is supposed to mean.
So let's pretend I have made a few new partitions in my hard disk and I want to add lines for them into my /etc/fstab file so they will be automatically mounted at each boot-up. I made a new FAT32 data partition, a new NTFS data partition, plus an ext3 data partition and a reiserfs data partition. First, before we do anything, we'll make a backup of /etc/fstab, code:
It is not a good idea to create a second backup of the same file using the same filename again though, as that will overwrite your original back-up and if you ever need that again you won't have it. It might be a good idea to include some numbers, such as the date in filenames. How to use this method (a) find filesystem details (partition number, filesystem type) (b) make your mount points if they don't already exist (c) edit /etc/fstab with the correct details for mounting the filesystem automatically each boot up (a) find filesystem details (partition numbers, filesystem types) I used the ls /dev/disk/by-uuid/ -alh command to list the UUID numbers for the filesystem types I have, Code:
I'll need this because I'm going to copy some of these UUID numbers into my /ect/fstab file soon.
I'll need to leave this open so I can use it to help me edit my /etc/fstab pretty soon. (b) make a mount point for each file system if one doesn't already exist Use the ls command to take a look in /media to see if there's already any mount points I want to use, Code:
Example:
(c) edit /etc/fstab with the correct details for mounting the filesystem automatically each boot up It is best to open a new terminal in another desktop to do this, so you can copy and paste to transfer information from the commands we entered in (a) above to the /etc/fstab file. To get my /etc/fstab file I type 'sudo gedit /etc/fstab' in a terminal. like this, Code:
These are the lines I'll add to my /etc/fstab file to mount my FAT32 data partition, number 6 in my hard disk, or /dev/hda6 code:
These are the lines I would add to my /etc/fstab file to mount my NTFS data partition, if I had one. What is NTFS? - ntfsprogs website, www.linux.ntfs.org It wouldn't really make any sense to have an NTFS data partition for Linux, this is just for demonstration purposes, code:
Refer to Feisty Starter Guide's 1.14.1.4 How to mount Windows partitions (NTFS) on boot-up, and allow all users to read only and, How to mount your NTFS volume - ntfsprogs website, www.linux.ntfs.org Here is the line for mounting my ext3 data partition which is my number 8 partition on hard disk, or /dev/sda8, Code:
Here is the line for mounting my reiserf data partition which is my number 9 partition on hard disk, or /dev/sda9,
The UUID numbers won't be colored, they'll be black, but I left them colored for the illustration. File Ownership and Permissions If you have trouble copying and pasting or reading and writing data from one file system to another there could be a problem with your file ownership and permissions. Refer to this webpage's File Ownership and Permissions
|
|
Mount an .iso file in /etc/fstab This fstab entry can automatically mount an .iso file for you at each boot up, and give you a desktop icon for it. Code:
To get the partitions to mount now we just have to enter this command in terminal,
To the best of my knowledge it is not possible to mount an .iso so you can edit the file directly. Mounting an .iso file allows you to browse the files in it without the need to burn it to a CD first. If you want to edit the .iso file, the only way to do it is to copy all the files out of it, and paste them into a directory. Then edit the files, and re-run a genisoimage command to make the directory into a new .iso file with the same filename as the .iso you already had, to overwrite it. See: genisoimage commands for making .iso files to burn to CDs and DVDs |
| Updating Filesystem UUID Numbers in /etc/fstab After doing work with a hard disk partition editor and deleting or creating partitions and file systems, our /etc/fstab files always need to be updated with the recent changes. If we forget, then booting will be interupted with a file system check error and we'll need to press 'Ctrl'+'D' to continue each boot-up. Here's an example link, Problem in mounting special device at boot. Ubuntu's /etc/fstab files since Ubuntu 6.10 'Edgy Eft' use file system UUID numbers instead of just partition numbers to specify the exact file systems to be mounted. That makes it easier for people who like plugging in different hard disks or whose partition numbers get changed. Here is one command that can list the UUID numbers of our current file systems,
If that one doesn't work, try this one,
Example output:
Open your /etc/fstab file with this command,
Be sure to carefully compare the UUID numbers listed in your /etc/fstab file with the ones from the 'sudo blkid' or 'ls /dev/disk/by-uuid/ -alh' command. Check each partition.
It is really not too difficult to edit your UUID numbers in /etc/fstab once you get used to it. If you use LiLo for booting or if you just don't like having UUID numbers in your /etc/fstab file and don't want to use them, you don't have to. You can make your /etc/fstab file back into a traditional style one like you were used to. Just remove the hash mark before the regular '/dev/hda' style partition designator and delete the UUID numbers. New lines can be added in the traditional manner with or without the new UUID, it will work the old fashioned way. Here's a Ubuntu Web Forums thread on UUIDs: fstab UUIDs? ( 1 2 3)
mattisking
Here are some more commands that can be used to get file system UUID numbers. To find the UUID number for just one partition, any of the following commands will be fine, Code:
When you know it's an ext2 or ext3 file system, gives lots of information Code:
For a reiserfs superblock, this gives the UUID plus a lot of other interesting info, Code:
|
| File Ownership and Permissions Gnu/Linux file systems feature the ability to keep track of who owns each file and control who's allowed to read it, write to it and who's allowed to execute it, (especially if it's a program). This is useful if you share the same computer with other users and it's particularly important if you have any kind of server software installed in your Ubuntu operating system, see SSH Network. In normal GUI mode if you right-click on a file or folder and click 'properties', and look in the 'Permissions' tab you will be able to see the file's ownership and permissions. Normally in a person's own /home/username directory all of the files will be owned by the user, so in my own /home/herman directory I can do whatever I want to my own files. Operating system files or all files not in a /home/username directory are normally owned by 'root', and we are not allowed to create, delete or edit those files without typing the word 'sudo' before the command and entering our sudo (administrator's) password. This is an important security feature in Gnu/Linux operating systems and it helps to protect the operating system files from careless or malicious users, malware and viruses. A better way to look at your Gnu/Linux file ownership and permissions is with the ls -l command. With the command line we can see a whole list of files at once instead of just looking at one file at a time. The 'ls' is short for 'list', and the -l option stands to 'long', meaning 'detailed'. The /media and /mnt directories are interesting. They contain some files which are owned by a user and others which are owned by root. Use 'ls -l' for a list of files and their file permissions and ownership details, for example,
example output,
In the first column, The first letter could be a 'd' or an l, (d for 'directory' or l for 'link'), if it's just a file you will not see anything there. The next nine letters or dashes tell us the security settings for the mount point or file, (more about that below). The second column has a number in it which tells us how many directories are inside that mount point. The third and fourth columns show the owner of the file and the name of any group to share it with. The fifth column is supposed to show the size in bytes but I'm not sure how accurate that is. The sixth column displays the date and time the file was last modified. And finally, the seventh column show us the name of the file or directory. The directories we're looking at right now are special directories called 'mount points' and they're like a doorway into another file system, in another partition. Now I want to expand on what the letters in the first column represent. The nine letters or the letters and dashes like 'drwxr-xr-x ' represent the file's permissions. r stands for read, w stands for write, x is for execute, (open it with a program), and - (a dash) means no permission. There are three sets of three letters and dashes because there are three kinds of computer users who can access files. These are the file's owner, the file owner's group (friends), and anyone (possibly strangers). Each of these kinds of user can be allowed seven different types of access to a file. Here's a table for quick reference,
NOTE: The numbers 1 to 7 in the right-hand columns in this table are to tell you what numbers to use for your chmod command, (below). The chmod and chown commands chmod - changes file permissions chown - changes file ownership If you just want to try out the chmod command, a useful thing to do to begin with would be to chmod your /home/username directory to make it private. As you can see from the ls -l command output shown here below, in a typical new Ubuntu installation my /home/username directory can be accessed by anyone, code,
output,
To fix that, I can use the chmod command like so,
7 - read, write and execute permisson for the owner, (myself, herman) 0 - no permission for members of the group 'herman' to do anything 0 - no permission for anyone to do anything Let's check and see if it worked,
Well, not unless they have administor (root) powers and can over-ride my settings. If somebody has a Live CD and they have physical access to my computer they can just chmod the folder again to suit themselves and still be able to read it and do whatever they want. In that case, chmodding your home/username directory would only deter polite intruders. For networking though, it's different. As long as you never give your guests administrative powers, (which would be rather foolish), then setting your file permissions for your /home/username folder would be quite effective and a highly recommended course of action. A minor problem will be if I ever need to rescue my files, I will just need to use the chmod command again to gain access to my own files. Probably that's why Ubuntu doesn't come with the /home/username folder already chmodded at installation time, it would make it a little harder for new users who might not know about the chmod command to rescue their files with a Live CD when they 'bork' their systems. Another popular example of the use of the chmod command would be when I make a bash script to run a sequence of commands with. To make it executable I would type: sudo chmod 755 myscript.sh and that would mean I can read, write and execute (run) my script or program but anyone else can only execute it. That's '7' for me, '5' for my group, and '5', permission for anyone else. example,
If you need to use both the chown plus the chmod commands Let's take another look at the mount points I have in my /media directory I showed you earlier,
The top line is my encrypted file system which may contain confidential information and the next line down contains the bulk of my stored data, which also may contain files that I might prefer to keep private. If I were to allow other people into my computer, either by creating an ordinary user account for them and letting them sit at my desk using my keyboard, monitor and mouse, or if I allow other people to enter my computer via the LAN network or internet, then I will need to change the ownership and permissions for these mount points. Even the encrypted file system is easy for anyone else to see once I enter the password and have it mounted. File system encryption is great to keep people with physical access to the media from accessing your data, but it doesn't do anything for people with network access. This is where linux file ownership and permission rules are useful.
The results,
Now I can still have full access to my own files but any others who may have a user account in my PC, whether they have direct access to the computer or they access it via the network cannot easily see my private files. WARNING: When you're chmodding and chowning mount points, avoid using the -R option, (unless you know what you're doing). The -R option means 'Recursive', so it changes the permissions of all the directories and files inside the folder you run it on as well as the folder itself. Probably most of the time you don't need it and it would be 'overkill'. Not only that, but if you get in the habit of using the -R option and you ever use it on a mount point for a file system containing an operating system it will probably ruin all the file ownership and permissions settings for the entire other operating system. That would 'bork' the operating system and you'd need to re-install it. It's usually (but not always) okay to use the -R option if you're just using it on a directory full of normal (non-operating system) files. How to Create Users and Groups You can create a new group if you go 'System'->'Administration'->'Users and Groups', and click on the 'Manage Groups' button. Just for an example, let's imagine we're members of a cycling club and we want to set up our computer with SSH server software so we can keep in touch and share maps and pictures and other route information about our bicycle tours between members of our bicycle club. Click 'Add Group', and then make up a name for your group, say 'bicycleclub' and click 'Okay'. Now if you go back to 'Users and Groups', you can add each member of your bicycle club to your list of registered users of your computer. Just fill in the form 'New user account', and before you close it, in the advanced tab, make sure you remember to add your new user to your bicycle club. Each of your bike club members will have a /home/username folder of their own that they can use in your computer, either by direct access or by SSH network, if you have that set up. SSH Network. Gnu/Linux operating systems gives you the adminstrator, the flexibilty to control what information gets shared with whom. You can do that by using chmod and chown commands. If you're not sure you understand Gnu/Linux file ownerships and permissions and the use of the chown and chmod commands, the best way to learn is to experiment and practice with them. You'll soon get the hang of it. Tuxfiles has a great page on how to use the chmod command, Linux File Permissions Tuxfiles has another great page on how to use the chown command too, How to change a file's owner and group in Linux - 1.0 See also FilePermissions - Understanding and using file permissions - Ubuntu Community Docs. |
| The ext series of file systems are
the by far the most popular and best supported Linux file systems. Ext - The first Extended Filesystem (ext fs), was designed by Rémy Card and implimented in Linux in April 1992. Link: Extended File System - wikipedia Ext2 - the ext2 file system was the second in the series, also by Rémy Card and introduced and January 1993. Many people still use it. Link: Ext2 - wikipedia. Ext3 - the ext3 file system, developed by Stephen Tweedie and introduced in 2001 is backwards compatible with ext2 and is basically the ext2 file system with journaling added. Ext3 has a reputation for being very safe and stable and was the default file system for Ubuntu up until Karmic Koala. Link: Ext3 - wikipedia. Ext4 - features a lot of great improvements over ext3. Theodore Tso is the lead developer of ext4. Ubuntu was the first Gnu/Linux distro to feature the ext4 file system as the standard default file system and ext4 has been the default file system for Ubuntu since Karmic Koala was released on 29 October 2009. Ext4 features a default block size of 4 KiB or 4096 bytes, which divided by 512 equals 8 sectors, and uses 'extents' of 128 KiB, or 256 sectors, making it particularly agreeable to erase block alignment in SSDs and flash memory applications. Link: Ext4 - wikipedia.
Running a filesystem check on an ext series filesystem Here's the best way to run a file system check from the command line (terminal) for a Linux live CD or from a hard disk installed Linux after you unmount the file system first. Code:
With these options, e2fsck can solve quite a large number of file system problems, even some quite severe ones. This is a very effective command, and very beneficial to your file system. It never does any harm, only good. You could run this command regularly to keep your file system in good order. I use this one myself quite often. That command will normally fix 99% of all file system problems. If it doesn't, you might get one of these two classic error messages 1,
1. If you have the first error message, jump to What to do if you have a bad ext3 superblock. 2. For the second error message, carry on with the steps below. 2. Oh-oh! That means e2fsck has found a problem it doesn't want to deal with without human supervision. Maybe some files will need to be unlinked and sent to the /lost+found directory! e2fsck doesn't want to do that by itself, e2fsck wants you to hold it's hand so it knows you're aware of what's happening. You'll need to to run something a little stronger. First, backup (or rescue) all your important files (if you still can). Then run a more 'heavy-duty' e2fsck command, probably one something like this one,
If that doesn't fix just about any problem you might have with an Ext* file system then I don't know what will! Check for files in your /lost+found directory afterwards, you may need to recover a few of your files again from your lost+found directory. Recovering files from lost+found If you needed to run a file system check as severe as this, I recommend you also try the next two commands as well, in case there are bad blocks in your hard disk. This one is more for coping with bad blocks in your hard disk.
When this command is needed it's probably time to start shopping for a new hard disk, but this will help you keep your old hard disk running just a little bit longer. NOTE: Some web pages recommend 'sudo e2fsck -cc -k -v /dev/sda2'. |
| Recovering files from lost+found After running a command like e2fsck -y -f -v /dev/hda2 or reiserfsck --rebuild-tree, you should check your lost+found directory in case the file system check had to move some files there. You might have a few files missing from their proper locations and you might be able to restore them from lost+found. I think it's just for recovering personal files because the files will be saved without their file names. If you have operating system files in the lost+found it would be hard to identify them, they'll be useless without their original filenames, so in that case you'll probably need to re-install. At least you can probably recover any personal files like photos and bank records or whatever. Confused57 reported that he had all of the files in one partition sent to the /lost+found and he just did 'sudo nautilus', and recovered all his files this way, Quote:
It's hard to find information about how to recover files from /lost+found, so any information on this subject is very much appreciated. This is the most recent and reliable advice I have so far. Thank you so much for that good information, confused57, that sounds like the best way to do it! :) That will surely be likely to help someone out of a bad situation. I have spent hours searching the internet and here is the best link I have been able to find on this subject so far, (it's a .pdf file), [PDF] Untitled File Format: PDF/Adobe Acrobat - View as HTML The first thing to do when exploring an ext2 or ext3 lost+found directory is. to prepare an area on another disk to which you can temporarily copy files ... www.oreilly.com/catalog/morelnxsvrhks/chapter/hack 96.pdf - Similar pages Here are some more links on /lost+found, http://www.tldp.org/LDP/Linux-Filesy...lostfound.html http://www.sunmanagers.org/pipermail...er/005866.html http://archives.free.net.ph/message/...c72f03.en.html http://ubuntuforums.org/archive/index.php/t-229143.html |
What to do if
you have a bad ext3
superblock
...and this one: Understanding UNIX/Linux filesystem Superblock First, before you do anything, check to make sure that it is really an ext3 filesystem that you were trying to run a filesystem check on when you received the warning message about the superblock being missing or corrupted. 99 times out of 100, there is nothing wrong except the user (you or I), made a mistake when typing the command or we forgot to update /etc/fstab after changing partitions around with partition editing software. Maybe the partition number you used refers to a partition that used to contain an ext3 file system but you have some other file system in that partition now. Here is a command that you can use to check,
This command can be used to tell you where there might be backup superblocks to replace your corrupted one with.
Using one of the numbers from the output from the above command, now you do something like this, 'sudo e2fsck -b 32768 /dev/hda6'
If not, try again with different number. |
| How to take a look at your ext3 superblock The dumpe2fs command is for taking a look at your ext3 superblock, for example, Code:
|
| What to do if your ext file system doesn't fit your partition Here is what to do if your partition looks like it's full when you know it really shouldn't be, or if programs like fsck complain that your superblock is boasting of a larger file system than your partition size can actually accomodate. Code:
The resize2fs command is used to calibrate the size of the file system to the size of the partition. The file system needs to be unmounted to do this, so it's probably best if you can do it from a LiveCD, or at least from an operating system in a different partition, making sure to unmount the file system in the partition you want to work on. Example threads, ext2/3 super block repair? (block count wrong) |
| Using e2label to set a filesystem label an ext4 filesystem Here's a really cool customization that'll make your day-to-day computing chores easier and more fun! Set labels for your ext2, ext3 or ext4 file systems. This idea is great for USB flash memory sticks with ext2 or ext3 file systems, especially if you have more than one USB flash memory stick and you want to be able to tell which is which. File systems in your hard disks can be given labels too. This makes a great improvement to Hardy Heron's new click-icon mounting ability. A file system that has been give a label will stand out from other file systems when you look for them among the icons in your 'Places' menu, (see Filesystem mounting basics). Rather than just appearing as '40.0 GB disk', or 'disk-1' or something dull and boring like that, your file systems can each have a recognisable name and they'll be mounted with that name too. It's easy to set a label for an ext2, ext3 or ext4 file system, just run the e2label command, and give your file system a name. A descriptive name is often useful, but you can choose give your file system a pet name or any kind of name you like. All you have to do is take a look at your partition table with fdisk, as shown below,
As you can see, my usbdisk is called '/dev/sde1', by the Linux kernel. I need to use that for the next command.
From now on my usbdisk won't just appear on my desktop as 'usbdisk', it will be labeled 'WEBSITE'. All ext2, ext3 and ext4 file systems can be labeled as easily as that and having them labeled is very convenient if you have several ext2, ext3 or ext4 partitions in your hard disk(s) and USB flash memory sticks. It is quite safe to run e2label at any time to set a label or change any label on any ext2 or ext3 file system. Your file system labels will show up in Gnome Partition Editor too, (GParted). Related Link: RenameUSBDrive, - Community Docs. Thanks Mylorharbour for prompting me to update file system labeling and and emphasize it more. |
Handy ext2 and ext3 commands,
|
| Working with the Reiser File System The original home page for ReiserFS was, http://www.namesys.com/, but that link will be down for the foreseeable future. The alternative home page for namesys it this one, ReiserFS - webarchive.org. The Reiser File System is great for busy partitions containing a lot of small files because it is up to fifteen times faster than most other file system for writing small files. ReiserFS was the first Linux file system to feature file system journaling. File system journaling makes it easy to recover after a crash, (like when my dog suddenly unplugs my power cords from the wall). If for some reason journalling isn't wanted, we can easily turn off file system journaling in the ReiserFS simply by adding the mount option 'nolog' to our /etc/fstab files. Example:
ReiserFS also features 'tail packing', and can save around 6% disk space, but at the expense of some of the extra speed. If you want speed, just leave the 'notail' option as it is. If you're cramped for room and you need to pack your files into a smaller amount of disk space, delete the 'notail' option from your /etc/fstab line.\ Because of reiserfs's reputation of being up to 15x faster than ext3 for small files, a few Gnu/Linux users, especially some from the Arch Linux distro like to advocate the use of multiple partition installations with ext file systems in most partitions and reisers for /usr and /var partitions. Some people believe this can result in faster operating system performance. They could be right especially if it's done in conjunction with some kind of short stroking strategy across two or three large capacity hard disks. Personally I like to stick with the simplicity of a single partition installation. I used to prefer reiserfs for flash memory but that was before ext4 came along with its SSD/flash memory enhancements and in my tests there doesn't seem to be enough difference in speed between ext4 and reiserfs to convince me to use reiserfs right now. I have not tried reiser4 as yet though, sorry. I will do some reading about reiser4 and look into it sometime soon. Finally, Reiser4 Benchmarks Against EXT4 & Btrfs - phoronix UPDATE: As far as I know Reiser4 isn't finished yet and won't be supported by the Linux kernel at least for the time being. Running a file system check on a Reiser File System The easiest way for new users to run a file system check in a partition containing a Reiser File System is to boot your Ubuntu 'Desktop' live CD and Run a filesystem check with GParted (a user friendly GUI method). GParted will run 'reiserfsck --yes --fix-fixable --quiet /dev/sdxy' for you. The following information is for those of us who prefer to use the command line, or if GParted couldn't fix it. In the following examples, the file system to be checked is in partition /dev/sda2, yours will likely be a different number, so please check with 'sudo fdisk -lu', or 'blkid', or open Gnome Partition Editor (GParted), and take a look. Always dismount a filesystem (partition) before running a filesystem check. Code:
--check Here we go now, this is the command to run first, Code:
Make sure you type 'Yes', (with a capital 'Y') after the prompt, or nothing will happen. This runs a quick check (takes a look around), and tells you if anything is wrong. This is a safe command for anyone to run at any time you like. It doesn't fix anything, but you can use this whenever you want to perform a routine disk check or any time you think something might be wrong with a reiser file system. The feedback from this quick check will tell you if any more work is needed. Exit status 0 means no errors were discovered, (you can relax and be happy). Exit status 1 (and a report about fixable corruptions) means that you should run reiserfsck again with the --fix-fixable option. Exit status 2 (and a report about fatal corruptions) means that you need to run reiserfsck again with the --rebuild-tree option. If reiserfsck --check fails in some other way you should also run reiserfsck again with the --rebuild-tree option. --fix-fixable If 'reiserfs --check' reports back that something needs fixing, (or exit status 1), you need to run reiserfsck again with the --fix-fixable option.
NOTE: After you press 'enter', you will see a message to let you know what reiserfsck will do for you and asking you to confirm. Make sure you type 'Yes', (with a capital 'Y') after the prompt, or nothing will happen. The above command should fix most problems the average user will ever have with the reiser file system. --rebuild-tree If 'reiserfs --check' reports back that it found some fatal corruptions, (or exit status 2), that's a little bit more serious, and the --rebuild-tree option will be necessary. You really should make a backup of you data first (if you haven't done so already), as this command may unlink some data to the lost+found directory, see Recovering files from lost+found. This may not be a safe option for new users, you might want to seek advice from more experienced Linux users before using it. Here it is anyway,
NOTE: After you press 'enter', you will see a message to let you know what reiserfsck will do for you and asking you to confirm. Make sure you type 'Yes', (with a capital 'Y') after the prompt, or nothing will happen. For more reiserfsck command options, type 'man reiserfsck' into your terminal,
This link here is quite helpful too, Repairing ReiserFS file system with reiserfsck - nixCraft If you just want to see what's written in your reiserfs journal header,
Setting a Volume Label in a Reiser File System It's a very good idea to give each of your file systems a label, especially if you have a few of them. The easiest way if you have Ubuntu 'Intrepid Ibex' or later, is to open Gnome Partition Editor and right-click on the partition and click 'LABEL', (or something like that), and give the file system a name. If you have an older version of Ubuntu, or if you love the command line, here is an example of how to set your file system label in a Reiser File System, Code:
Where: I want to name it 'DEBIAN" Now whenever my Reiser File System is mounted, it will be given a mount point in /media named "DEBIAN" and the name 'DEBIAN" will appear under the icon on my Ubuntu desktop. It will also be listed as "DEBIAN in Gnome Partition Editor and when I run the command 'sudo blkid' too. ReiserFS Commands: reiserfs - mkreiserfs - creates a Linux ReiserFS filesystem on a device (usually a disk partition). reiserfsck- searches for a Reiserfs filesystem on a device, replays any necessary transactions, and either checks or repairs the file system, (depending on the options you use after the command). resize_reiserfs - resize_reiserfs - resizer tool for the ReiserFS filesystem reiserfstune - The tunning tool for the ReiserFS filesystem. debugreiserfs - The debugging tool for the ReiserFS filesystem. Mount options More links about Reiserfs: O'Reilly's Hacks: Hack 95. Repair and Recover ReiserFS File Systems The structure of the Reiser file system by Florian Buchholz reiserfsck
|
| BTRFS The B-Tree File System Links: btrfs - Ubuntu Community Documentation |
| JFS Journaling File System Links: JFS Filesysem - archlinux wiki JFS For Linux - sourceforge |
| XFS Links: XFS - Wikipedia, the free encyclopedia XFS: A high-performance journaling filesystem - Introducing XFS - Advanced filesystem implementor's guide |
| SQUASHFS What is SquashFS - tldp.org squashfs - sourceforge SquashFS HOW TO - tldp.org How to mount casper -rw in persistence USB install Some people like to install Ubuntu in a USB flash memory stick and use it like a regular Ubuntu installation. Currently the two most popular ways to make a Live CD persistence type of Ubuntu installation in a USB flash memory drive are by using the Ubuntu Startup Disk Creator or by running third party software from Pendrive Linux. At some time it might be necessary to be able to access the user's saved files inside the USB installation, but this isn't always easy for new users. You need to know how to use a few Linux commands. Here is an example of the commands needed to make a backup or perform a file rescue from a Ubuntu Live CD Persistence type of installation in a USB drive when you're working from a real Ubuntu operating system. From: Casper-rw -- How to Access - Ubuntu Web Forums First, plug in your USB drive with the Ubuntu Startup Disk or Pendrive Linux type of Ubuntu CD install. Then, open a terminal up and use the following commands to mount your file system,
A folder should open and you should be able to navigate to your personal files in your Ubuntu Startup Disk or Pendrive Linux Persistence USB installation. Perform your file backup or file rescue or whatever. When you're done, you can dismount the file system and delete the mount point to clean up with the following commands,
|
|
Running a filesystem check on a FAT32 filesystem You might have a FAT32 data partition or a USB disk that you need to run a file system check on but you might have a Linux-only computer. From Ubuntu
From GParted -- LiveCD
If you have a Windows operating system and you can use CHKDSK from Windows, then you might need to do that instead or Windows might not recognize it. I don't know why that is. |
| fat32 usbdisk volume label If you have more than one an external usb thumb drive with a fat32 file system you can set a disk label so that every time you plug your usb disks in they will have a name so you can tell which is which. To set a file system volume label in a usbdisk with a fat32 file system, mkdosfs [ -n volume-name ] device worked for me, use sudo fdisk -lu to work out which device it is first, (/dev/sd??) then apply the command, for example: mkdosfs -n 10GBvfatdata /dev/sdf1 Make sure you back up your usb disk's data first!!! mkdosfs - create an MS-DOS file system under Linux. Next time the usbdisk is plugged in and mounted it will be mounted with that label.Make sure you back up your usb disk's data first, because this command makes a new filesystem!
Make sure you back up your usb disk's data first, because this command makes a new filesystem!
|
|
When there are 'differences between the bootsector and its backup' If there is a FAT32 (Windows) file system present in the machine, it usually has an entry in our /etc/fstab file made automatically when Ubuntu is installed. That means it will be automatically mounted during each boot-up. Ubuntu needs to check other file systems during boot-up to make sure they are in a fit and safe condition to write to, especially if they are to be mounted 'read/write'. A disaster could result if an attempt is made to write data to a file system already has some kind of small file system problem. The file system check is turned on by a number in the 'pass' column in our /etc/fstab file. Windows and other file systems would normally have a '2' in the 'pass' column so fsck will check them in parallel with any other file systems to save time during boot-up. You can change the number in the 'pass' column from '2' to '0' if you don't want Ubuntu to check your Windows file system at all, but I do not recommend that. The first sector of a Windows partition is known as the boot sector. Malware and viruses like to alter the code in a Windows boot sector so the malware or virus will be booted when Windows is booted, and/or to show you an ad as soon as your Windows computer boots. Another way to foul up a Windows boot sector would be by installing GRUB to it by accident. (GRUB should be installed to MBR, or a Linux bootsector, but not to a Windows bootsector). Fortunately, in Windows with the FAT32 file system, there is a backup bootsector which can be used to restore the original bootsector. I don't imagine there would be any Linux command you can use to fix the boot sector of Windows with the NTFS file system. It is only recently that Linux NTFS support has made NTFS safely writable from Linux. You would need to use FIXBOOT from a Windows recovery console. For Windows with the FAT32 file system you can do this in Ubuntu with a 'sudo' command. Make sure the file system is unmounted first, then use 'sudo dosfsck -ar /dev/hdx,y', or 'sudo fsck -V -r /dev/hdx,y'. WARNING: First try scanning your Windows system for viruses and malware with as many anti adware and anitvirus apps as you can get your hands on, as they may can your bootsector and find the virus by recognizing it's code in your bootsector. Replacing your boot sector with it's backup right away might not be the best idea. You really need to get rid of the virus first.
The example I will give here will fix your Windows FAT32 boot sector if you have accidentally made a mistake with the grub-install command and installed GRUB to the wrong partition. It is best to use a Live CD for this type of work, so the file system won't be mounted. In this example I used a GParted -- LiveCD. If you use a Ubuntu Live CD, you still need to use the 'sudo' prefix before each command. Code:
After entering either of these commands, the program will show you a report, so you can see for yourself what the differences are. Normally, the report would not be as large as the one shown here, and would only show a few bytes where the differences were found. This example was obtained by installing Grub to the FAT32 bootsector, which is not a recommended thing to do. (Don't try this at home, folks!).
1) Copy original to backup 2) Copy backup to original 3) No action ?
You type the answer after the '?' prompt.
You should be careful here. Most of the time I think it would be the original (the bootsector that is in use) that would be corrupted. In that case 99% of the time I would suggest typing a '2' so the bootsector will be restored from the backup copy. However, there was a thread recently in Ubuntu Web Forums where it was the backup that was found to be corrupt for some reason, and the user fixed it by typing '1' instead. Most of the time it should be '2', but be careful. Then, it will ask you to confirm,
That's it, it should be fixed!
Another way to fix it would be to run 'FIXBOOT' from a Windows recovery console. If it was a Windows virus that corrupted the boot sector, you would be best advised to re-install Windows and try to put your data back in again without any viruses this time. |
| NTFS and FAT32 File System Repair and Maintenance The NTFS file system is the preferred file system from Microsoft for most Windows XP and Vista users since it's supposed to add more security for the Windows Operating System. The NTFS file system needs a file system check every once in a while the same as any other file system and it's a good idea to do so. It is also recommended to run CHKDSK after the file system had been resized. Often that will clear up problems or at least keep things running well. In Windows XP, the program to use for running a file system check on a FAT32 or NTFS file system is CHKDSK. CHKDSK on bootup To schedule CHKDSK to run next time you reboot Windows XP, you can go 'My Computer',-->'Local Disk (C:), and right-click on 'Properties'. Open the 'Tools' tab, and in the 'Error Checking' box, click the 'Check Now' button. A 'Check Disk' window will open.
CHKDSK from Windows Recovery Console If an NTFS file system needs repair or maintenance, and Windows won't even boot, you may need to use a Windows XP Recovery Console, available from your Windows XP Installation disk (CD-ROM). If your computers came with a 'Recovery' CD or worse, a 'Recovery Partition' instead of a real Windows 'Installation' disc, you will need to go borrow a Windows XP 'Installation' CD from a friend, just to use the Recovery Console. The CKDSK has 'switches' (Windows language for 'options'), for specifying what you want the command to do. Here are a few links to explain what 'switches' you can use and what they do, Chkdsk - Microsoft, and An explanation of CHKDSK and the new /C and /I switches - Microsoft, and Sample Chapter from Microsoft® Windows® 2000 Professional Resource Kit. CHKDSK - ss64.com NTFS File System Checking from Linux If you want to you can induce Windows to run a file system check next time it boots on an NTFS file system from Linux, You'll need to install ntfsprogs.
Run 'man ntfsprogs' for a list of all the things you can do with ntfsprogs,
As you will see, the command for inducing a file system check on an NTFS file system from Linux is 'ntfsfix'.
|
| Restore an NTFS boot sector with it's backup Method 1 You may need to restore the backup for the NTFS boot sector if you have damaged it, for example by installing the wrong boot loader to it by mistake. If you have your Windows Installation CD or can get a Windows XP Recovery Console somehow, if you run the command FIXBOOT, it will fix your Windows boot sector for you. Lots of people are not given a Windows Installations disk, but a 'Recovery' disk, or a recovery partition and no CD at all. Method 2 In an NTFS partition, the backup of boot sector is stored in the last sector of the partition. If you run 'sudo fdisk -lu', it will tell you what sectors are the start sectors and end sectors of your partitions,
Method 3 TestDisk is a program you can install in Ubuntu, and TestDisk can easily restore the boot sector in an NTFS partition from the backup, or even rebuild an NTFS boot sector. TestDisk has their own page with illustrations, here is a link, TestDisk Step by Step. And here is the specific link, 12 NTFS Boot sector recovery. If you want to install TestDisk in Ubuntu, use a command like this,
To run TestDisk, you start it with the testdisk command,
|
| genisoimage commands for making .iso file to make CDs and DVDs CDs and DVDs use special file systems that are very different from the file systems we use for hard disks and floppy disks. The genisoimage command is used for making file systems that can be written to a CD. To use the genisoimage command you should type 'man genisoimage' into a terminal and read the man page about it first. Unfortunately the man page for the genisoimage command is almost impossible for beginners to understand. We need to begin with some understanding of the lingo and terminology peculiar to the world of CD/DVD making. CD and DVD file systems CD and DVD file systems include High Sierra, ISO 9660, Rock Ridge, UDF, and HFS.The genisoimage command can be used to make an .iso file with any of these file systems in it depending on what command options you use. High Sierra High Sierra, made up way back in 1986, was the first file system for CDs that was widely recognised and enabled CDs to be made that would be readable in different operating systems. By agreeing on certian standard rules, suitable drivers that match those rules could be made for various operating systems so that any CD can be made or played in any operating system. ISO 9660 ISO 9660 is a newer version of the High Sierra format, and was developed in 1988 with a few improvements by the International Organization for Standardization, (I.S.O.). There are three 'levels' of ISO 9660, level 1 is the simplest and safest, (you can be sure it will be readable by almost any operating system), while levels 2 and 3 add useful enhancements. ISO 9660 level 1 rules contain the following restrictions,
ISO 9660 level 2 CD file systems mostly conform to the rules listed for ISO 9660 level 1 (above), but the filenames can be longer,
ISO 9660 level 3 CD file systems mostly conform to the rules listed for ISO 9660 level 2 (above), but the files don't have to be contiguous,
Joliet The Joliet file system for CDs is recognized by Windows 95 and later operating systems, it is based on ISO 9660, but even longer file names are allowed, and directory names can have extensions.
Rock Ridge RRIP (Rock Ridge Interchange Protocol) is yet another extension of ISO 9660 made up in 1994 for support for Unix filesystem features like file permissions and things like that. Windows computers can still read a disc with Rock Ridge attibutes because it's based on ISO 9660, but the RRIP extensions are ignored when viewed in Windows. See also: Rock Ridge - Wikipedia, the free encyclopedia UDF Universal Disk Format- Packet writing is supported, enabling the writing of small amounts of data to a CD-ROM or DVD, just like you can to a regular hard disk. Filenames up to 255 characters long are supported. Computers with old CD-ROM drives, or old operating systems like DOS can't read these CDs unless the drive conforms to the 'multiread' specification. Most computers now have at least a CD burner or DVD/CD-RW optical drive and operating systems newer than Windows 95 or later. http://www.osat.org/specs/index HFS HFS is the file system for CDs used by Macintosh computers. Pure HFS can't be read in a PC based computer, but it is possible to burn a 'hybrid' HFS/ISO 9660 or HFS/Joliet CD that can be read by both kinds of computer. Either system will only be able to see the part of the disc that is compatible with it though. Aliases: If a file with a name that is too long is included in a CD, the file name will be automatically truncated at the filename limit by the operating system that is trying to read the disk. man genisoimage for more information.
Here's an example of the genisoimage command in action, this one is for making a bootable LiveCD out of a directory full of files, Code:
I still haven't got this one perfect yet, it doesn't have the correct md5sum, but it does make a bootable and usable Live CD out of the right files. Here's another one. Code:
How To Build a Super GRUB Disk/GParted CD / DVD. and How to make your own personalized GRUB CD-RW man genisoimage for more information. That's how to make a folder full of files into an .iso file. Copy a CD or DVD to an .iso file To do things the other way around and copy a CD or DVD to an .iso file, we use the dd command,
Where: 'username' is replaced with your own particular user name. Where: 'filename' is replaced with anything you want. |
|
Running a check for bad blocks on your hard disk Here's a great link from 'Tips For Linux Explorers', about this: Bad Blocks The command 'sudo badblocks -sv /dev/sda2' or whatever partition number you have, is for checking your hard disk for bad blocks. It can take quite some time, especially if have a big hard disk and you decide to check the entire hard disk at once.
If your hard disk has bad blocks, you will be given lots of numbers. Your hard disk probably should be replaced very soon!!! A 'bad block' is an area of your hard disk where the material is losing it's ability to retain a magnetic field and thus store data reliably. There are spare sectors in your hard disk when it is new, which the hard disc will swap out silently when badblocks develop due to imperfections and deterioration of the materials. It's only after those spare sectors have been all used up that bad blocks start to become apparent to the file system. When that starts to happen, your hard disk is getting close to the end of its useful life. |
| Smartmontools If you're having an excessive amount of file system problems, a sophisticated way to check on the health of your hard disk is to use smartmontools, if your hard disk supports S.M.A.R.T. Smartmontools is installable in Ubuntu through apt-get or Synaptic Package Manager. To install smartmontools,
To make sure it's enabled in the hard disk you want to check,
This command will run smartmontools and if not file named 'harddiskreport' exists yet, it will make one and print the output to that file. If a file by that name already exists, it will append the output to the 'harddisk report' file,
Installing smartmontools and running the command are the easy parts, making sense of the output is for the learned. These links should be helpful to most people: Self-Monitoring, Analysis, and Reporting Technology, and, Self-Monitoring Analysis and Reporting Technology (SMART) - Storage Review.com |
Avoiding filesystem damage
There only a few ways you can cause damage to a Linux filesystem. Improper (sudden) shutdown due to user error or panic See proper emergency shutdown procedures below here, (what to do if your operating system freezes up). This includes unplugging an external USB hard drive or USBdisk, mp3 player, etc, without clicking 'eject' first or 'unmount'. Improper (sudden) shutdown due to a power failure You should use a good UPS (Unlimited Power Supply) unit that will beep if the power is cut and give you time to shut your computer down if it's a serious outage. User abuse or error Running the wrong apps or commands on it, or running commands on it when it is still mounted when it should be unmounted first. Bad blocks in your hard disk it could be that your hard disk is just getting old. It might be running hot. It could be about to have a bearing failure. Or maybe the computer has been dropped or bumped a little too hard while the hard disks were spinning. (Especially if your computer is a laptop). Refer to this link, Check On Your Hard Disks With Smartmontools. * If any of the above things happen to a filesystem and you know about it, it is a good idea to run a filesystem check on it as soon as possible (A.S.A.P.), and preferably before writing any more data to the device. |
|
Proper techniques (in the event of a frozen system) to prevent filesystem damage If your mouse or keyboard stops working on you, try unplugging them at the usb or ps/2 port and wait a second, then plug them back in again. Often that does the trick. If it's just your mouse that won't work, but your keyboard is still functioning, press 'Alt + F1', for the menus and then use your arrow keys to navigate through the menus. Use 'Alt + F4' to close a Window. Use 'Esc' to quit. |
| Two ways to find and 'kill' a runaway process: (don't do a 'hard reboot', which is dangerous to your filesystem). 1. xkill You need to be able to use your mouse if you want to use xkill.
To 'background' a process: Press 'Ctrl' + 'Z' keys. To 'foreground' the process: press 'f' and then 'g' keys. To see what jobs are running: use the 'ps' command (type: ps for a list of jobs, including their job numbers. To kill a process: type: kill <job number> |
| Proper Emergency Shutdown Procedures for Linux If none of the above is any help and your desktop or mouse is still frozen but your keyboard still works you may be able to switch to a 'tty' by pressing 'ctrl'+'alt'+'F1' (or any 'F' key from 1 to 6. That takes you to a black screen where you can log in at the prompt with you username and password. (Pressing 'F7' returns you to your Desktop again). Log in at the prompt and then issue the following command, `sudo shutdown -h now', or, 'sudo reboot -i'.
Your computer might need time to close all your running processes and write any cached data to disk. Try not to ever just turn it off, that can damage your file systems. The amount of damage depends on how much data is held in memory waiting to be written to your hard disk. If your keyboard will work, you can use the 'Raising Skinney Elephants' keyboard sequence, that trick always works. Read this great link from 'Tips For Linux Explorers' links: Skinny Elephants ( if all else fails ) It is rare, but I have had times when I lose the use of my keyboard too, when my computer freezes. First I try unplugging it and plugging it back in again. That often works for both keyboards and mice. Another idea some people can use if the computer is part of a network is to log in from a nearby computer on the same network and shut it down remotely. See also SSH Network. This might work even if the frozen computer has lost the use of it's keyboard and mouse. If the computer that is frozen has ssh server software installed and you know the IP address, users account details and password, (especially if it's your own computer), you can just ssh into it and shut it down, use the same commands already mentioned.
I type in the command to reboot it. The resulting feedback:
If none of these ideas help, then sometimes
you have no choice but to use the big ol' OFF switch. If you do, be sure to run a file system check from a Live CD or different operating system right away as soon as you can. Running a filesystem check on an ext3 filesystem. |
| Links About Linux Filesystems Tips For Linux Explorers 5.10.- Linux System Administrators Guide Filesystems - Linux System Administrators Guide The Linux filesystem explained - FreeOS.com |