11

Im having a problem, my primary partition is running out of space. Due to this, I can't access linux machine remotely (through vncserver). I have another drive (/dev/sdb) having much more free space. I want to shrink space from (/dev/sdb) and extend to (/dev/sda1) partition which is my primary partition and have all linux boot, kernel etc files. What would be best risk free way to do this without losing my data on primary drive(/dev/sda1) ?? fdisk or 'dd' command or 'mount and umount' ? Any help would be highly appreciated. :)

5 Answers 5

5

You have to use resize2fs command,Which is used to resize your partition.

For more information refer this link.

http://www.howtoforge.com/linux_resizing_ext3_partitions

Ex:

 resize2fs /dev/sda 6000M

You can use resize2fs to increase as well as decrease the size of partition. First,you have to decrease the size of /dev/sdb.Then,After increase the size of /dev/sda(Primary partition).

I hope this will helps you.

2
  • Before resizing the partition,you should unmount the file partition.
    – sat
    Jun 25, 2012 at 12:27
  • I'm pretty sure its primary partition is using the maximum it can, and so, won't be able to resize the underlying filesystem. Thus, a simple resize2fs will fail.
    – Dolanor
    Jun 25, 2012 at 12:27
2

The Risk Free way would be if you can copy(mirror) all your data from /dev/sda1 to some other partition.

After this is done, I would recommend to go with GParted live CD and execute all partition modifying commands from there. This seems to be the most secure way of doing it.

0

You need a live CD/temp OS to boot on it, resize the new partition to the right size, mount the old and new partitions and copy your files first with

cp -avx /media/originalRootPartition /media/newRootPartition

Then you should change some references (UUID or partition name) to the new partition in /etc/fstab to match the new partition, and reinstall grub on that new partition :

grub-install /dev/sdb1
3
  • After prolonged thinking i decided not to extend or shrink any partition as im using amazon EC2 linux instance. They attach 8 GB primary partition by default. After extending instance type(upgrating instance) they gave us another partition instead of extending last one (primary partition). To avoid any future up coming problems, im going to move my all installed softwares like Application server(Glassfish) My SQL server etc to secondary partition. Now the problem is that how can i only move my specific data instead of complete drive data by using 'dd' command: e.g dd if=/dev/sda1 of=/dev/sdb
    – Haseeb
    Jun 25, 2012 at 14:21
  • and set secondary drive(e.g /dev/sdb) for future installation. Like if in future i like to install any software it should by default install to secondary drive instead of primary partition. how i can do this ?
    – Haseeb
    Jun 25, 2012 at 14:24
  • Can you create a new question for that ? There is not enough space in the comment to answer, and editing my question will make it non-valid for your specific question of that page ;) The answer would be with mount --bind /usr and /var and doing stuff "offline" ;)
    – Dolanor
    Jun 26, 2012 at 12:47
0

The answers given so far don't seem to take into account that the free space you have is on another drive.

I don't think you can easily extend a partition to another physical drive, although I may be mistaken. Anyway, a more straightforward thing to do in this case is to constantly mount a partition from your other drive (say /dev/sdb1) into your filesystem. For example, you could keep your /home on /dev/sdb1. That would make some space in /dev/sda1. Look into fstab on how to achieve this and don't forget to backup first.

3
  • After prolonged thinking i decided not to extend or shrink any partition as im using amazon EC2 linux instance. They attach 8 GB primary partition by default. After extending instance type(upgrating instance) they gave us another partition instead of extending last one (primary partition). To avoid any future up coming problems, im going to move my all installed softwares like Application server(Glassfish) My SQL server etc to secondary partition. Now the problem is that how can i only move my specific data instead of complete drive data by using 'dd' command: e.g dd if=/dev/sda1 of=/dev/sdb
    – Haseeb
    Jun 25, 2012 at 14:25
  • and set secondary drive(e.g /dev/sdb) for future installation. Like if in future i like to install any software it should by default install to secondary drive instead of primary partition. how i can do this ?
    – Haseeb
    Jun 25, 2012 at 14:26
  • @Haseeb My advice still stands, I'd just create a couple of partitions on /dev/sdb and mounted, say, /dev/sdb1 as /usr and /dev/sdb2 as /home, etc. As for moving, use mv command. Jun 25, 2012 at 14:30
0

I use often for Servers which run over a few years and go now out of space this workaround:

Normally one or two applikations/services/deamons/whats so ever... need the most most space. If thats the case u can mount move the directory from disk sda to disk sdb, so you utilize more space.

here is what i do: create a directory on the empty drive

mkdir /mountpointsdb/data/deamon_database

now we just have to copy all data from the original folder to "/mountpointsdb/data/deamon_database"

cp /usr/deamon/database/* /mountpointsdb/data/deamon_database

now we can delete the original folder, but make sure the deamon want run. Thiss will give you more free space on sda. After that just mount the new folder to the old location and start the deamon:

mount --bind /mountpointsdb/data/deamon_database /usr/deamon/database

If u want this to be permentent you have to make an entry like this in the mtab:

/mountpointsdb/data/deamon_database    /usr/deamon/database    none    bind

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .