Score:0

Creating a ramdisk with lvmvdo persistent across reboot?

tl flag

I am trying to create a persistent ramdisk with lvmvdo with the below unit file but it does not seem to work.I have not added the --type vdo option to the lvcreate command yet ( this is for RHEL9 )

[mukesh@server1 ~]$ sudo cat /etc/systemd/system/my_lvm.service 
[Unit]
Description=Create and mount LVM logical volume

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash -c 'mknod /dev/ram0 b 1 0; \
  pvcreate /dev/ram0; \
  vgcreate my_vg /dev/ram0; \
  lvcreate -n my_lv -L 100M my_vg; \
  mkfs.ext4 /dev/my_vg/my_lv; \
  mount /dev/my_vg/my_lv /mnt/ramdisk'

[Install]
WantedBy=multi-user.target

Ok i made some changes ( i am using brd kernel module instead of mknod), now ExecStart is working fine but ExecStop does not work.

[mukesh@server1 ~]$ cat /etc/systemd/system/my_lvm.service 
[Unit]
Description=Create and mount LVM logical volume

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash -c 'pvcreate /dev/ram0; \
  vgcreate my_vg /dev/ram0; \
  lvcreate -n my_lv -L 80M my_vg; \
  mkfs.ext4 /dev/my_vg/my_lv; \
  mount /dev/my_vg/my_lv /mnt/ramdisk'

ExecStop=/bin/bash -c 'umount /mnt/ramdisk; \
  lvremove -yff /dev/my_vg/my_lv; \
  vgremove -yff my_vg; \
  wipefs /dev/ram0; \
  pvremove -yff /dev/ram0'

[Install]
WantedBy=multi-user.target

Updated Errors : output of journalctl -xeu my_lvm.service

Feb 14 15:05:40 server1.example.com bash[2881]:   Logical volume my_vg/my_lv contains a filesystem in use.
Feb 14 15:05:40 server1.example.com bash[2882]:   Logical volume my_vg/my_lv contains a filesystem in use.
Feb 14 15:05:40 server1.example.com bash[2883]: DEVICE OFFSET TYPE        UUID                                   LABEL
Feb 14 15:05:40 server1.example.com bash[2883]: ram0   0x218  LVM2_member nEmZLv-x6eJ-WnQV-JIpq-zbK5-EsXA-fEhFqM
Feb 14 15:05:40 server1.example.com bash[2878]:   WARNING: PV /dev/ram0 is used by VG my_vg.
Feb 14 15:05:40 server1.example.com bash[2878]:   WARNING: Wiping physical volume label from /dev/ram0 of volume group "my_vg".
Feb 14 15:05:40 server1.example.com bash[2878]:   Can't open /dev/ram0 exclusively.  Mounted filesystem?
Feb 14 15:05:40 server1.example.com bash[2878]:   Can't open /dev/ram0 exclusively.  Mounted filesystem?
Feb 14 15:05:40 server1.example.com bash[2878]:   Error opening device /dev/ram0 for reading at 0 length 4096.
Feb 14 15:05:40 server1.example.com bash[2878]:   Cannot use /dev/ram0: device has a signature
Feb 14 15:05:40 server1.example.com systemd[1]: my_lvm.service: Control process exited, code=exited, status=5/NOTINSTALLED
Feb 14 15:05:40 server1.example.com systemd[1]: my_lvm.service: Failed with result 'exit-code'.
Feb 14 15:05:40 server1.example.com systemd[1]: Stopped Create and mount LVM logical volume.
Score:0
tl flag

This seems to fulfill my requirement, it seems to work without any issue.Unless there is a better way to do it.

[munish259272@munish259272example ~]$ cat /etc/modules-load.d/brd.conf
brd
[munish259272@munish259272example ~]$ cat /etc/modprobe.d/brd.conf 
options brd rd_nr=1 rd_size=73400320 max_part=1
[munish259272@munish259272example ~]$ lsmod | grep brd
brd                    16384  1
[munish259272@munish259272example ~]$ 

Unit file :

[Unit]
Description=Create and mount LVM logical volume

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash -c 'pvcreate /dev/ram0; \
  vgcreate my_vg /dev/ram0; \
  lvcreate --type vdo -n my_lv -l 17919 -V 700G  --config "allocation/vdo_slab_size_mb=1024" my_vg; \
  mkfs.ext4 -K /dev/my_vg/my_lv; \
  mount /dev/my_vg/my_lv /mnt/ramdisk; \
  lvmdevices -y --deldev /dev/ram0'


[Install]
WantedBy=multi-user.target
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.