PROBLEM:
I currently have a 4GB disk with a single primary FAT32 partition that has Windows 98SE installed. The disk is almost full and I want to move the partition over to a larger 8GB disk.
QUESTION:
Using dd
, how can I successfully clone the original 4GB disk to a larger 8GB disk and the Windows OS still be bootable?
SCOPE:
For the purposes of the wider audience, it should be irrelevant whether I am using CompactFlash cards as hard disks for the purpose of this test. I see no reason why it is not suitable to substitute my use of CompactFlash cards with traditional IDE/SATA hard disks for users who have a similar question.
CONFIGURATION:
Instead of standard IDE/SATA hard disks, I use Transcend CompactFlash (CF) cards with an IDE CF adapter as the primary hard disks in my old hardware systems to run MS-DOS or Windows 95/98SE. The test system uses a IDE to CF adapter that treats the CompactFlash card as a conventional local hard disk.
I am using a Linux laptop with a USB CompactFlash reader to read/write the images from/to the CF.
For the purposes of my tests, the disks are identified in Linux as the following:
/dev/sda
Transcend 4GB CompactFlash 133x
/dev/sdb
Transcend 8GB CompactFlash 133x
In order to save reading time for those who do not wish to see what I have attempted, and know the perfect answer, please ignore the remaining text. For those who wish to see what I have attempted so far, please read further:
ATTEMPTS:
- dd 4GB disk to 8GB disk
- dd 4GB partition to 4G partition on 8GB disk
- clonezilla 4GB -> img -> 8GB
Installing Windows to the 8GB disk
4a. Restoring the 4GB partition to the 8GB disk
4b. Restoring the 4GB partition to the 8GB disk then the 8GB MBR
NOTE: After each unsuccessful attempt (except 4a), to wipe the target disk clean, I deleted the partition(s) using GParted and created a new partition table to wipe the existing: Device -> Create Partition Table -> msdos -> Apply
1. dd 4GB disk to 8GB disk
My first attempt was to clone the whole disk using dd
:
sudo dd if=/dev/sda of=win98se.img bs=4M; sync
then restore the disk image to the 8GB disk:
sudo dd if=win98se.img of=/dev/sdb bs=4M; sync
This didn't work. When starting the system, I see the error: "Invalid system disk. Replace the disk, and then press any key".
2. dd 4GB partition to 4G partition on 8GB disk
I cloned the partition from the 4GB disk instead of the whole disk:
sudo dd if=/dev/sda1 of=win98se_part.img bs=4M; sync
I then restored this 4GB partition to the 8GB disk:
sudo dd if=win98se_part.img of=/dev/sdb1 bs=4M; sync
I noticed this wouldn't start the operating system because there was no bootloader in the 8GB disk's MBR that knows how to boot Windows from the partition that I've just copied across.
In GParted, the partition layout looks correct but it won't boot because the necessary boot code isn't there:
3. clonezilla 4GB -> img -> 8GB
This test was done solely on the target system. I booted clonezilla live from a CD and saved the 4GB disk image to secondary storage (USB flash drive) using the device-image
option and savedisk
route. I then restored this image to the 8GB disk using the restoredisk
route. However, I got the same error as in attempt #1.
4. Installing Windows to the 8GB disk
To confirm the 8GB disk was capable of booting Windows, I installed Windows 98SE from scratch (i.e. an installation CD) onto the 8GB disk. Once the installation was complete, and the OS could boot, I imaged the disk:
sudo dd if=/dev/sdb of=win98se_8gb.img bs=4M; sync
I also took a separate copy of the MBR:
sudo dd if=/dev/sdb of=~/tmp/transcend_8gb.mbr bs=512 count=1
4a. Restoring the 4GB partition to the 8GB disk
The 8GB disk now had a bootable MBR and partition that could boot (a basic and empty) Windows installation. Using dd
, I copied the partition from the 4GB disk (as done in attempt #2) over the existing 8GB partition. This allowed me to boot into Windows and contained the data and configuration from the 4GB partition. However, this approach had created an 8GB partition that was only recognised as the original 4GB partition size in Windows. In GParted, it looked like this:
Shrinking and re-growing the partition with GParted did not solve the issue and Windows continued to see it as a 4GB disk.
4b. Restoring the 4GB partition to the 8GB disk then the 8GB MBR
From a clean disk, I used dd
to copy the 4GB partition to the 8GB disk:
sudo dd if=win98se_part.img of=/dev/sdb1 bs=4M; sync
then copy the MBR (from the Windows 98 installation image) back to the 8GB card:
sudo dd if=transcend_8gb.mbr of=/dev/sdb
This results in the same as attempt #4a. Windows boots but the 4GB partition is now an 8GB partition but only recognised as 4GB (same screenshot as in attempt #4a).
I also attempted the same by copying across only the bootcode (the first 446 bytes of the MBR):
sudo dd if=transcend_8gb.mbr of=/dev/sdb bs=446 count=1
But that did not work because when trying to dd
the partition to the target disk, it wasn't visible.
I've now spent 6 days on this trying different approaches in a different order (dd
MBR then partition and vice versa) but I'm not having any success.
READINGS:
https://unix.stackexchange.com/questions/111895/copy-mbr-and-boot-partition-to-a-smaller-disk
How to perform system migration to a smaller drive using the unix/linux tool dd?
https://www.howtoforge.com/tutorial/linux-dd-command-clone-disk-practical-example/