<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Silent</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Silent"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Silent"/>
	<updated>2026-04-29T22:49:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Logical_Volumes_with_LVM&amp;diff=8272</id>
		<title>Setting up Logical Volumes with LVM</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Logical_Volumes_with_LVM&amp;diff=8272"/>
		<updated>2012-06-06T19:32:25Z</updated>

		<summary type="html">&lt;p&gt;Silent: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Storage]]&lt;br /&gt;
{{Tip|This process can be done automatically by using the [[setup-disk]] script, using the -L option.}}&lt;br /&gt;
This document how to create logical volumes in Alpine using lvm2.&lt;br /&gt;
&lt;br /&gt;
LVM is collection of programs that allow larger physical disks to be reassembled into &amp;quot;logical&amp;quot; disks that can be shrunk or expanded as data needs change.&lt;br /&gt;
&lt;br /&gt;
In this document we will use a [[Setting up a software raid1 array | software raid1 device]] as physical storage for our logical volumes. We will set up a swap partition and a data partition for [[Setting up a basic vserver | vservers ]]&lt;br /&gt;
=== Installing LVM software ===&lt;br /&gt;
First we need to load the kernel driver, &#039;&#039;dm-mod&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe dm-mod}}&lt;br /&gt;
&lt;br /&gt;
We also want it to be loaded during next reboot.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo dm-mod &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
We also need the userspace programs.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add lvm2}}&lt;br /&gt;
&lt;br /&gt;
=== Preparing the physical volumes ===&lt;br /&gt;
First we need to tell LVM that the partition is available as a physical volume and can be added to a volume group. In this example we use a software raid array as physical volume.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|pvcreate /dev/md0}}&lt;br /&gt;
&lt;br /&gt;
=== Preparing the Volume Group ===&lt;br /&gt;
We can then create a volume group and add the physical volume &#039;&#039;/dev/md0&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|vgcreate vg0 /dev/md0}}&lt;br /&gt;
&lt;br /&gt;
If we later need more space we can add additional physcal volumes with &#039;&#039;vgextend&#039;&#039;. All physcal disks/partitions added need to be prepared with &#039;&#039;pvcreate&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Creating Logical volumes ===&lt;br /&gt;
In the volume group we can create logical volumes. To create a 1GB volume called &#039;&#039;swap&#039;&#039; and a 6GB volume called &#039;vservers&#039;&#039; on the volume group &#039;&#039;vg0&#039;&#039; we run&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lvcreate -n swap -L 1G vg0&lt;br /&gt;
lvcreate -n vservers -L 6G vg0}}&lt;br /&gt;
&lt;br /&gt;
=== Display Logical Volumes ===&lt;br /&gt;
You can now se the logical volumes with the lvdisplay utility.&lt;br /&gt;
&lt;br /&gt;
 lvdisplay&lt;br /&gt;
  --- Logical volume ---&lt;br /&gt;
  LV Name                /dev/vg0/swap&lt;br /&gt;
  VG Name                vg0&lt;br /&gt;
  LV UUID                a4NYOi-FQP6-Lj5Q-0TYk-Jjtk-Qxjt-nxeBPn&lt;br /&gt;
  LV Write Access        read/write&lt;br /&gt;
  LV Status              available&lt;br /&gt;
  # open                 0&lt;br /&gt;
  LV Size                1.00 GB&lt;br /&gt;
  Current LE             256&lt;br /&gt;
  Segments               1&lt;br /&gt;
  Allocation             inherit&lt;br /&gt;
  Read ahead sectors     0&lt;br /&gt;
  Block device           253:0&lt;br /&gt;
   &lt;br /&gt;
  --- Logical volume ---&lt;br /&gt;
  LV Name                /dev/vg0/vservers&lt;br /&gt;
  VG Name                vg0&lt;br /&gt;
  LV UUID                16VMmy-7I0s-eeoW-tL2V-JrlN-jM6C-d0wEg0&lt;br /&gt;
  LV Write Access        read/write&lt;br /&gt;
  LV Status              available&lt;br /&gt;
  # open                 0&lt;br /&gt;
  LV Size                6.00 GB&lt;br /&gt;
  Current LE             1536&lt;br /&gt;
  Segments               1&lt;br /&gt;
  Allocation             inherit&lt;br /&gt;
  Read ahead sectors     0&lt;br /&gt;
  Block device           253:1&lt;br /&gt;
&lt;br /&gt;
=== Rename Logical Volumes ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lvrename /dev/vg0/vservers /dev/vg0/database}}&lt;br /&gt;
&lt;br /&gt;
=== Extend Logical Volumes ===&lt;br /&gt;
If you want to add space and the volume has the room for it...&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lvextend -L +50G /dev/vg0/vservers}}&lt;br /&gt;
&lt;br /&gt;
If you want to set the space to a new larger size...&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lvextend -L 10G /dev/vg0/vservers}}&lt;br /&gt;
&lt;br /&gt;
=== Start LVM during Boot ===&lt;br /&gt;
We want lvm to init the logical volumes during boot. There is a boot service named &#039;&#039;lvm&#039;&#039; to do this. If your volumes are on raid, make sure that &#039;&#039;/etc/init.d/lvm&#039;&#039; is started after mdadm-raid.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add lvm}}&lt;br /&gt;
&lt;br /&gt;
Or, on Alpine Linux 1.8 or earlier:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc_add -s 12 -k lvm}}&lt;br /&gt;
&lt;br /&gt;
=== Setting up swap ===&lt;br /&gt;
Now we have our devices in /dev/vg0 and can use them as normal disk paritions. To set up swap:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mkswap /dev/vg0/swap}}&lt;br /&gt;
&lt;br /&gt;
Add the following line to your &#039;&#039;/etc/fstab&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 /dev/vg0/swap   none            swap     sw    0 0&lt;br /&gt;
&lt;br /&gt;
=== Setting up /vservers partition ===&lt;br /&gt;
Finally we want to set up an XFS partition for /vservers.&lt;br /&gt;
&lt;br /&gt;
Install xfsprogs.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add xfsprogs}}&lt;br /&gt;
&lt;br /&gt;
Create filesystem on /dev/vg0/vservers.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mkfs.xfs /dev/vg0/vservers}}&lt;br /&gt;
&lt;br /&gt;
Add the mount information to your /etc/fstab: NOTE:tagxid may cause this not to mount. Try this by hand and check dmesg to see if there are any errors&lt;br /&gt;
&lt;br /&gt;
 /dev/vg0/vservers /vservers     xfs     noatime,tagxid 0 0&lt;br /&gt;
&lt;br /&gt;
Note that the &#039;&#039;tagxid&#039;&#039; option is specific for setting up vserver [http://oldwiki.linux-vserver.org/Disk+Limits disk limits] so it might be you don&#039;t want it. The &#039;&#039;noatime&#039;&#039; option is to increase performance but you will no longer know when files were accessed last time.&lt;br /&gt;
&lt;br /&gt;
=== Starting localmount and swap ===&lt;br /&gt;
&lt;br /&gt;
Now we can mount our partition.&lt;br /&gt;
{{Cmd|mount /vservers}}&lt;br /&gt;
&lt;br /&gt;
Make sure we run &#039;&#039;localmount&#039;&#039; during boot too, and that it is done after lvm. In Alpine Linux 1.9 and newer this should not be needed&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add localmount boot}}&lt;br /&gt;
&lt;br /&gt;
Or, on Alpine Linux 1.8 or earlier:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc_add -s 14 -k localmount}}&lt;br /&gt;
&lt;br /&gt;
Start the swap service and make sure it starts during next reboot and that it starts &#039;&#039;&#039;after&#039;&#039;&#039; lvm.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/swap start&lt;br /&gt;
rc-update add swap}}&lt;br /&gt;
&lt;br /&gt;
Or, on Alpine Linux 1.8 or earlier:&lt;br /&gt;
{{Cmd|/etc/init.d/swap start&lt;br /&gt;
rc_add -s 14 -k swap}}&lt;br /&gt;
&lt;br /&gt;
=== More Info on LVM ===&lt;br /&gt;
These resources may be helpful:&lt;br /&gt;
&lt;br /&gt;
* the [http://tldp.org/HOWTO/LVM-HOWTO/commontask.html common tasks] section in the [http://tldp.org/HOWTO/LVM-HOWTO/index.html LVM Howto]&lt;br /&gt;
* [https://wiki.archlinux.org/index.php/LVM Arch wiki page on LVM]&lt;br /&gt;
* [https://wiki.archlinux.org/index.php/Software_RAID_and_LVM Arch wiki page on RAID and LVM]&lt;/div&gt;</summary>
		<author><name>Silent</name></author>
	</entry>
</feed>