Solved

Want to reallocate disk areas in LINUX

Posted on 2010-08-13
4
1,302 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

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: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Teach the user how to convert virtaul disk file formats and how to rename virtual machine files on datastores. Open vSphere Web Client: Review VM disk settings: Migrate VM to new datastore with a thick provisioned (lazy zeroed) disk format: Rename a…
Teach the user how to install and configure the vCenter Orchestrator virtual appliance Open vSphere Web Client: Deploy vCenter Orchestrator virtual appliance OVA file: Verify vCenter Orchestrator virtual appliance boots successfully: Connect to the …

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now