Thursday, November 08, 2007

RedHat Linux disk partitions

After installing a RedHat Linux server from a kickstart script and having a larger disk in your server than normally there can be some space left on the disk that is not allocated into a partition.

First thing you have to do is to determine if this is the case. First thing to do is to find out what is mounted and how the current setup is done.

You can use the df command for this:

[root@amssys04 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb2 3.0G 2.2G 650M 78% /
/dev/sda1 99M 9.2M 85M 10% /boot
none 1.5G 0 1.5G 0% /dev/shm
/dev/sdb1 4.0G 41M 3.7G 2% /oebs/oemagent
/dev/sda3 2.0G 36M 1.9G 2% /tmp
/dev/sda5 494M 69M 400M 15% /var

If you do a little math you can find out if all the space is mounted to your filesystem or not. If this is not the case there are several possibilities. (A) there is a partition created but not mounted or (B)there is no partition created and you have to create the partition before you can mount this to your filesystem. For this example we go for situation B.

You can check your partition settings by using the fdisk tool available from your prompt. We do fdisk /dev/sda because we like to view the partition settings of the /dev/sda disk.

[root@amssys04 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 19457.
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)

Command (m for help):

M will print some more information for you. We would like to view what is assigned or not so we take the p command to print the settings to the screen.

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 535 4192965 82 Linux swap
/dev/sda3 536 796 2096482+ 83 Linux
/dev/sda4 797 19457 149894482+ 5 Extended
/dev/sda5 797 861 522081 83 Linux


From this information we can see that there is space between 861 and 19457. By using the n command you will be guided into creating a new partition. You will be asked to enter the first and the last sector where you like to create your new partition. When this is done you write the changes to the system by the w command. A kernel reboot is needed to pick the changes up. You will now have a /dev/sda6 partition which is at this moment still useless.

First we have to format the new partition by executing the following command:
/sbin/mkfs -t ext3 /dev/hda6

When formating is done we have to label the partition by using the following command:
e2label /dev/hda6 /as


Now we like to mount this new partition to the filesystem. First we have to create a directory a mount point and then add it to fstab by editing /etc/fstab

cd /
mkdir sa


And add the following line to /etc/fstab
LABEL=/as /as ext3 defaults 1 2

Finaly mount it to your filesystem by executing:
mount /as


No comments: