Email us

Email us
Business I.T support Brighton from LJE Ltd.

Monday 20 October 2008

resize linux root partition

The last year that ive been doing I.T Support in London, Ive seen quite a few linux servers which dont have sufficent root partition space.

So here's a procedure ive used several times to extend a ext3 root partiton and filesystem on redhat enterprise 5

If you use ext3 ( not LVM) as your root patition and you run out of space this procedure will enable you to create a larger partition, move existing root files to the new partition and expand the filesystem to new size.

You need to have enough spare disk space on your disk to create a large parition, or fit an additional disk to the server.

This guide is detailing resize2fs utility only. Other third party tools can change the partition itself, but this entry details our current procedure.

In this example partion 5 contains the original root partition and partition 6 is the next available spare area of disk

1.Always backup the partition you will be copying in case of errors.

2. boot from redhat cd1/dvd ( rescue CD or first boot cd)
at boot prompt type
:'linux rescue'
when prompted, dont mount the disk partitions you need to change
(umount /dev/sda5 if needed)

3. create the new partition 9no6) using fdisk
fdisk /dev/sda
(m)ake a new partion at the correct size ( partion 6)
(w)rite the partiton to disk

4. reboot and boot from rhel cd again for partition table to be loaded
fsck.ext3 -f /dev/sda5 ( check original fsystem is clean)

5. copy the old partion files to the new larger partition
dd if=/dev/sda5 of=/dev/sd6
(This can take some time, no progress is show)

Note: dd copies original partiton contents and filesystem size ( inodes), so when you next reboot it will apprear the new partion size has shrunk to the old partition size.
This is becase dd does a track by track copy of the original data including any spare filesystem.
As we hav'nt create the filesystem on the new disk so it is using exactly the same data as partition 5.

Logical Volume Manager (LVM) can be then used to create inodes upto the end of the new partiion size.

Remember resize2fs is not able to extend a partion itself ,only any unused filesystem within that partition.

6. Next you need to extend inodes to continue to the end of the new partion,but keeping the original copied root data untouched .

/sbin/resize2fs -p /dev/sda5 9000M ( extends the file system to 9 GB, the actual partition max size)

This will only extend the filesystem to the current partition size. As mentioned above, if the partition is not big enough (d)elete and (w)wrie the new partion again in fdisk.

Once the correct size and disk dump has completed ,delete the orginal partition on the disk.

In example if you remove sda5 then the new partition sda6 becomes sda5, so there is not need to change partition lables or edit /etc/fstab

Occasionally we have seen that you might need to rewite the journel if the disk doesnt mount properly on first reboot.

Boot from cdrom again,

tune2fs -j /dev/sda5
or tune2fs -O has_journal /dev/sda5 ( to remove the journel or make partition on an older ext version)


Have fun
Akbel

Friday 10 October 2008

Red Hat 5 ip forwarding

By Default , whether firewall and SELinux are switched on or not, Traffic will NOT be routed between two network cards in a Red hat box. You need to manually setup as a router

To make the machine act as a router, you need to add some policies to iptables and enable
/etc/sysctl.conf net.ipv4.ip_forward=1

iptables -A FORWARD -i eth1 -j ACCEPT ( allow network ip's from eth1 thru )
iptables -A FORWARD -o eth1 -j ACCEPT

add the line below to iptables script in /etc/init.d/iptables

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
masks requests from LAN nodes with IP of the eth0

Note: masquerade not show in /sbin/iptables -L for some strange reason
In the example above eth1 is Internet side eth0 is private LAN

Set the default gateway to pint to dns/inetrnet router

test from client on Private LAN ,should be set to defaultgateway to eth1 to test packet forwarding.

On Linux Check operation using
/usr/sbin/tcpdump -X port 80 -i eth0 -w filename
/usr/sbin/tcpdump -r filename -X port 80


Regards

Chris