1

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
1
  • Let's see the output of pvs and lvs. Aug 9, 2012 at 13:57

2 Answers 2

3

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.

  1. Boot to Rescue Mode
  2. lvm vgchange -a y
  3. e2fsck -f /dev/vg0/root (Or whatever your root Logical Volume is named here.)
  4. 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!
  5. lvm lvreduce -L <targeted size>
  6. 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:

  1. lvcreate -ntmp -L<size> /dev/vg0 (Replace vg0 with your Volume Group like you did above.)
  2. mkfs.ext3 -L tmp /dev/vg0/tmp
  3. mv /tmp /tmp2
  4. mkdir /tmp
  5. Add entry to /etc/fstab for your new mount point.
  6. mount -a
  7. Move /tmp2's data back into the new /tmp. Delete /tmp2.
2
  • Thanks Aaron! Could you provide me with an example, say for doing '/tmp" .
    – Lexicon
    Aug 9, 2012 at 14:08
  • @Lexicon Added an example for /tmp. Aug 9, 2012 at 14:17
1

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.

  1. Backup anything in /home you want to save.
  2. umount /home
  3. lvremove /dev/vg_ts0/lv_home or lvreduce -L200G /dev/vg_ts0/lv_home
  4. lvcreate -nlv_tmp -L<size> vg_ts0
  5. lvcreate -nlv_var -L<size> vg_ts0
  6. lvcreate -nlv_varlog -L<size> vg_ts0
  7. Repeat for remaining mountpoints.
  8. 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.

3
  • How do I do that?
    – Lexicon
    Aug 9, 2012 at 13:55
  • keep in mind, this is being done remotely, via SSH...
    – Lexicon
    Aug 9, 2012 at 14:07
  • @Lexicon If this is being done remotely, you'll need some sort of remote console. What you are doing to these filesystems requires that they be unmounted. Practice this on a local VM or something first. Not a live production system. Aug 9, 2012 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .