Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My hard drive currently has (I believe) 2 partition; boot (sda1) and everything else (sda2?). Some of the hard drive is also being used as swap memory, but I don't really understand how that effects things. The server is physical and I have a LiveCD.

How do I add a new partition (1 MB, ext3) to the hard drive, and make sda2 smaller to accommodate the new partition?

Any additional comments on how lvm, /dev/mapper, and dm-0 and dm-1 apply would be appreciated, but not required.

Thank you

[root@desktop ~]# mount
/dev/mapper/vg_desktop-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 

[root@desktop ~]# fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00056f9a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64      182402  1464625152   8e  Linux LVM

[root@desktop ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_desktop/lv_root
  LV Name                lv_root
  VG Name                vg_desktop
  LV UUID                DhBjdq-0UJR-dJjx-bgH6-adGJ-TL43-8DrZR7
  LV Write Access        read/write
  LV Creation host, time desktop.xxx.com, 2013-07-01 04:10:19 -0700
  LV Status              available
  # open                 1
  LV Size                1.36 TiB
  Current LE             356082
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     1024
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_desktop/lv_swap
  LV Name                lv_swap
  VG Name                vg_desktop
  LV UUID                mNpyae-UtdA-MzJR-bbEc-D9OA-VPn8-ECMpbq
  LV Write Access        read/write
  LV Creation host, time desktop.xxx.com, 2013-07-01 04:13:25 -0700
  LV Status              available
  # open                 1
  LV Size                5.83 GiB
  Current LE             1492
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     1024
  Block device           253:1

[root@desktop mapper]# ls -l /dev/mapper
total 0
crw-rw----. 1 root root 10, 58 Jul  4 00:37 control
lrwxrwxrwx. 1 root root      7 Jul  4 00:37 vg_desktop-lv_root -> ../dm-0
lrwxrwxrwx. 1 root root      7 Jul  4 00:37 vg_desktop-lv_swap -> ../dm-1
[root@desktop mapper]#
share|improve this question
    
Is this 1MB a requirement or just an example? The proper way is to shrink an LVM and add another one. –  Nathan C Jul 4 '13 at 14:16
    
@NathanC. 1MB is just an example. –  user1032531 Jul 4 '13 at 14:22
    
@NathanC. I've since shrunk my LVM to 1000G. Question remains how do I add a new partition (using remaining space instead of only 1MB)? Thanks –  user1032531 Jul 4 '13 at 15:21

1 Answer 1

up vote 2 down vote accepted

You'll need to shrink your existing group with lvreduce to make room for the new volume. Then, you can use:

lvcreate -L 3G -n <lvname> vg_desktop where 3G is the size you want the volume to be. Then:

mkfs -t ext3 /dev/vg_desktop/<lvname> to format it. And finally, mount it with mount -t ext3 /dev/vg_desktop/<lvname> /mnt/somedir.

share|improve this answer
    
Thanks! Looks like I still have only (2) partitions (sda1 & 2), however, sda2 uses LVM to effectively have multiple partitions (in my new case, lv_root, lv_swap, and lv_myNewPartition). Correct? Also, I am sure you knew, but when mounting, I needed to add "lv_" to my selected <lvname>. –  user1032531 Jul 4 '13 at 15:47
    
That is correct. LVM is "logical" so it won't appear as an sda*-style partition. It's actually designed to span multiple drives too. –  Nathan C Jul 4 '13 at 15:49
    
Makes sense. Do you know if LVM is slower than creating a new primary partition on a single drive? My reason for doing this is to store /var/lib/mysql on its own partition, see if ext3 is quicker, remove barriers, or whatever is needed. See serverfault.com/questions/518747/… for history. –  user1032531 Jul 4 '13 at 16:04
    
LVM should be more or less the same. –  Nathan C Jul 4 '13 at 17:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.