Saturday, 8 August 2015

Contiguous space re-partition - Linux

To recap, root FS has run out of space and data contained on it couldn't be removed or compressed to free up the space. Since there was swap space, so I planned to reclaim from the swap partition without losing the data and would extend the space for root file system. 

Host : susenode2
OS   : SuSE 11 / CentOS / Redhat 
Disk : sda

It could have been easy we could have extended volume using LVM, since our disks are not under LVM, we are here trying to re-create the entire partition without losing data.

Current scenario :

Disk (sda) is been into 3 partitons, of which sda1, sda2 are my data partitions & sda3 swap partition. I would recreate the swap partition and would extend the root file system. It could also be seen that the sector are contiguous between sda2 and sda3 hence I could destroy those two partitions and re-create.

df & fdisk & swap output :

susenode2:~ # df -hT
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda2      ext3    13G   12G  570M  96% /
udev           tmpfs  369M  128K  369M   1% /dev
tmpfs          tmpfs  369M     0  369M   0% /dev/shm
/dev/sda1      ext3   1.1G 1015M   18M  99% /application/logs
susenode2:~ #

susenode2:~ # fdisk -l /dev/sda

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cc8af

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     2265087     1131520   83  Linux
/dev/sda2   *     2265088    31625215    14680064   83  Linux                  <<===  root fs
/dev/sda3        31625216    41943039     5158912   82  Linux swap / Solaris   <<===  swap 
susenode2:~ #

susenode2:~ # swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       5158908 0       -1
susenode2:~ #

Since we are resizing the root file system, we need to get into rescue environment to do so. 
I am using an SuSE DVD or you could also use knoppix and would get into rescue environment and make necessary changes to the partition table. 


I would delete the partition sda2 and sda3 and would recreate the sda2 from the sector which was at the start i..e 2265088 and would end for my required size say 18G which I would add to this file system.

I would later create a new partition for the swap for remaining space. 

snaps are as below :


Once partition are created we need to change the type of the partition to swap for sda3 and since sda2 was bootable, make sure you would toggle boot flag on the partition.


Make sure you now has enough space in the disk where you could resize your root file system and make the swap partition. 


Rescue:~ # mkswap /dev/sda3
Rescue:~ # reboot

After reboot, check your root file system space. It would have been increased and swap space decreased. 

Snap after increasing file system :

susenode2:~ # df -hT
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda2      ext3    18G   12G  5.3G  69% /
udev           tmpfs  369M  128K  369M   1% /dev
tmpfs          tmpfs  369M     0  369M   0% /dev/shm
/dev/sda1      ext3   1.1G 1015M   18M  99% /application/logs
susenode2:~ #

susenode2:~ # fdisk -l /dev/sda

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cc8af

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     2265087     1131520   83  Linux
/dev/sda2   *     2265088    40013823    18874368   83  Linux
/dev/sda3        40013824    41943039      964608   82  Linux swap / Solaris
susenode2:~ #

susenode2:~ # swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       964604  0       -1
susenode2:~ #

Thanks

No comments:

Post a Comment