Raspberry Pi : Mount LVM volumes

I wanna use Raspberry Pi as File server, Media server, Cache server and etc. So I separated /var, /opt, /home directories to LVM volumes as following steps.

root@raspberrypi:/$ df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/root                         15G  1.6G   12G  12% /
/dev/mmcblk0p1                    44M   23M   22M  51% /boot
/dev/mapper/VolGroup00-lvolvar    20G  592M   19G   4% /var
/dev/mapper/VolGroup00-lvolopt    20G   84M   19G   1% /opt
/dev/mapper/VolGroup00-lvolhome   49G   53M   47G   1% /home
/dev/mapper/VolGroup00-lvoldata 1007G   72M  961G   1% /data

1.Create LVM volumes by these steps.

2.Mount LVM volumes from Pi and move data.

root@raspberrypi:/$ apt-get install lvm2
root@raspberrypi:/$ vgscan # find volume groups
root@raspberrypi:/$ vgchange -ay # activate logical volumes
root@raspberrypi:/$ mount /dev/VolGroup00/lvolvar /mnt
root@raspberrypi:/$ swapoff -a  # to move swapfile /var/swap, swapoff temporarily
root@raspberrypi:/$ mv /var/* /mnt/
root@raspberrypi:/$ umount /mnt
root@raspberrypi:/$ mount /dev/VolGroup00/lvolvar /var
root@raspberrypi:/$ swapon -a 
#  move data from other directories as well

3.Update /etc/fstab

/dev/mapper/VolGroup00-lvolvar /var ext4 defaults 0 1
/dev/mapper/VolGroup00-lvolopt /opt ext4 defaults 0 1
/dev/mapper/VolGroup00-lvolhome /home ext4 defaults 0 1
/dev/mapper/VolGroup00-lvoldata /data ext4 defaults 0 1

4.Update initramfs for mount LVM on booting

root@raspberrypi:/$ update-initramfs -u # update existing initramfs

Without step 4, init can’t find LVM volumes on booting and some init processes fail. Besides, if /usr is also separated and failed to mount then kernel panic occurred and it never boot.

Leave a Reply

Your email address will not be published. Required fields are marked *