Tuesday, June 12, 2012

Fedora: Restoring Accidentally Deleted Files Using YUM...

While working on a bug, I needed to install some Python libraries from RHEL. Since I didn't want to go through a long process of downloading the source RPM, building it for Fedora, installing it and its dependencies, etc. I thought I'd be slick and just install the library using the setup.py file. Then I can just delete the library when I'm done.

Yeah, that ALWAYS works, right?

So while trying to delete the installed libraries, I managed to accidentally type:

rm -rf /usr/lib

before hitting Enter by accident. I stopped it, but not before deleting directories some might consider important. So, after a brief moment considering how it's going to really be a pain in the ass to reinstall my system, I figured I'd try restoring the deleted files and directories.

Solution

I first got a list of all of the RPMs that have files in the /usr/lib directory. I had to be specific since my laptop uses 64-bit packages, so I had to limit the search to only /usr/lib and ignore /usr/lib64. So I built out the list of packages using the following command line:

for file in $(rpm -qla|grep ^/usr/lib/); do echo $(rpm -qf $file); done | uniq | sort > /root/packages.ls

This part took a VERY long time since it's examining every file in every package, looking for those that have /usr/lib/ in their filename and collecting the package name. But when it's done this file contains the list of all packages I'm interested in re-installing in order to get my laptop back in order. So I then go through and do the re-installation using:

yum reinstall $(cat /root/packages.lst | uniq)

When this finished, all of the packages in question were re-installed on my system. Granted I had a few cases where I had to remove old packages that had some conflicts (not sure how I got into such a state, but that's a different blog post). But when all was said and done, the system was back in working order.

Monday, June 11, 2012

QEMU/KVM: Unable To Restore Saved VM

Before upgrading my laptop to Fedora 17, I had saved a VM off, persisting its state and shutting it down. After my upgrade completed I was unable to restore the VM. Instead I consistently got "Error: Connection reset by peer". And there was no way to bring the VM back up again afterward.

Solution

To fix this problem, you need to remove the saved state for the VM using the following virsh command:

virsh managesave-remove [VM name]

substituting in the VM's name.

Once that was completed, the VM was able to start up again.

Details And Bug Report

Checking the logs I saw the following error:

2012-06-11 15:02:11.920+0000: starting up
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin /usr/bin/qemu-kvm -S -M pc-0.14 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name Windows7 -uuid dda2225d-0e57-8396-eff5-ad4da9d9febc -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/Windows7.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/libvirt/images/Windows7.img,if=none,id=drive-ide0-0-0,format=raw -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -drive file=/var/lib/libvirt/images/MeetManager.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=22,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:db:50:0d,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 127.0.0.1:0 -vga qxl -global qxl-vga.vram_size=67108864 -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -incoming fd:20 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
Domain id=1 is tainted: high-privileges
char device redirected to /dev/pts/11
do_spice_init: starting 0.10.1
spice_server_add_interface: SPICE_INTERFACE_QXL
red_worker_main: begin
display_channel_create: create display channel
cursor_channel_create: create cursor channel
pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

file mcoputils.cc: line 499 (static std::string Arts::MCOPUtils::mcopDirectory()): assertion failed: (home != 0)
sdl: SDL_OpenAudio failed
sdl: Reason: No available audio device
sdl: SDL_OpenAudio failed
sdl: Reason: No available audio device
audio: Failed to create voice `dac'
audio: Failed to create voice `adc'
qemu: warning: error while loading state for instance 0x0 of device '0000:00:02.0/qxl'
load of migration failed
2012-06-11 15:02:32.936+0000: shutting down

Which led at least one developer to suspect that the SPICE audio portion could not handle the migrate-to-file->upgrade->migrate-from-file scenario. I've filed this Bugzilla to get it fixed.

Ruby: Fix for "timeout.rb:60: [BUG] Segmentation fault"

After upgrading my laptop from Fedora 16 to Fedora 17, I hit a big problem while working in Ruby. Since Fedora changed from Ruby 1.8.7 to Ruby 1.9.3 I've decided to work more with RVM so that I can continue to develop across versions.

Problem

One of the tasks I'm working on requires developing native extensions. So for Ruby 1.8.7 I needed to install the various rake, rake-compiler, rspec and other gems for use under RVM. But when I tried to install them I had this error come up consistently:


mcpierce@mcpierce-laptop:ruby (Different-Runner-model) $ gem install rake
/home/mcpierce/.rvm/rubies/ruby-1.8.7-head/lib/ruby/1.8/timeout.rb:60: [BUG] Segmentation fault
ruby 1.8.7 (2012-06-10 patchlevel 368) [x86_64-linux]

Solution

I needed to reinstall Ruby 1.8.7 under RVM with the following compiler flags:

mcpierce@mcpierce-laptop:ruby (Different-Runner-model) $ CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" rvm install 1.8.7
Installing Ruby from source to: /home/mcpierce/.rvm/rubies/ruby-1.8.7-p358, this may take a while depending on your cpu(s)...

ruby-1.8.7-p358 - #fetching 
ruby-1.8.7-p358 - #extracting ruby-1.8.7-p358 to /home/mcpierce/.rvm/src/ruby-1.8.7-p358
ruby-1.8.7-p358 - #extracted to /home/mcpierce/.rvm/src/ruby-1.8.7-p358
Applying patch 'stdout-rouge-fix' (located at /home/mcpierce/.rvm/patches/ruby/1.8.7/stdout-rouge-fix.patch)
Applying patch 'no_sslv2' (located at /home/mcpierce/.rvm/patches/ruby/1.8.7/no_sslv2.diff)
ruby-1.8.7-p358 - #configuring 
ruby-1.8.7-p358 - #compiling 
ruby-1.8.7-p358 - #installing 
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.8.7-p358 ...
Installation of rubygems completed successfully.
ruby-1.8.7-p358 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.8.7-p358 - #importing default gemsets (/home/mcpierce/.rvm/gemsets/)
Install of ruby-1.8.7-p358 - #complete 
Please be aware that you just installed a ruby that requires 2 patches just to be compiled on up to date linux system.
This may have known and unaccounted for security vulnerabilities.
Please consider upgrading to Ruby 1.9.3-125 which will have all of the latest security patches.

Once I did this then install gems installs worked as expected.