Sa1 4

Page 1

SA1 LECTURE 4 Disk Management: Disk management in Linux is done be a series of commands. Unfortunately neither there is not a single command or a GUI tool for Disk/Partition Management. We use following commands 1. 2. 3. 4. 5.

fdisk: e2label: mkfs: /etc/fstab: fsck:

To To To To To

Create, Delete, Set Type of a Partition and Set a partition Active. assign a label to a partition. format a partition. mount a partition at boot time. scan a partition for errors.

Things to Remember: 1. Only Four main partitions (Primary and Extended) can be created on a hard drive. 2. Only one Extended partition can be created on a hard drive. 3. Logical partitions can only be create in extended partition therefore, until you do not create a extended partition you can not create a logical partitions.

Create Partitions: Fdisk utility is used to create partitions on hard drive. First we check which type of hard drives are available / present in your computer.

fdisk –l Messages Copied From System: Disk /dev/sda: 9126 MB, 9126805504 bytes 255 heads, 63 sectors/track, 1109 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot /dev/sda1 * /dev/sda2

Start 1 1021

End Blocks Id System 1020 8193118+ 83 Linux 1109 714892+ 82 Linux swap / Solaris

The fdisk –l command displays you output something like this and display all disks present in your system. Here it tells you that: The disk present in the system is either SCSI or SATA (sd) and it is fist hard drive in your system (a). Size of the disk is around 9GB (9126MB) and there are two partitions in it.

/dev/sda1:

Starting from cylinder 1 ending at 1020 cylinder. Partition type is Linux(ext3) and ID of ext3 is 83. Each partition has been assigned a predefined ID ext3 has 83 and swap has 82. And it an active partition (*).

/dev/sda2:

Starting from cylinder 1021 ending at 1109 cylinder. Partition type is Linux Swap and partition type ID is 82.

To run fdisk utility we have to provide Linux name of hard drive to fdisk command. If we want to create partition on Hardrive /dev/hda then we will start fdisk like.

fdisk /dev/hda Above command will give you some messages and if you have added a new hard drive in your system then you will get more messages as given bellow: Messages Copied From System: [root@ES3 root]# fdisk /dev/hda


Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 2080. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) arning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): Command (m for help): Is fdisk prompt here you can give commands to fdisk to create, delete, set active and set type of partitions. List of most commonly used fdisk commands are: a d l m n p q t w

make a partition active. delete a partition list known partition types print this menu add a new partition print the partition table quit without saving changes change a partition's system id write table to disk and exit

Display Existing Partitions: Command “p” tells fdisk to display all partitions in the hard drive. Output is similar as we have seen in “fdisk – l” output Messages Copied From System: Command (m for help): p Disk /dev/hda: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot /dev/hda1

Start 1

End Blocks Id System 970 488848+ 83 Linux

Create New Partitions: On fdisk prompt type “n” to create a new partition. Fdisk is intelligent if you haven’t created a extended partition it does not give you option to create a logical partition. And if you have made extended partition then it does not give you option to create a extended partition. And if you have created four main partitions then it only gives you to created logical partitions. See the following system messages. We are creating partitions on Primary Master hard drive (hda) this is a new hard drive as soon as we pressed “n” system gave us two options Create extended partition “e” Create primary partition. “p” We selected “p” to create primary partition. Fdisk gave us option that we can create 4 primary partition on this hard drive therefore which partition you want to create 1 to 4. As this is our first partition we selected “1”. For next primary partition we will select “2”. Then fidsk asked from where we want to start this partition we selected “1” means first cylinder means beginning of the hard drive.


Then we told fdisk to assign this partition 500MB space (+500M) to this partition. This is fdisk style that we first + means add then size 500 then scale name M Megabytes. Then we typed “p” to display the newly created partition. Then we again pressed “n” to create a new partition. Then selected “e” to create extended partition. Then in the “First cylinder” we just pressed enter to accept the default and default is next available cylinder. In the size or “Last cylinder” we pressed enter to accept the default and default is the last cylinder of the hard drive. This means that we are assigning all available space to this partition (next available cylinder to last cylinder). As soon as we created extended partition “e” option to create a extended partition vanished. Now we have “l” to create a logical partition. Messages Copied From System: Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2080, default 1):1 Last cylinder or +size or +sizeM or +sizeK (1-2080, default 2080): +500M Command (m for help): p Disk /dev/hda: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot /dev/hda1

Start 1

End Blocks Id System 970 488848+ 83

Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): Value out of range. Partition number (1-4): 2 First cylinder (971-2080, default 971): Using default value 971 Last cylinder or +size or +sizeM or +sizeK (971-2080, default 2080): Using default value 2080 Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (971-2080, default 971): Using default value 971 Last cylinder or +size or +sizeM or +sizeK (971-2080, default 2080): Using default value 2080 Delete Partitions: To delete a partition we use “d” command on fdisk prompt. Fdisk asks which partition you want to delete. We have to select a partition number to delete. You can find number of a partition by “p” command of fdisk. As


explained in the following system messages. Messages Copied From System: Command (m for help): p Disk /dev/hda: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot /dev/hda1 /dev/hda2 /dev/hda5

Start 1 971 971

End Blocks Id System 970 488848+ 83 Linux 2080 559440 5 Extended 2080 559408+ 83 Linux

Command (m for help): d Partition number (1-5): 5 Command (m for help): p Disk /dev/hda: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot /dev/hda1 /dev/hda2

Start 1 971

End Blocks Id System 970 488848+ 83 Linux 2080 559440 5 Extended

Set a Partition Active: To make a partition active “a” command of fdisk can be used. After “a” fdisk ask the number of the partition you want to set active. As explained in the following system messages. Messages Copied From System: Command (m for help): a Partition number (1-5): 1 Command (m for help): p Disk /dev/hda: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot Start 1 /dev/hda1 * /dev/hda2 971

End Blocks Id System 970 488848+ 83 Linux 2080 559440 5 Extended

Save Changes and Exit: To save changes and exit fdisk use “w” command. And read carefully the fdisk message before exiting. Fdisk some times requires rebooting the system before changes take effect. Especially if you have Windows partitions on the disk, fdisk asks you to reboot system. Messages Copied From System: Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.


Create Partitions: Label assignment is a very good feature of Linux. There is a file /etc/fstab in Linux systems that contains information about the partitions that systems mounts during system boot process. Entries in this file used to be like following:

/dev/hda5 /var ext3 defaults

11

It means mount /dev/hda5 on /var directory and if we change the hard drive position and make Secondary Master for some reason then name of hard drive will become /dev/hdc and partition name will become /dev/hda5 and during boot process when system will read /etc/fstab file it will try to find /dev/hda5 and system will not boot as there is no such partition present in system. In such case you will errors something like “Give root password or press Ctrl+d to reboot normally” To avoid such conditions we give labels (names) to partitions and mention these names in /etc/fstab file in case if hard drive position changes the name remains same and systems boots properly. To assign Labels to partitions we use following command.

e2label /dev/hda5 /var Here: e2label: /dev/hda5: /var:

Command that changes the label of a partition. Partition to which is being assigned the label. Label name. Normally we assign label same as mount point (the directory on which we mount a partition) name.

Format Partitions: The process of making a partition able to save, read and search files and directories is called Formatting. Or File system creation process on a hard drive is called Formatting. When we format a partition system divides partitions in different areas and write some information on that partition and some space of partition is occupied in this process this is called “File system Overhead”. When we format a partition in Linux. It divides partitions in following areas: 1. Data Block: It is the area where data is stored. It is consumes most of the partition area. 2. Inode Block: It is a table (like fat table in windows) in which file and directory related information are stored. Like: Inode No. 000001 000002

File Name Data imp.doc

Permission

Links

Access Time

Creation Time

Owner

Group

….

0755 0644

2 1

07120456.2007 05090630.2007

07120456.2005 05090630.2007

Root U1

root Mkt

…. ….

3. Super Block: Super

block keeps information like How much free and used space in the partition How many free and used indoes. Partition starting and ending on which cylinder From which cylinder data, inode and other areas are starting and ending. etc.

To format a partition, use the following command.


mkfs –j /dev/hda6 Here: mkfs: -j: /dev/hda6:

Command that formats a partition. Format a partition in “ext3” format. Partition to which is being formatted.

Mount Partitions at Boot Time: As mentioned earlier. There is a file in Linux system “/etc/fstab” that contains entries of the partitions that system mounts during boot process. During boot process system reads all entries of this file and tries to mount partitions accordingly. One line contains information for a single partition. Entries like following are present in /etc/fstab file. Entry 1 Entry 2 Entry 3 Entry 4 Entry 5 Entry 6

LABEL=/ LABEL=/var /dev/sda2

/ /var swap

Here: Entry 1 (LABEL=/): Entry 2 (/): Entry 3 (ext3 & swap): Entry 4 (defaults):

Entry 5 (0 & 1):

Entry 6 (0,1 & 2):

ext3 ext3 swap

defaults defaults defaults

1 1 0

1 2 0

Label or the name of the partition. Mount Point. Partition’s format type. For swap it is swap, for Linux data partition it is ext3 and for Windows data (fat32/fat16) it is vfat. Defaults is a group of mount options that includes rw, dev, exec, auto and nouser etc. rw means mount partition in read and write mode so users and system can read and write to this partition. dev means devices files can be created/present on this partition and system can use them. exec means that scripts, commands and programs etc present on this partition can be executed auto means that this partition should mount with “mount –a” command nouser means that normal users will not be able to mount this partition. This entry is used by dump command. Either dump command will take backup of this partition or not. 0 means do not take backup, 1 means take backup In case of abnormal shutdown or in case if the partition has been mounted and unmounted as many times as set by the mkfs command during formatting. The system should run partition scanning at boot time or not? 0 means do not run scanning (fsck command), 1 is reserved for / partition and it means run scanning and 2 is for all other none / partitions it means run scanning.

Note: Mount point must be an empty directory. Mount point directory can be present under / or it can be present under many directories line /media/harddrives/data. Nested mount are also allowed. Like /var is mount point of /dev/hda3 and /var/log can be a mount point of /dev/hdc5.

Scanning Partitions: To scan a partition first unmount that partition and then use following command for scanning.

fsck /dev/hda5 Here:


fsck: Command to scan a partition. /dev/hda5: Partition to scan.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.