Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

Using LVM to expand existing Linux directory

Hi all,

    It is my first time to ask question. I am using Redhat 8.0 for the servers in my office (one with IDE and one with SCSI HDD). Recently, the space for the for the /home directory is running out of space. Someone tell me that I can use LVM to resize and make use of the free space in other partitions (e.g.: /usr and /var) (sorry for using the word 'partition' as I can't think of another better word).

    However, when I read the information about LVM, it said that creating the LVM logical volume will distory the information in that directory. As I have never created it before, is it the case if I create one in my server? It is not affordable for me to have another new hard disk.

    On the other hand, if I choose to format the harddisk (this is the last step if nothing can do), what I need to do in order that I can resize the logical volume in the server?

    The following are some information all the system:
- Redhat 8.0 (kernel 2.4.18-26.8.0)
- with /, /home, /usr, /var, /boot
- LVM module LVM version 1.0.3
- not create any logical group and volume before

    Thank you for any suggestion.

William
0
kidwong
Asked:
kidwong
  • 3
  • 2
1 Solution
 
JaemCommented:
To use LVM, you will have to destroy your existing partitions, and recreate them as LVM ones. I have two possible solutions:
1) Real easy, but not very elegant. Create a home directory in /usr (I suppose it is where you got most of your free space) and create symbolic links in /home to corresponding directories in /usr/home as need arises.
2) Use resize2fs/fdisk or parted to rearrange your partitions. This might be tricky and dangerous, so you will need to do backups. resize2fs will shrink or expand e2/3fs. fdisk will modify your partition size. parted should be able to do both at once. You might even be able to create LVM. Could you tell us more about the size/layout of your harddrive? (fdisk -l /dev/hda)
0
 
kidwongAuthor Commented:
Thank you Jaem,

The following is the layout of the harddrive:

Disk /dev/hda: 255 heads, 63 sectors, 1222 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1        13    104391   83  Linux
/dev/hda2            14       842   6658942+  83  Linux
/dev/hda3           843       969   1020127+  83  Linux
/dev/hda4           970      1222   2032222+   f  Win95 Ext'd (LBA)
/dev/hda5           970      1033    514048+  83  Linux
/dev/hda6          1034      1071    305203+  83  Linux
/dev/hda7          1072      1103    257008+  82  Linux swap

By the way, for the second suggestion, I am not sure how to implement as I have never done that before. Could you explain a little bit detail? Thank you

William
0
 
JaemCommented:
The plan might be:
1) Shrink a big partition (either with parted, or shrinking the fs (resize2fs), then the partition (fdisk)).
2) Use the freed space!

Now I realize I need much more information about your layout. Could you post the output of "df". That would tell me what is
/dev/hda2 (6.5Gig, /home ?)
/dev/hda3 (1Gig, /usr ?)
/dev/hda5 (500Meg, /var ?)
/dev/hda6 (300Meg, / ?)
And maybe look into etc/fstab to make sure that the filesystems are ext3.

Also could you give an estimate of how much space you want in your /home directory.

Apparently you got 1 Gig of free disk space left (you can create an hda8 partition). And if my layout is about right, it might be possible to temporarily move the hda5 hda6 hda7 partitions on a temporary location, and free them. Then you would get 1 more gig to play around with...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kidwongAuthor Commented:
Hi Jaem,

The following is the result of df -h:
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda6             289M   93M  180M  34% /
/dev/hda1              99M  9.0M   84M  10% /boot
/dev/hda5             486M  480M    5M  98% /home
none                   57M     0   57M   0% /dev/shm
/dev/hda2             6.3G  3.8G  2.1G  64% /usr
/dev/hda3             980M  144M  786M  16% /var

All of the filesystem are ext3. And I would like to have 2 Gig free space for /home.

Thanks for your help and looking forward to having your reply.

William
0
 
JaemCommented:
Hi kidwong,

The big picture: put everything in hda2. Check if it works. Backup. Repartition to your taste, and put everything back into place.

I got to try this first on my RH7.3, but those are the steps I would take:
1) Modify /etc/grub.conf, so it could boot with root device /dev/hda2 (instead of /dev/hda6).
2) Boot with the CD/rescue CD. Mount /dev/hda2 read-write, create a /usr directory and move everything into it. Then I would mount /dev/hda3 (resp. /dev/hda5, /dev/hda6) (read-only, so not to mess anything), copy all of its files under the directories /var (resp. /home, /) relative to the mount point.
3) Create a swapfile in /dev/hda2 mount point directory. Do "dd if=/dev/zero of=swapfile bs=1024k count=256" and "mkswap swapfile".
4) Modify /etc/fstab (hda2) (after: backing it up): Comment out every ref to partition others than hda2 and hda1. Create an entry for the swapfile:
/swapfile  none   swap    defaults 0 0
5) unmount all, reboot, select the grub entry for booting with /dev/hda2 as root, and check everything is OK, especially check that hda3, hda5, hda6, hda7 are not used (use "mount" and "swapon -s").
5bis) Emergency recovery: Undoing the changes is easier. Boot in rescue mode, mount /dev/hda2, remove all directories except /usr, then move everything in /usr to the root.

Now I would do a raw backup the partitions we are about to destroy (A CD writer would be good). I need to work the details out, cause it's something I really don't want to mess.

Then you should be ready to reorganize your partitions: you can do about anything to /dev/hda3, /dev/hda5... Everything is temporarily working on /dev/hda2, and you got backups. Do you still want to go the LVM route? Else you got to choose the resizing/partition editing software. I don't know what redhat got on its CD...

Only thing that bothers me about the current layout of your disk, is that the extended partition (/dev/hda4) is way too small, and /dev/hda2 is a bit too big (it might be a good idea to shrink it first to 5G). Getting rid of /dev/hda3 would be good also.

Another thought. You wouldn't have any hard drive lying around, would you? Temporarily connecting another harddrive is useful for moving things around and/or quick backups.

Tell me what you think.
0
 
CleanupPingCommented:
kidwong:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now