Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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. :)

share|improve this question

migrated from stackoverflow.com Jun 25 '12 at 16:52

This question came from our site for professional and enthusiast programmers.

4 Answers 4

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.

share|improve this answer
    
Before resizing the partition,you should unmount the file partition. –  sat Jun 25 '12 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 '12 at 12:27

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.

share|improve this answer

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
share|improve this answer
    
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 '12 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 '12 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 '12 at 12:47

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.

share|improve this answer
    
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 '12 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 '12 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. –  Lev Levitsky Jun 25 '12 at 14:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.