Have you ever found that you've done something that made your linux system unbootable?
I was doing a replacement of a hard drive in my laptop, as always you seem to have just a few megabytes more to store than storage. I've got an old Acer Aspire 1350 that I use at home, and was running out of disk space on it. So I went out and bought a 100Gbyte Seagate drive.
Installation was fairy easy, once I'd worked out the right way around to put the 2.5" to 3.5" drive converters so I could copy the data between drives. One small moment of stress was some smoke coming from the drive! But lucky it was just the shielding on the outside of the drive touching on the converter. A little bending with needle nose pliers had that solved.
I did have a Windows XP partition to copy and my Fedora installation to move as well ( details of the process coming soon ). But it all went without a hitch, except for a couple of self inflicted issues.
While I was doing the move I thought that it would be a good time to change the names of the Logical Volume Group and Logical Volumes so that they had a nicer naming convention than the default installs...LogVol01, LogVol02 etc are usable but not so nice.
# lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVolHome VolGroup01 -wi-ao 32.00G LogVolRoot VolGroup01 -wi-ao 15.00G LogVolSwap00 VolGroup01 -wi-ao 2.50G LogVolVmware VolGroup01 -wi-ao 10.00G # vgs VG #PV #LV #SN Attr VSize VFree VolGroup01 1 4 0 wz--n- 75.48G 15.98G
Creating the Volume Group and Logical Volumes on the new drive was simple enough and doing a transfer between the drives was simple enough, reinstalling grub to get the boot sector right was easy too.
Trouble started with the first real boot...the system wouldn't boot.
Hmm looks like the rename of the Volume Group and Logical Volumes are the trouble, so I'll do a quick edit to the startup initrd image to fix it.
First we'll get the current one from the /etc/grub/menu.lst file
cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,1)
# kernel /vmlinuz-version ro root=/dev/VolGroup01/LogVolRoot
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,1)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.23.9-85.fc8)
root (hd0,1)
kernel /vmlinuz-2.6.23.9-85.fc8 ro root=/dev/VolGroup01/LogVolRoot rhgb quiet
initrd /initrd-2.6.23.9-85.fc8.img
title Fedora (2.6.23.8-63.fc8)
root (hd0,1)
kernel /vmlinuz-2.6.23.8-63.fc8 ro root=/dev/VolGroup01/LogVolRoot rhgb quiet
initrd /initrd-2.6.23.8-63.fc8.img
title Other
rootnoverify (hd0,0)
chainloader +1
The image we want is initrd-2.6.23.9-85.fc8.img.
Note it would be a good idea to make a backup copy of this in case we cause any trouble.
cp /boot/initrd-2.6.23.9-85.fc8.img /boot/initrd-2.6.23.9-85.fc8.img.bak
We'll now make a directory to unpack it into and edit it to work ( hopefully! )
mkdir -p /boot/init cd /boot/init zcat /boot/initrd-2.6.23.8-63.fc8.img | cpio -i 16983 blocks
Now lets see what we've got from the image
[root@valhala init]# ls -l total 21 drwx------ 2 root root 1024 2008-01-22 02:23 bin drwx------ 3 root root 1024 2008-01-22 02:23 dev drwx------ 4 root root 1024 2008-01-22 02:23 etc -rwx------ 1 root root 2508 2008-01-22 02:23 init drwx------ 4 root root 1024 2008-01-22 02:23 lib drwx------ 2 root root 1024 2008-01-22 02:23 proc lrwxrwxrwx 1 root root 3 2008-01-22 02:23 sbin -> bin drwx------ 2 root root 1024 2008-01-22 02:23 sys drwx------ 2 root root 1024 2008-01-22 02:23 sysroot drwx------ 3 root root 1024 2008-01-22 02:23 usr
The init script is what we'll need to update, we want to change the Volume Group and Root Logical Volume to fix the boot error.
# cat init #!/bin/nash mount -t proc /proc /proc setquiet echo Mounting proc filesystem echo Mounting sysfs filesystem mount -t sysfs /sys /sys echo Creating /dev mount -o mode=0755 -t tmpfs /dev /dev mkdir /dev/pts mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts mkdir /dev/shm mkdir /dev/mapper echo Creating initial device nodes mknod /dev/null c 1 3 mknod /dev/zero c 1 5 mknod /dev/systty c 4 0 mknod /dev/tty c 5 0 mknod /dev/console c 5 1 mknod /dev/ptmx c 5 2 mknod /dev/rtc c 10 135 mknod /dev/tty0 c 4 0 mknod /dev/tty1 c 4 1 mknod /dev/tty2 c 4 2 mknod /dev/tty3 c 4 3 mknod /dev/tty4 c 4 4 mknod /dev/tty5 c 4 5 mknod /dev/tty6 c 4 6 mknod /dev/tty7 c 4 7 mknod /dev/tty8 c 4 8 mknod /dev/tty9 c 4 9 mknod /dev/tty10 c 4 10 mknod /dev/tty11 c 4 11 mknod /dev/tty12 c 4 12 mknod /dev/ttyS0 c 4 64 mknod /dev/ttyS1 c 4 65 mknod /dev/ttyS2 c 4 66 mknod /dev/ttyS3 c 4 67 echo Setting up hotplug. hotplug echo Creating block device nodes. mkblkdevs echo "Loading ehci-hcd.ko module" insmod /lib/ehci-hcd.ko echo "Loading ohci-hcd.ko module" insmod /lib/ohci-hcd.ko echo "Loading uhci-hcd.ko module" insmod /lib/uhci-hcd.ko mount -t usbfs /proc/bus/usb /proc/bus/usb echo "Loading mbcache.ko module" insmod /lib/mbcache.ko echo "Loading jbd.ko module" insmod /lib/jbd.ko echo "Loading ext3.ko module" insmod /lib/ext3.ko echo "Loading scsi_mod.ko module" insmod /lib/scsi_mod.ko echo "Loading sd_mod.ko module" insmod /lib/sd_mod.ko echo "Loading libata.ko module" insmod /lib/libata.ko echo "Loading pata_via.ko module" insmod /lib/pata_via.ko echo Waiting for driver initialization. stabilized --hash --interval 250 /proc/scsi/scsi echo "Loading ata_generic.ko module" insmod /lib/ata_generic.ko echo "Loading dm-mod.ko module" insmod /lib/dm-mod.ko echo "Loading dm-mirror.ko module" insmod /lib/dm-mirror.ko echo "Loading dm-zero.ko module" insmod /lib/dm-zero.ko echo "Loading dm-snapshot.ko module" insmod /lib/dm-snapshot.ko echo Making device-mapper control node mkdmnod insmod /lib/scsi_wait_scan.ko rmmod scsi_wait_scan mkblkdevs echo Scanning logical volumes lvm vgscan --ignorelockingfailure echo Activating logical volumes lvm vgchange -ay --ignorelockingfailure VolGroup01 resume /dev/VolGroup01/LogVolSwap00 echo Creating root device. mkrootdev -t ext3 -o defaults,ro /dev/VolGroup01/LogVolRoot echo Mounting root filesystem. mount /sysroot echo Setting up other filesystems. setuproot echo Switching to new root and running init. switchroot echo Booting has failed. sleep -1
Now that the script has the right names in it we can pack it back up
find . -print | cpio -oc | gzip -9 > /boot/initrd-2.6.23.8-63.fc8.img
and see how we boot.
Thats much better. Yes I know that I could use mkinitrd to regenerate the initrd file but the only change that I need is to get the names into the script. Hey it's good to know what is going on inside there anyway.
Now it's on to boot up and run...
except there is one other trouble, selinux related I think. I'll detail the fix for that soon.