Yesterday I decided to install Windows 7 natively, aiming for a dual-boot between Fedora 11 & Win 7. Obviously I was aware that windows installers always wipe the MBR with its own boot loader, destroying any loader which plays well with others (just about any OS besides Windows), so I took backups of the MBR (both with and without the partition table, or so I thought):
dd if=/dev/hda of=/home/David/mbr_backup_nopart bs=446 count=1 (just the MBR without the partition table) I copied this file to a USB memory stick so I would be able to access it following the Win7 install I then performed the following procedure (worked perfectly) to shrink file systems, logical volumes, and finally the physical partitions:
- Boot to any linux Live CD (I used Ubuntu, if your Live CD doesn’t automatically give you sudoer, authenticate as root and drop the ’sudo’ prefixes)
- sudo lvm vgchange -a y (enable logical volume management, since my Fedora install uses LVM2)
- sudo fsck -fC /dev/vg_davesdualcore/lv_root (check the file system which I am about to resize)
- sudo resize2fs -p /dev/vg_davesdualcore/lv_root 250G (shrink the ext4 file system to use half my hard drive)
- sudo lvresize /dev/vg_davesdualcore/lv_root –size 250G (shrink the logical volume accordingly)
- sudo lvs (to report the size of your logical volumes, we are after the size of the /swap volume)
- sudo lvremove /dev/vg_davesdualcore/lv_swap (remove the swap volume so it can be recreated at the start of the newly available space)
- sudo lvcreate –size 3.8G –name lv_swap vg_davesdualcore (recreate the swap partition)
- sudo mkswap /dev/vg_davesdualcore/lv_swap (set up a linux swap area on the re-created volume)
- sudo pvs (report use and calculate the size the partition can be reduced to, ie. PSize – PFree)
- sudo pvresize /dev/sda2 –setphysicalvolumesize 254G (resize the physical volume to free up space at the end of the partition)
- sudo pvs –units s (list physical volumes with size specified in sectors, note PSize)
- sudo parted /dev/sda unit s print (print the physical disk partitions with Start, End, & Size in sectors)
- Calculate the new End sector (Start from step 13 + PSize from step 12, add at least 32MB/65536 sectors as an error margin)
- sudo parted /dev/sda rm 2 (Remove the entry from the partition table. The number is the partition number as listed from step 13)
- sudo parted /dev/sda mkpart primary 409663s 533487742s (recreate the partition with the original Start & newly calculate End from step 14)
- sudo parted /dev/sda set 2 lvm on (enable logical volume management, again the number is the partition number)
- Done! You can view your new structure with ‘parted /dev/sda print’ and/or ‘fdisk -l /dev/sda’
Following this, I inserted a Windows 7 Pro DVD & rebooted. The windows installation completed successfully and I ended up with a working windows 7. Now, as mentioned at the start of this blog post, the windows installation wiped the MBR. And this is where my nightmare begins.. I attempted to restore the MBR using the following shell command from an Ubuntu Live CD: (STORE N GO is the volume name of the memory stick I used)dd if=/media/STORE\'N\'GO/mbr_backup_nopart of=/dev/sda bs=446 count=1
And rebooted..
Much to my dismay I was greeted with the 'Invalid System Disk' message. Fedora 11 still boots following this message however (guess its some sort of BIOS fail-over mechanism), but I am so far unable to get Windows 7 booting from GRUBWhen I restored the MBR, it apparently reverted the size of my PV to use most of the disk space again. I re-ran pvresize to set this back, but no luck on the Windows 7 front yet. Looks like I might be up for a complete re-install after all
![]()