Solved

Want to reallocate disk areas in LINUX

Posted on 2010-08-13
4
1,313 Views
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 ~]#

0
Comment
Question by:cschene
  • 2
4 Comments
 
LVL 3

Expert Comment

by:pitt7
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.
0
 
LVL 1

Accepted Solution

by:
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
0
 
LVL 3

Assisted Solution

by:pitt7
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.

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
 

Author Comment

by:cschene
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.)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

776 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