Editing LVM

From Bibliotheca Anonoma

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
LVM is greatly extensible and can be set up into Volume Groups.
LVM is greatly extensible and can be set up into Volume Groups.


<pre>
```
<x404102> You make an LVM drive array on the drives. Then you partition it in two partitions, 2TB each, for both drives that makes VG volume groups. so you have 4 volume ground A0 A1 B0 B1. You put a RAID 1 on A0 and B0 and a RAID 0 on A1 and B1.
<x404102> You make an LVM drive array on the drives. Then you partition it in two partitions, 2TB each, for both drives that makes VG volume groups. so you have 4 volume ground A0 A1 B0 B1. You put a RAID 1 on A0 and B0 and a RAID 0 on A1 and B1.
<x404102> It's not really partition it's just volume groups.
<x404102> It's not really partition it's just volume groups.
Line 12: Line 12:
<antonizoon> I'll note this down
<antonizoon> I'll note this down
<x404102> Yeah LVM is recommended it's extensible. You can grow a RAID https://raid.wiki.kernel.org/index.php/Growing
<x404102> Yeah LVM is recommended it's extensible. You can grow a RAID https://raid.wiki.kernel.org/index.php/Growing
</pre>
```
 
From now on, now that I understand the value and power of LVM partitioning, I will set it up for every drive I see.
 
== LVM (Graphical) ==
 
<code>system-config-lvm</code> or <code>kvpm</code>
 
Graphical partitioning systems are the best way to create logical volumes.
 
== LVM (Command Line) ==
 
=== Create MBR or GPT Partitions ===
 
First, you should format your drive with a partition table. While LVM can be installed to the entire disk without a partition table, there are severe downsides, especially if you are using a non-UEFI BIOS, and no speed advantages.
 
While GPT is a superior partition table format, not all BIOSes support it, especially those made before 2012 (when Windows 8 and UEFI was released for PCs). Thus, I chose to use MBR with one partition.
 
Use GParted to create an MBR Partition table and one Linux LVM partition. Or use <code>fdisk</code> and create one partition with type <code>8e</code> (Linux LVM).
 
http://askubuntu.com/questions/153761/can-i-install-to-a-raw-logical-volume-or-must-i-partition-the-space-first
 
=== Create Physical Volume ===
 
<blockquote>In this example, the SSD partition is at <code>/dev/sda1</code>. This may not always be the case, so be very careful.
</blockquote>
<pre># pvcreate /dev/sda1</pre>
=== Create Volume Group ===
 
Now, you can create a volume group for your drive. It might be a good idea to follow a decent naming convention: one where you use your hostname.
 
<pre># vgcreate vg_stavatron_00 /dev/sda</pre>
You can extend it to other devices as well using <code>vgextend</code>.
 
<pre># vgextend vg_stavatron_00 /dev/sdc</pre>
* [http://tanguy.ortolo.eu/blog/article72/naming-vgs Volume Group Naming Convention]
 
=== Create Logical Volume ===
 
Now we need to create some logical volumes in the volume group. The following partitions are usually prudent choices:
 
<blockquote>'''Note:''' Reserve about 20% of free space above the minimum to handle increased sizes.
</blockquote>
* <code>/boot</code> (100-200MB) - Contains the kernel and other boot information.
* <code>/</code> (15-20GB) - The root partition, containing most of the system.
* <code>/var</code> (10-12GB) - Contains many small files. The choice of file system type should consider this fact if a separate partition is used.
* Because a lot of small read/writes are made to <code>/var/</code>, which can reduce it's working lifetime, you should consider storing it on a hard drive.
* <code>/tmp</code> (tmpfs) - To significantly enhance system performance, the data in <code>/tmp</code> can be stored in RAM instead. This also reduces wear on the SSD. You can set up tmpfs after installation.
* swap - A swap partition is necessary when RAM is completely used up, or the system needs to store data for hibernation (on a laptop).
* Alternatively, you could use [https://wiki.archlinux.org/index.php/Swap#Swap_file a variable-size on-demand swapfile] on an <code>ext4</code> partition. NEVER create a swapfile on a <code>brtfs</code> partition.
* You should reduce the swappiness to a very low level, such as 1.
 
<pre># lvcreate -L &lt;size&gt; &lt;volume_group&gt; -n &lt;logical_volume&gt;
# lvcreate -L 100M vg_stavatron_00 -n lv_boot
# lvcreate -L 20G vg_stavatron_00 -n lv_root
# lvcreate -L 15G vg_stavatron_00 -n lv_var
# lvcreate -l +100%FREE vg_stavatron_00 -n lv_home</pre>
* [https://wiki.archlinux.org/index.php/Tmpfs Arch Linux Wiki - Tmpfs]
 
=== Filesystem Formats ===
 
There are various filesystem formats you can choose from, and each of them bring their own benefits and disadvantages. They also have certain settings that optimize performance on SSDs.
 
* <code>ext4</code> - Rock solid, well tested, known to be reliable. <code>/boot</code> also requires you to use an <code>ext</code> filesystem, so this is the best choice.
* <code>/boot</code> <code>/home</code>, <code>/</code>
* <code>brtfs</code> - Relatively new, known for being bleeding edge, but offers higher performance. Make sure you use the latest kernels possible if you plan to use it.
* However, even though stability is much higher these days, <code>brtfs</code> is not stable enough in comparison to <code>ext4</code> for situations where corruption caused by the filesystem is unacceptable, in the case of the <code>/home</code> partition.
* The problem with btrfs is that when it fails, [https://www.reddit.com/r/linux/comments/3dl2nw/is_btrfs_production_ready/ct68pnw it fails HARD.] It also doesn't deal with random power outages very well (which can be common on a laptop) and corrupts files to the point that it can't be deleted without a &quot;btrfs check&quot;.
* In addition, with LVM you cannot resize a <code>brtfs</code> partition. On the flip side, you can make subvolumes under brtfs.
* <code>/</code>, <code>/var/</code>
 
Format the logical volumes you made:
 
<pre># mkfs.ext4 /dev/mapper/vg_stavatron_00-lv_boot
# mkfs.ext4 /dev/mapper/vg_stavatron_00-lv_root
# mkfs.ext4 /dev/mapper/vg_stavatron_00-lv_var
# mkfs.ext4 /dev/mapper/vg_stavatron_00-lv_home</pre>
 
-----
 
* [http://unix.stackexchange.com/questions/685/why-put-things-other-than-home-to-a-separate-partition Stack Overflow - Why put things other than /home/ to a separate partition?]
* [https://wiki.archlinux.org/index.php/File_systems#Types_of_file_systems Arch Linux Wiki - File Systems: Types of File Systems]
* [https://docs.fedoraproject.org/en-US/Fedora/15/html/Installation_Guide/s2-diskpartrecommend-x86.html Fedora 15: Recommended Partition Scheme]
 
=== Is Brtfs Right for me? ===
 
http://marc.merlins.org/linux/talks/2015/Btrfs-LCA2015/Btrfs.pdf
 
Make backups. Always. With Brtfs snapshots, there's no excuse.
 
=== Copy over Data with Rsync ===
 
I mounted the <code>lv_home</code> partition and sent my 9GB <code>/home</code> directory over in just 30 seconds at 91MB/second.
 
<pre># mkdir /mnt/lv_device
# mount /dev/mapper/vg_stavatron_00-lv_home  /mnt/lv_device
# rsync -aAXv /home/* /mnt/lv_device/
# umount /dev/mapper/vg_stavatron_00-lv_home</pre>
Next, I sent over <code>/var</code>. I made sure to clean up my pacman cache before doing this step.
 
<pre># mount /dev/mapper/vg_stavatron_00-lv_var  /mnt/lv_device
# rsync -aAXv /var/* /mnt/lv_device/
# umount /dev/mapper/vg_stavatron_00-lv_var</pre>
After that, I sent over <code>/boot</code>. Unlike the previous ones, we will use the a new <code>/mnt/lv_boot</code> to reduce confusion.
 
<pre># mkdir /mnt/lv_boot
# mount /dev/mapper/vg_stavatron_00-lv_boot  /mnt/lv_boot
# rsync -aAXv /boot/* /mnt/lv_boot/
# umount /dev/mapper/vg_stavatron_00-lv_boot</pre>
Finally, I sent over <code>/</code> with some directories excluded. I excluded <code>/home</code> and <code>/var</code> since they have their own partitions already (which need to be set in <code>fstab</code>).
 
<pre># mount /dev/mapper/vg_stavatron_00-lv_root  /mnt/lv_device
# rsync -aAXv --exclude={&quot;/dev/*&quot;,&quot;/home/*&quot;,&quot;/var/*&quot;,&quot;/proc/*&quot;,&quot;/sys/*&quot;,&quot;/tmp/*&quot;,&quot;/run/*&quot;,&quot;/mnt/*&quot;,&quot;/media/*&quot;,&quot;/lost+found&quot;} /* /mnt/lv_device/
# umount /dev/mapper/vg_stavatron_00-lv_root</pre>
* [https://wiki.archlinux.org/index.php/Full_system_backup_with_rsync Arch Linux Wiki - Full System Backup with Rsync]
 
=== Chroot into the root ===
 
Now, we need to enter the filesystem to set it up further.
 
<pre># arch-chroot /mnt/lv_device</pre>
=== Edit <code>fstab</code> ===
 
Edit your fstab to match the new configurations. In particular, you need to add mount points for the new <code>/home</code> and <code>/var</code> logical volumes, as well as SSD optimizaiton options.
 
Edit the <code>fstab</code>:
 
<pre># nano /etc/fstab</pre>
Then, edit the entry in the fstab to reference the correct root, home, and var logical volumes. Also add some SSD optimization options, such as <code>noatime</code> and <code>discard</code>. The following is what I used:
 
<pre>/dev/mapper/vg_stavatron_00-lv_boot /boot ext4 defaults,noatime,discard 0 2
/dev/mapper/vg_stavatron_00-lv_root / ext4 defaults,noatime,discard 0 1
/dev/mapper/vg_stavatron_00-lv_home /home ext4 defaults,noatime,discard 0 2
/dev/mapper/vg_stavatron_00-lv_var /var ext4 defaults,noatime,discard 0 0</pre>
Finally, remount all partitions.
 
<pre># mount -a</pre>
<blockquote>'''Note:''' LVM logical volumes should be referenced using <code>/dev/mapper/vgname-lvname</code>, not UUIDs.
</blockquote>
=== Generate kernel and GRUB Config ===
 
We need to create a new Linux kernel with the LVM option, and regenerate GRUB.
 
First, edit your <code>/etc/mkinitcpio.conf</code> to add the <code>lvm2</code> HOOK between block and filesystems. Next, edit the following:
 
<pre># mkinitcpio -p linux</pre>
Then, edit <code>/etc/lvm/lvm.conf</code> and set <code>use_lvmetad = 0</code>. This disables the errant option.
 
Next, edit <code>/etc/default/grub</code> and add the <code>lvm2</code> hook to <code>GRUB_PRELOAD_MODULES</code>. Then regenerate grub.
 
<pre># grub-mkconfig -o /boot/grub/grub.cfg</pre>
Finally, install GRUB to the MBR of the drive.
 
<pre># grub-install /dev/sda</pre>
=== Sources ===
 
* [https://wiki.archlinux.org/index.php/LVM#Create_physical_volumes Arch Linux Wiki - LVM: Create LVM Physical Volumes]
* [https://wiki.archlinux.org/index.php/LVM#Create_volume_group Arch Linux WIki - LVM: Create Volume Group]
* [https://wiki.archlinux.org/index.php/Partitioning#Partition_scheme Partitioning]
Please note that all contributions to Bibliotheca Anonoma are considered to be released under the Creative Commons Attribution-ShareAlike (see Bibliotheca Anonoma:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)