我正在尝试使用 lvmvdo 和下面的单元文件创建一个持久的 ramdisk,但它似乎不起作用。我--type vdo
还没有向 lvcreate 命令添加该选项(这是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
好的,我做了一些更改(我使用brd
内核模块代替mknod
),现在 ExecStart 工作正常,但 ExecStop 不起作用。
[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
更新错误:输出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.
答案1
这似乎满足了我的要求,似乎没有任何问题。除非有更好的方法来做到这一点。
[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]
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