PARTITIONS AND FILE SYSTEMS

For storing data, retrieving data or for doing any task on a disk we need a formatted hard disk. The formatting operation in Unix lies outside the domain of operating system.

The formatting of hard disk is carried out by certain utilities. After the disk has been formatted, it is divided into several logical parts called partitions.

Each portions can be consider as a logically independent disk and can be access by its own device file.

A hard disk space must be portion taking into consideration the present and future requirements.

Let us suppose that we have a given hard disk space of 2GB capacity. The different partitions can be as follows -

1. /swap directory (double)

This directory about double the main memory size.
e.g  System have 128 mb memory should get 256 mb swap space.

2. /directory (root)

About 60% of the available space. This is about 1200 mb in a 2GB hard disk.

3. /bin directory

About 20% of the available space. That is about 400mb in a 2GB of a hard disk.

4. /user directory

Remaining Space

5. F-DISK

The system partitions are define & created at system installation or when adding additional disk.

The F-disk utility is used to create, delete and activate partition. When use without options, it reports and act on the first hard disk.

$ disk

1. Display partition table
2. Use entire disk for Unix.
3. Use rest of disk for Unix.
4. Create Unix partition
5. Activate Partition 
6. Delete Partition

Enter your choice or 'q' to quite : 1

ADVANTAGES OF PARTITIONS

You can get a Unix System perfectly running on a single partition hard disk also. But dividing the hard disk into a no. of partitions will provide the following advantages -

1. If their is some problem in 1 Partition area of the hard disk then other partition area of the hard disk remain.

2. If a hard disk system has several partitions, then each partition can be backup separately on to a single volume of a tape.

3. keeping several partitions on a hard disk avoid the conflict among various data store on the disk.

4. It will reduce the time required to perform file system check.

5. If a file system becomes destroy due to some reason you will probably loose only the file on a single partition.

STRUCTURE OF THE FILE SYSTEM

A file system in Unix consist of a sequence of logical blocks each containing bytes, 1024 bytes or some multiple of 512 byte. A Unix wise consist of the following components -

1. BOOT BLOCK

It occupies the beginning of a file system, and may contain the bootstrap code that is read into the main memory to boot the computer or to node the o/s to start the computer.

2. SUPER BLOCK

It describes state a file system. It comprises of global info. about the file system. It maintains the list of free inodes and data blocks which can be immediate allocated by the kernel when a new file is created.

3. INODE BLOCK

It contains a table for every file of the file system. All attributes of a file and directory are store in this area except the name of the file.

4. DATA BLOCK

It contains data and program created by the user. An allocated data block can belong to one and only 1 file in a file system.

HARD LINK

The LN command is use to create multiple of links of a file you can create a link to the file stuff by giving the following commands-

$ ln stuff junk

Using ls -i you can see that the two files have the same inode.

$ ls -i stuff junk

Output -

1659 stuff 1659 junk you can now specify either stuff or junk and access the same file. If you make changes to stuff those changes will appear in junk as well.

For all purposes stuff and junk are the same file. These links are known as hard link because they create a direct link to an inode. If you delete one of these files using rm command you are actually deleting only one link to the inode.

The next link remains active and you will be able to access the data using this link.

$ rm stuff

SYMBOLIC LINKS (Soft link)   

Soft links are another type of link which are different from hard disk. This allow you to give a file another name, but does not link the file by inode. Using ln with hypen (-s) option creates a soft link to the file.

e.g 

$ ln -s stuff substance

You are creating us symbolic link name substance that points to the file stuff. This is unlike hard link where the links point to the inode. If you use ls -i you will see that the two files have different inodes. If you use ls -l you will see that the file substance is a symbolic link pointing to stuff.

DIFFERENCE B/W HARD LINK & SOFT LINK

1. One can create a symbolic link to a file that does not exist. The same is not possible with hard link.

2. Symbolic link identify the file they point to but with hard link their is no easy way to determine which files are link to the same inode.

3. You can hard link files only when they are on same file system, symbolic link do not have this restrictions. hard link cannot span accross file system whereas soft links can span file system.

HIGH NODES AND DIRECTORIES

1. CP AND INODE

The cp commands allocates a free inode number, placing a new entry in the inode table. It creates an entry in the directory, associating a name with a inode number and copies data into a new file. 
    
2. MV AND INODE

If the destination of the mv command is on the same file system as the source, the mv command -

a) Create a new directory entry with new file name.

b) Delete the old directory entry with the old file name.

It has no impact on the inode table or the location of data on the disk but if the destination is a different file system or a mv act as a copy and remove.

3. RM AND INODES

The rm command implements the link and frees the inode to be reuse. It places data blocks on the free list the remove directory entry data is not actually removed, but will be returned when the data blocks are used by another file.

ARCHIVING FILE

A simple mistake given under Unix o/s can destroy your precious work. Human error is recognized as the biggest cause of the data loss, followed by disk crashes and other hardware and software failures.

Backing up important files is very important to do. Preserving your work frequently can save you precious time and also eliminate of recreating something you have just finished. After saving all your important files in an archive or any other removable disk, You can safely delete the errors from your hardware.

In this way, you can save your old and important files in the storage device and remove the same from the hard disk in order to make space for the new file & work.

1. TAR

The simplest, versatile and one of the most popular commands for creating archives is the tar command.

An achievement is a single file that holds a no. of files that you plan to save to another medium. It is also a very useful utility for reading and writing disk base achievers, for copying directories b/w different system or b/w different locations on a single system. 

The tar command includes the following - 

a) A string of options
b) The name of the device
c) A list of files that are to be achieve

OPTIONS FOR TAR COMMAND

COMPRISING ARCHIVES

Some large size files can be compared and stored in the disk. Also, file compression is useful when you want to save and carry a large file on a floppy disk.

Some popular compression utilities are available with units are compression, Gzip and zip.

The compression is a fast and simple to use file comprasing utility.

For example : 

     To compression a file myfile.txt, we can give the following compression command 

$ compress myfile.txt

The above command will compress the file and will produce

myfile.zip

to uncompress the file, the uncompress is used

$ uncompress myfile.txt

The other utility is gzip to compress the file myfile.txt using gzip, we need to give the following command -

$ GZip myfile.txt

The compress file take the extension .GZ and the compress version of myfile.txt will be called myfile.txt.gz

This file can be uncompressed by using g unzip as follows -

$ Gunzip myfile.txt.GZ

The third utility is zip. The utility zip is differ from other in the sense that it can compress multiple files into a single file.

For example - The following command compress all the files into with .txt extension into a single file called zip text.

$ zip ziptext *.txt


Your feedback is important for us :)