CentOS7.3配置DRBD后重启报/dev/centos/root swap不存在的解决办法
Hey there, let's work through this boot issue with DRBD on your CentOS 7.3 system. From what you described, the root cause is almost certainly your initramfs lacking the necessary components to handle DRBD or your modified LVM setup, which is why it drops into the dracut shell on every reboot. Let's break down the fixes step by step:
First, let's make sure your system is trying to mount the right device and your DRBD setup is correctly defined:
- Check your
/etc/fstab: Ensure you're mounting /dev/drbd0 (the DRBD resource device) instead of the underlying/dev/mapper/centos-drbdLV. The LV is DRBD's backend storage and shouldn't be directly mounted. Also, add the_netdevmount option—this tells the system to wait for network/DRBD readiness before attempting to mount:/dev/drbd0 /your/mount/point ext4 defaults,_netdev 0 0 - Verify your DRBD resource file (usually in
/etc/drbd.d/, e.g.,r0.res): Confirm thedeviceis/dev/drbd0,diskpoints to/dev/mapper/centos-drbd, and if you're running a single node test, addon-startup primary;to the host block so the node automatically claims primary status on boot:resource r0 { device /dev/drbd0; disk /dev/mapper/centos-drbd; meta-disk internal; on your-hostname { address 192.168.x.x:7789; on-startup primary; } # Add secondary node config here if applicable }
CentOS 7's default initramfs doesn't include DRBD modules out of the box, and your modified LVM setup might not be reflected in the existing initramfs either. Let's fix that:
- Ensure you have all required DRBD packages installed:
yum install drbd-utils kmod-drbd - Regenerate the initramfs to include DRBD and LVM components:
dracut -f --add drbd --add lvm /boot/initramfs-$(uname -r).img $(uname -r) - Verify the modules were added successfully:
You should see DRBD kernel modules and LVM utilities listed.lsinitrd /boot/initramfs-$(uname -r).img | grep -E '(drbd|lvm)'
Make sure the DRBD service is enabled so it initializes /dev/drbd0 before the system tries to mount it:
systemctl enable drbd.service
If you still run into timing issues, you can force the local filesystem mount target to wait for DRBD:
systemctl add-requires local-fs.target drbd.service
Before rebooting, confirm everything is in a healthy state:
- Check DRBD resource status:
You should see your resource marked asdrbdadm statusPrimary/UpToDate(for single node) orPrimary/Secondaryif you have a cluster. - Verify the DRBD device mounts correctly manually:
mount /dev/drbd0 /your/mount/point umount /dev/drbd0
If you hit the dracut shell again, pay close attention to the error messages—it will usually tell you exactly which device it can't find (either /dev/drbd0 or /dev/mapper/centos-drbd), which can narrow down if the issue is with DRBD initialization or LVM detection.
内容的提问来源于stack exchange,提问作者bakasan

