Modifying partitions in CentOS 6
Ladies & Gentlemen, I'm currently running CentOS6 6 with 300 GB of storage space. Currently, /dev/sda looks like this (via parted):
Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary ext4 boot
2 525MB 322GB 322GB primary lvm
I am modifying this system to conform to CIS benchmarks, and I need to create separate partitions for /tmp, /var, /var/log, /var/log/audit, and /home.
Any suggestions???
Edit: added PVS and LVS
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_ts0 lvm2 a-- 299.51g 0
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_home vg_ts0 -wi-ao 239.68g
lv_root vg_ts0 -wi-ao 50.00g
lv_swap vg_ts0 -wi-ao 9.83g
Solution 1:
This is going to be far, far easier if you can create a Kickstart script or otherwise do this during the installation phase. I will assume here that you have one big logical volume mounted to root.
You will first need to boot to Rescue Mode (without mounting the local filesystem) and shrink your root logical volume. You can't create any new ones if all of your available space on the physical volume is consumed.
- Boot to Rescue Mode
lvm vgchange -a y
-
e2fsck -f /dev/vg0/root
(Or whatever your root Logical Volume is named here.) -
resize2fs /dev/vg0/root <targeted size -10MB or so>
Your target size can't be smaller than the amount of data or you will truncate your filesystem! lvm lvreduce -L <targeted size>
resize2fs /dev/vg0/root
I shrink the filesystem to slightly below targeted size and then grow it back to the logical volumes capacity to save the funky block size / rounding / math crap. If I was good at math, I'd have finished my C.S. degree and not become a Sysadmin.
Then, you need to move the current directories for your targeted mount points to get them out of the way. (Move /var
to /var2
, /home
to /home2
, etc.)
Then, you can create new logical volumes, new mount points and /etc/fstab
entries, mount every thing, then sync your data back from /var2
to the new /var
logical volume. (Repeat as needed.)
This part assumes that the root filesystem (which contains /tmp) was mounted. You can do it manually with mount
or reboot and let Rescue Mode do it this time around.
Basically:
-
lvcreate -ntmp -L<size> /dev/vg0
(Replace vg0 with your Volume Group like you did above.) mkfs.ext3 -L tmp /dev/vg0/tmp
mv /tmp /tmp2
mkdir /tmp
- Add entry to
/etc/fstab
for your new mount point. mount -a
- Move /tmp2's data back into the new /tmp. Delete /tmp2.
Solution 2:
You're on the right track. Just create separate logical volumes for all of those directories. They don't have to be physical partitions.
Since lv_home contains the most space, you should be able to do this remotely.
- Backup anything in
/home
you want to save. umount /home
-
lvremove /dev/vg_ts0/lv_home
orlvreduce -L200G /dev/vg_ts0/lv_home
lvcreate -nlv_tmp -L<size> vg_ts0
lvcreate -nlv_var -L<size> vg_ts0
lvcreate -nlv_varlog -L<size> vg_ts0
- Repeat for remaining mountpoints.
lvcreate -nlv_home -L<size> vg_ts0
That will also leave you some space in the volume group for expanding the other logical volumes at a later date.