Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1030662
  • 博文数量: 123
  • 博客积分: 5051
  • 博客等级: 大校
  • 技术积分: 1356
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-14 10:56
文章分类
文章存档

2012年(1)

2011年(21)

2010年(13)

2009年(55)

2008年(33)

分类: LINUX

2009-12-10 10:54:17

A good article introducing the file systems in Linux.

Since Linux appeared on the scene in the early 90's, ext2 has been the default file system. Though Linux systems are extremely robust and less prone to crashes, you never can tell when a power outage is going to bring your system down suddenly. Though ext2 is a hardy filesystem, there is a risk of data loss when these sudden crashes occur. For this reason, two projects have come up with alternatives known as 'journaling' filesystems. These are ext3 and ReiserFs.

ext2 is the "traditional" filesystem on Linux.By traditional, I mean that it has the longest run as being the most popular filesystem. From 1992, when it was developed by Remy Card, until 2002 or so, it was considered the 'default' Linux filesystem.

ext2 stands for 'second extended file system'. It replaced the original 'extended file system', which was in itself, a replacement for the Minix filesystem, which was Linux's first 'default' filesystem. Minix only allowed 14 character file names and had a maximum of 64 megabytes for . The first ext filesystem overcame these limitations (255 char. file names and 2 GB file size), but still suffered from other problems related to file access. ext2 corrected these problems and raised the file size bar to 4 gigabytes.

The main advantage to the ext2 filesystem is its speed. It's considered fast and other filesystems use its speed as a base for doing benchmarks. It's also extremely robust. However, the main problem is when your system crashes. ext2 need integrity checks that, depending on your hard disk size, may take an extremely long time. You may also end up with some . An attempt to take advantage of the positive points of ext2 and add some data loss protection and speed led to the development of journaling file system. Let's have a look at those.

As we mentioned, journaling file systems came about as a way to overcome problems with after a crash. Basically, a journaling filesystem logs changes you make to your files to a 'journal'. This is a file that resides in a separate portion of your hard disk. Instead of doing a lengthy filesystem check, a journaling filesystem just reads the contents of the journal to make sure that the files are in the state that they're supposed to be. This saves time and prevents file corruption. Let's look at the two most popular journaling filesystems used with Linux, ext3 and ReiserFS.

ext3 was developed by Dr.Stephen Tweedie in 1999. ext3 is essentially ext2 with a journal. The rationale behind creating a filesystem can be best summed up by Dr. Tweedie himself he gave at the Ottawa Linux Symposium in July of 2000.

 

... there are a rather lot of users out there who have got existing EXT2 filesystems. And more every day. And some of these EXT2 filesystems are getting really rather big. Even 24 months ago, there were people building 500 gigabyte EXT2 filesystems. They take a long time to fsck. I mean, really. These are filesystems that can take three or four hours just to mkfs. Doing a consistency check on them is a serious down time. So the real objective in EXT3 was this simple thing: availability. When something goes down in EXT3, we don't want to have to go through a fsck. We want to be able to reboot the machine instantly and have everything nice and consistent.

 
--Dr. Stephen Tweedie  

With ext3, the user gets just this. A robust and fast filesystem with a minimum of downtime. There is one disadvantage with the ext3 filesystem as compared with ext2. With ext3, are, for all intents and purposes, unrecoverable.

Systems running the ext3 filesystem are much more common than they were. Nevertheless, you may be running a system that may be considered a quasi-legacy system and you want to make the move from ext2 to ext3. The procedure is fairly straightforward. You simply need to run the following command:

tune2fs -c 0 -i 30 -j /dev/hda1

This command will convert your partition on hda1 to ext3 and also make sure that the system is checked every 30 days. This is a good idea because a journaling filesystem doesn't preclude the possibility of corruption.

You also need to edit your /etc/fstab and change ext2 to ext3 for every partition you've converted. After this, just reboot the machine.

Warning

Remember: Your kernel needs to support the ext3 filesystem. This is important especially if you've got a custom-made kernel. If you haven't included ext3 in it, upon reboot, you'll be in for a rather unpleasant surprise.

After rebooting, running the command 'df -T' should confirm that you've been successful:

Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/hda2 ext3 4032124 275088 3552208 8% /
/dev/hda3 ext3 9677928 1902404 7284004 21% /home
/dev/hda5 ext3 4032092 1424956 2402312 38% /usr

As we mentioned, the other popular journaling fileystem is the ReiserFS. It was originally developed by Hans Reiser with the help of SuSE. Now, development is carried on under the auspices of Namesys with the sponsorship of Linspire. DARPA has also provided grants to help with its development. At present, there are essentially two versions of the ReiserFS: version 3, which is in most widespread use and version 4, which is a complete re-write of version 3, is, at the time of this writing, in development and not considered stable.

ext3 and ReiserFS are similar in that they both use a journal. However, the ReiserFS journal concept is a bit different. ReiserFS stores both the file names and the file itself in a database where ext3 stores the file name but only its location. On the downside, ReiserFS needs a clean install to use whereas an ext2 filesystem can be converted to an ext3 fairly easily on a working system.

Though ext2, ext3 and Reiser are the most popular, there are also other filesystems in use in the Linux world.

JFS was originally developed by IBM for their AIX operating system. Worked started in 1999 to port JFS to Linux and the code was released under the GPL. As its name implies, it is a journaling filesystem.

JFS is like ReiserFS in that it provides a journaling filesystem from the start, unlike ext3, which is essentially a 'converted' ext2 filesystem. To use JFS under Linux, all one needs to do is enable Linux kernel support for it, by either adding it as a module or compiling it into the kernel itself. You will also need to install the package jfsutils.

Once you have JFS support in the kernel, the easiest way to convert your systems partition to JFS is to, first, create a new root partition from an empty partition. Take this empty partition and format it. Let's say your empty partition is /hda5:

mkfs.jfs -c /dev/hda5

This will convert it to jfs and check for bad blocks in the meantime (which is always a good idea). Once you've formatted, then you can copy your root partitions files over to the new partition. The easiest way is to create a temporary directory and then mount it. When you copy the root partition files there, make sure you don't copy /proc. Remember, those are running processes and aren't actual files.

The last thing you need to do is change either your lilo.conf or grub.conf (depending on the bootloader you're using) and your /etc/fstab. Now, with the old root filesystem you can create the /home partition for example. That can also be JFS if you want.

XFS is another journaling filesystem for use on Linux systems. It was initially developed by Silicon Graphics for use on their high-end Irix Unix systems. One of the most notable features of XFS is that it is designed to handle a filesystem as large as a million terabytes. A filesystem on a 32 bit Linux system needs to be much smaller, but weighs in at a still considerable maximum size of 16 terabytes.

Though less popular than ext3 and ReiserFS, it's in the same league as JFS. It's somewhat of a minority filesystem, but is considered popular enough to be offered as an option by major developers like RedHat, the Debian project and Mandriva.

With the ubiquitousness of Microsoft in the world of computing, it would be impossible for us to ignore the filesystems that work under Windows. In most offices, there's usually a need for a Linux machine to interact with them.

NTFS is the file system used on Windows server-type operating systems starting with Windows NT (hence the name) and continuing with Windows 2000, Windows XP and Windows Server 2003. Linux support for mounting NTFS read-only has existed since the 2.4 kernels. This support was greatly improved in the 2.6 kernels, but the ability to write to an NTFS partition is still somewhat experimental and therefore risky at the time of this writing.

Microsoft, the epitome of the proprietary software development company, has never divulged the inner workings of the filesystem. This has made NTFS driver development extremely hard and accounts for the difficulties in providing full read-write support. For this reason, most Linux distribution companies are reluctant to provide kernels with NTFS support built-in. That means that, in most cases, you'll need to either load a module for NTFS support into a running kernel or compile NTFS support into a home-made kernel.

If you have a dual-boot system, then it's likely that you need to mount the Windows partition from time to time. Assuming you have NTFS support in the kernel, you would mount the partition like this:

mount -t ntfs /dev/hda1 /mnt/

Let's say that you've bought a new system and you've paid the Microsoft tax - which means that you've had to pay for Windows XP because the OEM has left you with no alternative. In most cases (and probably all of them), these machines have taken up the entire hard disk. If you're going to install Linux, you need to free up some space. Fortunately, you can use freely available Linux utilities to get the job done. SystemRescueCd includes all the tools you need to resize and NTFS partition.

The Common Internet File System or CIFS is a network filesystem based on protocols developed by Microsoft. Since this system was developed by Microsoft, it's naturally difficult to explain how it works with 100% accuracy. Microsoft is famous for keeping secrets.

CIFS started out as the Server Message Block (SMB) protocol. That's how Linux users know it best. The best known Linux software to emulate a server running this protocol is known as Samba. It's fairly easy to get a Samba server running on Linux. If you're interested in this, please see our section [LINK] on Samba.

As far as client software goes, any Linux desktop running KDE can use Konqueror as a client. By entering:

smb://server

in the URL field, you can open up a remote samba server.

You might be interested in mounting a remote file system. That is also fairly easy with 'smbmount'. Simply create a subdirectory called 'samba' in your /mnt directory and issue the following command:

smbmount //server/directory /mnt/samba -o "uid=username,gid=username,fmask=664,dmask=775"

and you can use the remove samba share as a local directory, creating files in it, writing to them or whatever you wish.

阅读(1062) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~