LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2012, 04:58 AM   #1
Alvin88
LQ Newbie
 
Registered: Mar 2012
Posts: 18

Rep: Reputation: Disabled
Smile Shrinking SWAP and ezpand ROOT - how this can be done?


Hi all,

I am new here, so first of all - Hello, everybody.

My issue is as follows:
I got Linux CentOS 6.2 istalled on SSD, which is 60 GB. However, the allocation is as follows:
- 26G - is root /
- 12G - home
- 17G - swap

What i would like to do is shrink swap to about 2G, and expand root /, with remaining 15G.

What i have done so far is:
- shrink swap file - I use an instruction which I have found on the Net
cat /etc/fstab | grep swap
lvdisplay /dev/mapper/VolGroup-lv_swap
swapoff /dev/mapper/VolGroup-lv_swap
lvresize /dev/VolGroup/lv_swap -L 2G
mkswap /dev/VolGroup/lv_swap
swapon /dev/VolGroup/lv_swap


The result is as:
lvdisplay /dev/mapper/VolGroup-lv_swap
--- Logical volume ---
LV Name /dev/VolGroup/lv_swap
VG Name VolGroup
LV UUID kGtj3Z-P9ke-tgrc-58hD-OBLe-zRmN-T8kRH4
LV Write Access read/write
LV Status available
# open 1
LV Size 2.00 GiB - it was 17.5 GB before
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

So, i got 15.7G free:
pvscan
PV /dev/sda2 VG VolGroup lvm2 [55.41 GiB / 15.70 GiB free]
Total: 1 [55.41 GiB] / in use: 1 [55.41 GiB] / in no VG: 0 [0 ]


Now the question is - how can I add those 15 GB to root /?
If i missed something, or you need more info - please do not hesitate to ask/point that.
 
Old 03-16-2012, 05:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Have a look here: LVM Resizing Guide

Hope this helps.
 
1 members found this post helpful.
Old 03-16-2012, 05:05 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
is / an LV? if so, then sure, it's really simple. use lvresize to increase the LV to use the rest of the free extents and then from a rescue disk or other mechanism whereby you have the / filesystem not mounted, you can then use resize2fs to make the ext2/3/4 filesystem fit the LV.

If / is NOT an LV, then it's a whole heap more tricky, and a better option may be to make a new LV and migrate some part of / onto it, e.g. /usr or /var
 
Old 03-16-2012, 05:17 AM   #4
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
I haven't tried this, but it seems to me that one workaround you could do is to boot off another source(e.g. live CD), replace the swap partition with a regular one, shrink, and then make it back into a swap partition. After you package it up, make sure it works(so you avoid potentially touching the swap space before you compress it).

Do this as the very last thing before distributing (X windows and all other apps should not be running).
Code:
# swapoff -a
# shred -n 0 -z /dev/sdaXX  # (sdaXX is your swap partition)
# mkswap /dev/sdaXX         # recreate the swap format
# halt
to do it on every shutdown:
edit /etc/init.d/umountfs (at least in ubuntu)
After "swapoff" add:
Code:
# shred -n 0 -z /dev/sdaXX # zero out partition
# mkswap /dev/sdaXX        # recreate swap format
 
Old 03-16-2012, 05:20 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
that's not what they asked, swap is already sorted.
 
Old 03-16-2012, 05:42 AM   #6
Alvin88
LQ Newbie
 
Registered: Mar 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Smile

Many thanks for your help, the link provided by druuna was really helpfull on that occasion.

... and I must say that I am really suprosed by the speed of your response...

Many thanks for your help - and have a great weekend.
 
Old 03-16-2012, 05:46 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
We are a fast bunch, aren't we......

And: You're welcome

BTW: Can you put up the [SOLVED] tag.
first post -> Thread Tools -> Mark this thread as solved
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM and shrinking the root filesystem coreychch Linux - Newbie 5 11-22-2015 10:35 PM
Root and Swap Partitioning CT_0000 Linux - Newbie 15 11-11-2009 12:41 PM
Encrypted root and swap on thumbdrive itags.org Ubuntu 1 08-02-2009 05:04 PM
shrinking root partition and using free space to create a block device kickdgrass Linux - General 1 02-04-2009 05:04 AM
Shrinking Root Partition celticdaddio SUSE / openSUSE 1 10-06-2005 10:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration