Want to reallocate disk areas in LINUX

Posted on 2010-08-13
Last Modified: 2013-12-16
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 ~]#

Question by:Christopher Schene
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 33431496
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.

Accepted Solution

bguyton3 earned 300 total points
ID: 33431828
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

Assisted Solution

pitt7 earned 200 total points
ID: 33432360
Another option is shrinking your /home partition (which is quite easy) and creating a new partition for /opt.

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

Author Comment

by:Christopher Schene
ID: 33448247
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.)

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
Teach the user how to use configure the vCenter Server storage filters Open vSphere Web Client:  Navigate to vCenter Server Advanced Settings: Add the four vCenter Server storage filters: Review the advanced settings: Modify the values of the four v…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question