Difference between revisions of "LVM2"

From ArchWiki
Jump to: navigation, search
(added snapshot section (stub - needs work))
(content merged with Lvm)
Line 1: Line 1:
{{stub}}
+
#REDIRECT [[Lvm]]
=Logical Volume Manager v.2=
+
This is going to be a page dedicated to LVM2, with information on "what, why and how", complete with several examples. What is LVM2, Why use LVM2, How to use LVM2
+
<br>
+
Anyone and everyone with knowledge and experience with LVM2 are more than welcome to contribute.
+
<br>
+
Since this page is far from complete, you should also take a look at [[Installing_with_Software_RAID_or_LVM]], [http://www.tldp.org/HOWTO/LVM-HOWTO/ TLDP LVM HOWTO] and [[RAID_Encryption_LVM]]
+
==Example 1: Install with root on lvm2==
+
'''Case:'''
+
:A desktop system with one disc, 20GB. No other os installed.
+
:''The install medium used in this example is the Archlinux-i686-2007.05-Duke-Linuxtag2007.ftp.iso
+
===Partitioning===
+
We need to create some partitions. One for /boot and one for the LVM setup. I prefer cfdisk for this, but you can use any tool you like.<br>
+
;/dev/sda1  100Mb Primary, type 83, bootable : This is going to be boot partition. It is possible to have the boot partition on lvm2, but you will have to use Lilo or Grub 1.95 or later. (arch provides grub 0.97 on the cd)
+
;/dev/sda2  20Gb  Primary, type 83 :This is where we are going to put the LVM. You don't really need to create a partition for it, but it has some advantages. Mainly, many partition tools can't see a LVM setup, and just think that the space is free, unless you set up a normal partition for it. This can can cause problems e.g. if you later decide to set up dualboot with another os.
+
<br>
+
 
+
===Set up LVM2===
+
First load the necessary kernel module:
+
# modprobe dm-mod
+
<br>
+
Initialize the partition so that lvm can use it:
+
''Note: On the install cd, you have to run ''lvm [some_tool]'' instead of [some_tool] as you would on an already installed system.''
+
# lvm pvcreate /dev/sda2
+
<br>
+
Create a volume group (you can use another name instead of vgroup1, if you want)
+
# lvm vgcreate vgroup1 /dev/sda2
+
<br>
+
Create some logical volumes(partitions) on the volume group. (you can give them any name you want)<br>
+
*First, lets create a 5GB / partition:
+
# lvm lvcreate -L 5G vgroup1 -n root
+
*Next, a 512MB swap
+
# lvm lvcreate -L 512M vgroup1 -n swap
+
*And last, let's use the remaining free space for /home
+
# lvm lvcreate -l 100%FREE vgroup1 -n home
+
<br>
+
Now we need to activate the volume group before we start the installer:
+
# lvm vgchange -a y vgroup1
+
 
+
===The Arch Installer===
+
''Note: This only list the steps that have to do with lvm2. Refer to the install guide for more information about the other steps of the install.''
+
<br>
+
Start the installer
+
# /arch/setup
+
<br>
+
In the installer, under "Prepare Hard Drive, skip directly to step 3 "Set Filesystem Mountpoints"(don't choose autoprepare or partition hard drive)<br>
+
;/dev/sda1 : /boot with ext3
+
;/dev/mapper/vgroup1-root : /root with ext3
+
;/dev/mapper/vgroup1-swap : swap with swap
+
;/dev/mapper/vgroup1-home : /home with ext3
+
<br>
+
"Configure System"<br>
+
''Important:' Answer YES to Preconfiguration with hwdetect, and to boot from LVM2
+
<br>
+
;/etc/rc.conf : Chang USELVM="no" to USELVM="yes"
+
;/etc/mkinitcpio.conf : Make sure that lvm2 is present in HOOKS=
+
;/etc/fstab : Just glance over it to check that the mount points are correct.
+
<br>
+
"Install Bootloader"
+
;/boot/grub/menu.lst : The installer usually get this one right, but just check that everything is ok, especially the root= line.
+
Install grub to /dev/sda and choose NO to the software raid question.
+
<br><br>
+
That's it, exit the installer, remove the cd, and reboot.
+
==Example 2: Making a Snapshot==
+
LVM allows you to take a snapshot of your system in a much more efficient way than a traditional backup.  It does this efficiently by using a COW (copy-on-write) policy.  The initial snapshot you take simply contains hard-links to the inodes of your actual data. So long as your data remains unchanged, the snapshot merely contains there inode pointers and not the data itself.  Whenever you modify a file or directory that the snapshot points to, LVM automatically clones the data, the old copy referenced by the snapshot, and the new copy referenced by your active system.  Thus, you can snapshot a system with 35GB of data using just 2GB of free space so long as you modify less than 2GB of data.
+
 
+
Instructions:
+
* (todo)
+

Revision as of 10:44, 26 April 2008

Redirect to: