Our corporate standard is CentOS (which seems to prefer LVM), and I come from primarily a non-LVM background, so I'm treading new ground with this issue.
I inherited an older machine as a log-server and had to reinstall CentOS. Due to issues with EHCI on the motherboard (either via the normal install DVD or via LiveCD GUI install), the only thing I could find that would install CentOS 6.3 was a LiveCD text install. The LiveCD text install would not allow me to make my own partition settings on the disk; it only installs LVM and gave me bad space allocation for a log server...
[mpenning@someHost ~]$ cat /etc/issue
CentOS release 6.3 (Final)
Kernel \r on an \m
[mpenning@someHost ~]$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/mapper/vg_livecd-lv_root
50397 2167 47719 5% /
tmpfs 1850 0 1850 0% /dev/shm
/dev/md127p1 485 65 395 15% /boot
/dev/mapper/vg_livecd-lv_home
227001 188 215283 1% /home
[mpenning@someHost ~]$ sudo lvm vgdisplay
--- Volume group ---
VG Name vg_livecd
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 278.96 GiB
PE Size 4.00 MiB
Total PE 71415
Alloc PE / Size 71415 / 278.96 GiB
Free PE / Size 0 / 0
VG UUID 8qywNz-cmKv-RxAH-WcsV-2nEA-sGg3-fcZ6BU
[mpenning@someHost ~]$
Two questions:
- If I need to increase
/
to have 257398 1-M blocks and decrease/home
to 20000 1-M blocks, can I do this without rebooting and if so, what is the specific command sequence to do this? - If I want to add a dedicated
/var
partition, how should I do it without a complete reinstall?
You have roughly 280GB of space available, of which 50GB has been allocated to '/' and 230GB has been allocated to
/home
. Because this represents all of your available space, you're going to have to free something up first. Here are a few options:If you haven't placed any data in
/home
, it's easiest to just discard the existing filesystem and re-create it with the appropriate size:Unmount
/home
:Reduce the size of the logical volume (LV) to 20GB:
Recreate the
/home
filesystem:And remount
/home
:It is possible to shrink
/home
, rather than discarding it, but this can be a little trickier:Unmount
/home
:fsck
the filesystem. This is probably required by the next step:Resize the filesystem:
Reduce the LV:
You'll note that I've reduced the filesystem a little bit more than the LV; this is because I can never remember if they count things the same way so I try to leave a little wiggle room.
In either case, at this point you now have roughly 210GB free space in your volume group. Now you can increase the size of your root filesystem:
Increase the size of the root LV:
Increase the size of the filesystem:
Note that you may need to use a number slightly less than 260G due to the rounding I'm using in this answer. Also, recent versions of the LVM utilities include the ability to resize the filesystem for you, but I've been doing this since before those options were available...so I can't claim to know exactly how they operate.
First, you'll probably want to do this in single-user mode, otherwise running processes will probably have files open in
/var
making it hard to replace. Having said that...Once again you're going to need free space. If instead of using up all your free space in the previous step you leave a few GB free, you can do this:
Create a new logical volume:
Create a new filesystem:
Edit
/etc/fstab
to mount the new LV on/var
by adding the following line:But don't mount it yet!
Mount the new filesystem somewhere convenient:
Copy over the contents of
/var
:Rename
/var
to/var.old
and create a new directory:Mount your new LV on
/var
:# umount /mnt # mount /var
And continue booting. When you are satisfied everything is working correctly you can delete
/var.old
.Considering:
AFAIC, I'd try to netinstall/kickstart to get the desired configuration in one shot and in a reproductible way.
My 2cts