Linux LVM Partitioning
From KdjWiki
NOTE: This is a destructive process and if you don't know (or understand) what you are doing can kill your existing setup. Please use with caution and don't blame me if you mess things up!
Contents |
Configure Partition
If we want to setup a partition (say /dev/sda4) for music and video, and we expect to need to expand it as our collection grows, we may like to use LVM to future-proof our setup. In this example, /dev/sda4 is a partition 250GB in size.
First, in fdisk, ensure the partition is type 8e (LVM):
$ sudo fdisk /dev/sda
Enter the command t (t = change type)
Enter the partition (in our example 4)
Enter the hex code 8e (8e = Linux LVM)
Enter w to write the changes and exit fdisk
Create the Media volume group
$ sudo pvcreate /dev/sda4 $ sudo vgcreate MediaVG -s 8m /dev/sda4
This creates a volume group called Media with a physical extent size of 8MB. If you are only going to put music (or other small-ish files here - you might want to change this to 2m or 4m).
Create the Music and Video volumes
We are going to allocate 50GB to music and 200GB to video. The music volume is going to be formatted as reiserfs and video xfs:
$ sudo lvcreate --name music --size 50G MediaVG $ sudo mkreiserfs /dev/MediaVG/music
$ sudo lvcreate --name video --size 250G MediaVG $ sudo mkfs.xfs /dev/MediaVG/video
Using the volumes
As you may have noticed above, the volumes are now accessed via
/dev/MediaVG/music
and
/dev/MediaVG/video
Mount volumes
$ sudo mount /dev/MediaVG/music /var/music $ sudo mount /dev/MediaVG/video /var/video
Show status
$ sudo vgdisplay -v
Management Tasks
Add Volume
Add volume (e.g. 200GB):
- Create partiton (/dev/hdc1) for whole disk - type 8e (LVM)
- Create physical volume: $ sudo pvcreate /dev/hdc1
- Add physical volume to the volume group: $ sudo vgextend MediaVG /dev/hdc1
- Extend music (50GB):
$ sudo umount /var/music $ sudo resize_reiserfs /dev/MediaVG/music $ sudo mount /dev/MediaVG/music /var/music
- Extend video (150GB):
$ sudo lvextend --size +150G /dev/MediaVG/video $ sudo xfs_growfs /var/video