Recover Fedora21 after Removing swap LVM Partition

"God" help you if you make the mistake, as I did today on a newly-installed Fedora21 system, to delete an LVM swap partition without taking the proper precautions before rebooting. If you are in this position, or have been in the past, you've come face to face with the dracut rescue shell and its limited set of "shell" commands. While the rescue shell offers some potentially useful functions (commands), I could not successfully use it to implement any of the advised steps from manual pages and internet forums I came across when searching for a solution to this problem.
The Fedora Wiki page on "How to debug Dracut problems" suggested activating the root and any other logical volumes by executing 
# lvm vgscan
# lvm vgchange -ay
"With the root volume available, you may continue booting the system by exiting the dracut shell"
exit
Though, in fairness, that resolution was dealing with unlocking an encrypted root volume with an additional step that didn't apply to my unencrypted volumes; nonetheless, there are no other steps suggested to even recreate the initramfs image with the generic command
dracut -f /boot/initramfs-$(uname -r).img $(uname -r)
from within the dracut shell. Needless to say, I wasn't able to figure out how to get that accomplished as there is no "dracut" command in the "dracut" shell!
Next, a thread post on fedoraforum.org advised
anytime you change any of the system filesystems in /etc/fstab (/boot, swap /, etc...), then you need to rebuild the initramfs with dracut. Some of the others, it may give an error and kick you out to to emergency mode if your /etc/fstab is wrong (or has been changed), but it shouldn't prevent your initramfs from loading and booting your system.
Alas, at least now I knew what I needed to do; namely, get to a bash shell and recreate the initramfs image. If you've seen my previous post on "how to reset root password in rhel7, you'll remember the kernel parameters needed to get to a bash shell. Edit the grub2 menu entry and append the following to the end of the kernel line:
rw init=/bin/bash selinux=0
Once in the shell-session, you'll notice that the boot directory is empty. Afterall, we still have to mount the separate boot partition to the local filesystem.
bash-4.3# mount /dev/sda1 /boot
Create a backup of the current initramfs image and generate a new one.
bash-4.3# dracut -f /boot/initramfs-3.17.7-300.fc21.i686.img 3.17.7-300.fc21.i686

Next, edit the default grub file /etc/default/grub and edit the line that starts with GRUB_CMDLINE_LINUX:

bash-4.3# vi /etc/default/grub

Remove the reference to the swap volume, turning this
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora_localhost/swap rd.lvm.lv=fedora_localhost/root rhgb quiet
to something like this
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora_localhost/root rhgb quiet
Now, we're ready to update the grub configuration file
bash-4.3# grub2-mkconfig -o /boot/grub2/grub.cfg
To reboot, you may have to do give the "-f" option
bash-4.3# /sbin/reboot -f
Save yourself some trouble and do all of the steps above to recreate the initramfs image and update the grub configuration before rebooting!

Popular posts from this blog

Password Policy in RHEL 7

Centos 7 pulseaudio

wpa_supplicant and wifi in RHEL 7