0

I want to make a NAS storage with Raspberry Pi and attached drive. I would like to create partitions on my drive with LVM, but I'm afraid, that once my sd card with os breaks, I will lose my all data, because as far, as I know, all data needed for LVM to work resides in /etc/lvm on system itself.

My question is - is there any way to restore these settings on new os, once I decide to change sd card for whatever reason?

2 Answers 2

1

It is no problem to access logical volumes from a new installed operating system, e.g. Raspberry Pi OS Buster. Just install

rpi ~$ sudo apt install lvm2

and reboot. That is all what you need to manage, access and mount your LVM volumes on the NAS.

To verify it, I have flashed Raspberry Pi OS (32-bit) Lite based on Debian Buster to a SD Card and installed lvm2. Just without booting I'm able to see the logical volumes on a USB thumb drive:

rpi ~$  sudo pvs
PV         VG       Fmt  Attr PSize   PFree
/dev/sda2  rpi.vg09 lvm2 a--  <29.47g <19.47g

rpi ~$ sudo lvs
LV          VG       Attr       LSize Pool Origin  Data%  Meta%  Move Log Cpy%Sync Convert
root.lv     rpi.vg09 owi---s--- 6.00g
rpi_base.lv rpi.vg09 swi---s--- 4.00g      root.lv

But they are not registered as block devices and cannot be found in /dev/mapper:

rpi ~$ lsblk
lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1 29.7G  0 disk
├─sda1        8:1    1  256M  0 part
└─sda2        8:2    1 29.5G  0 part
mmcblk0     179:0    0  3.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0  3.4G  0 part /

rpi ~$ ls -la /dev/mapper/
total 0
drwxr-xr-x  2 root root      60 Aug 20 11:47 .
drwxr-xr-x 18 root root    3860 Aug 20 11:47 ..
crw-------  1 root root 10, 236 Aug 20 11:47 control

After a reboot I find:

rpi ~$ lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                            8:0    1 29.7G  0 disk
├─sda1                         8:1    1  256M  0 part
└─sda2                         8:2    1 29.5G  0 part
  ├─rpi.vg09-root.lv-real    254:0    0    6G  0 lvm
  │ ├─rpi.vg09-root.lv       254:1    0    6G  0 lvm  /mnt
  │ └─rpi.vg09-rpi_base.lv   254:3    0    6G  0 lvm
  └─rpi.vg09-rpi_base.lv-cow 254:2    0    4G  0 lvm
    └─rpi.vg09-rpi_base.lv   254:3    0    6G  0 lvm
mmcblk0                      179:0    0  3.7G  0 disk
├─mmcblk0p1                  179:1    0  256M  0 part /boot
└─mmcblk0p2                  179:2    0  3.4G  0 part /

rpi ~$ ls -la /dev/mapper
total 0
drwxr-xr-x  2 root root     140 Oct 21 10:47 .
drwxr-xr-x 19 root root    3960 Oct 21 10:47 ..
crw-------  1 root root 10, 236 Oct 21 10:47 control
lrwxrwxrwx  1 root root       7 Oct 21 10:47 rpi.vg09-root.lv -> ../dm-1
lrwxrwxrwx  1 root root       7 Oct 21 10:47 rpi.vg09-root.lv-real -> ../dm-0
lrwxrwxrwx  1 root root       7 Oct 21 10:47 rpi.vg09-rpi_base.lv -> ../dm-3
lrwxrwxrwx  1 root root       7 Oct 21 10:47 rpi.vg09-rpi_base.lv-cow -> ../dm-2

rpi ~$ sudo mount /dev/mapper/rpi.vg09-root.lv /mnt
rpi ~$ findmnt /mnt
TARGET SOURCE                       FSTYPE OPTIONS
/mnt   /dev/mapper/rpi.vg09-root.lv ext4   rw,relatime

If you do not want to reboot then you are able to register the block devices direct after installation of lvm2 with:

rpi ~$ vgchange -ay
4
  • You are right, but it is worth to mentione, that we have to use command vgchange -ay in order to make vgs available in /dev/mapper again after new os installation. Commented Oct 20, 2020 at 22:04
  • @s-kaczmarek I haven't seen so far that I need vgchange on boot up with an attached device. Sometimes I have to use it on dynamically attached usb thumb drives, or when mounting LVM volumes inside an image file.
    – Ingo
    Commented Oct 20, 2020 at 22:35
  • I did experiment today in vbox. I created an additional drive, one volume group and two logical volumes. I used alpine as os. I did reinstalled alpine, installed lvm, rebooted and vg was not available in /dev/mapper. I found solution with vgchange -ay on red hat forum and it happened to work. I will try the same with ubuntu server. Commented Oct 20, 2020 at 23:01
  • 1
    @s-kaczmarek We are on Raspberry Pi here and registering the block devices in /devmapper is working with a reboot. I have updated my answer.
    – Ingo
    Commented Oct 21, 2020 at 10:18
0

I think you are looking for image-backup

image-backup:

image-backup creates a backup of a running Raspbian system to a standard 'raw' image file that can be written to an SD card or a USB device with Etcher, imageUSB, etc. It will also perform incremental updates to an existing backup image file.

Usage: image-backup [options] [pathto/imagefile for incremental backup]
-h,--help This usage description
-i,--initial pathto/filename of image file [,inital size MB [,added space for incremental MB]]
-n,--noexpand Do not expand filesystem on first run after restore
-o,--options Additional rsync options (comma separated)
-x,--extract Extract image from NOOBS (force BOOT partition to -01 / ROOT partition to -02)"

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=247568

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.