Want to reallocate disk areas in LINUX

I have a 40GB VMware virtual Linux drive allocated so only about 2Gb is alocated to /opt (dev/sda2): I need more space for /opt and I would like to reallocate about 60% of the space from /home or, alternatively, reassign /opt to /dev/sda3  (the location home is on).

Thanks for your help

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              3960348   1966684   1789240  53% /
/dev/sda3             34640104   4620328  28231744  15% /home
/dev/sda1                46633     10387     33838  24% /boot
tmpfs                   517644         0    517644   0% /dev/shm
[root@localhost ~]#
[root@localhost ~]# df /opt
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              3960348   1966684   1789240  53% /
[root@localhost ~]#

Christopher ScheneSystem Engineer/Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pitt7Commented:
Resizing of partitions needs two steps:
Changing the partition table and resizing the file system.

You can do these steps manually with fdisk (or other partition editors) the file system resizing tool of the used filesystem (resize2fs for ext2/3/4 for example).

But I suggest to try out parted (if you have X you can use gparted (GTK) or qparted (QT) as frontend). This does both steps.

Always ensure you have a backup before changing anything. It can be useful for disaster recovery to save the output of fdisk -lu.
0
bguyton3Commented:
Note that your /opt partition is not actually a separate partition, but simply a directory in your root partition.

Since you're not using a logical volume manager, what you are really asking is if you can increase the size of your root partition.  This would involve moving your entire /home partition, which is fairly large.  I'm and old fart and may be out of touch, but generally in my experience, you're not going to be able to move the start of that /home filesystem on sda3 to a later spot on that partition without having to migrate the data there.

The absolute easiest thing to do would be to transfer the /opt data to /home (/home/opt) and simpliy make a symlink to it (rsync -av /opt /home; mv /opt /opt/old; ln -s /home/opt /opt).  Not the prettiest, but probably the simplest to accomplish
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pitt7Commented:
Another option is shrinking your /home partition (which is quite easy) and creating a new partition for /opt.

Example:
umount /home
(You have to umount the partition to shrink it, enlarging works online too)

resize2fs /dev/sda3 30G
(30G means 30GB use whatever you want but it cannot be smaller than the actually used space of course.)

Resizing partitions with fdisk/cfdisk is not possible. You have to delete them and recreate. This is not a problem but ensure the start sector is the same as before. Otherwise the filesystem on the new partition won't mount. So use Sector Units in cfdisk.

To ensure the new partition isn't smaller than the resized filesystem on it make the partition 1G bigger as your filesystem resize. Of course it's possible to calculate the exact size of the partition for the filesystem size but it's a bit work. So I prefer to shrink to a smaller value, create the new partition with the desired size and running:
resize2fs /dev/sda3
afterwards. This will enlarge the filesystem to the partition size.

You can try to shrink /home with parted too.

After shrinking home you have new space left on your disk at the end, create a new partition, format it and copy /opt to the new partition. Then the contents of /opt and mount the new partition to /opt. (Make a fstab entry to mount the new partition to /opt on each boot.)
0
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
Ok, I did the following

1) I unmounted /home
2) e2fsck -f /dev/sda3
3) resize2fs /dev/sda3 30G

Ok, I know this is what I am to do next but I don't know the command specifics: After shrinking home you have new space left on your disk at the end, create a new partition, format it and copy /opt to the new partition. Then the contents of /opt and mount the new partition to /opt. (Make a fstab entry to mount the new partition to /opt on each boot.)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.