?
Solved

Want to reallocate disk areas in LINUX

Posted on 2010-08-13
4
Medium Priority
?
1,371 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:Christopher Schene
[X]
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
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 1200 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 800 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: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.)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Teach the user how to configure vSphere Replication and how to protect and recover VMs Open vSphere Web Client: Verify vsphere Replication is enabled: Enable vSphere Replication for a virtual machine: Verify replicated VM is created: Recover replica…
Teach the user how to use vSphere Update Manager to update the VMware Tools and virtual machine hardware version Open vSphere Client: Review manual processes for updating VMware Tools and virtual hardware versions: Create a new baseline group in vSp…

719 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