Copy partition to a smaller partition?

Hello all,

I have a hard drive that is 40GB with a QNX partition that is about 32GB with only about 200MB used. I would like to copy the partition to a smaller hard drive. Is it possible to copy a partition to a smaller partition? (and it not destroy the file system obviously) Have not found any successful stories of this being done…

If say I were to setup the smaller drive with a 1GB QNX partition, could you possibly use the dd command to have it copy over the files to the new drive?

And if you could simply copy the files over, how would you go about setting the new drive to boot properly?

Thanks for helping a rookie learn a lil’bit!

After reading some more, would using the following work (or some variation), or would this copy the entire partition in which the partitions would need to be the same size?

cp /dev/hd0t77 /dev/hd1t77

I’m thinking there must be a way to use cp to do this… but of course when you don’t know much about something, it seems you have lots of ideas how things ‘must’ work!

Thanks again…

When you first initialize a disk, using dinit, the QNX 4 file system puts a bitmap file at the begining of the disk, which is used for file allocation. So doing a sector by sector partition copy will not work very well. You can do this temporarily, especially if you do not plan to write to the new disk. You might be able to write to such a disk for a while, but eventually you will end up writing to non-existant sectors.

Instead you need to create a smaller partition, and do a file by file copy.

The way i do it, if I have different partition sizes:

attach the new disk to your computer together with the source and boot.
Start fdisk /dev/hdX, where /dev/hdX is the new harddisk and create a partition as needed on the new disk. Put a the loader (l) on the disk and make this partition the boot-partition (b).

At this point i reboot, but i think it must be possible to mount the drive with mount -p /dev/hdX

Format the partition with dinit -h /dev/hdXt77 (be sure, it is the right one ;-) ) and mount it with mount /dev/hdXt77 /hdX .

Change to the root-directory of the original disk.

Use: cp -vLRcp -Munix * /hdX and cp -vLRcp -Munix .* /hdX

You will now also copy virtual devices to the new harddrive. If you have a ramdisk, it will be physically present on the new harddrive. Also te names of QNX-patitions are copied. If you have a drive /hd4, it will now also exist /hdX/hd4. You better delete them now on the new disk.

Now boot from the new disk. It should work, but mayby you must update some licenses. Use licinfo -a on the old disk and after booting on the new one.

Maybe the pros have something to improve. That would be interesting for me too.



Regarding the copying of licenses. If you have new style licenses in the .licenses file, they will copy fine. If you have any old style licenses in the /etc/licenses directory, they will not copy properly. To deal with this, after copying the disk, delete everything in the new /etc/licenses directory. Then execute the following:

license /etc/licenses /hdx/etc/licenses

That should take care of it.

Thanks guys! I performed the cp commands like explained it worked great! I was able to copy QNX 4.25 from a 20GB partition down to a 3GB partition. It took a long time to copy everything, but I expected it would.

A few files did not copy but it scrolled past too fast to see what the reasons were. They must not have been too important because the small drive boots up and runs just fine.

The license must have been the new style (I think 4.25 uses the new style) since I did not have to do the additional license copying.

Thanks again!

There are some “things” in the file system that don’t copy. Examples are .bitmap, and /dev/ser1. cp is pretty smart about these things, and I don’t recall any objects that it ignores and objects to. There might be something to look at with soft and/or hard links, but I don’t recall.

I’ve copied a couple hard drives with the way you guys showed me a while back, but now I’m trying to do it slightly different. I am trying to boot from a QNX Boot Floppy and copy one hard drive to another. I can get the files copied with the first part ok (cp -vLRcp -Munix * /hdX) but whenever I try the .* part, I get an error that reads ‘cannot open source file’. I can manually copy each .xxx by typing in the name and it seems to work fine, but I’m curious why I cannot use the wildcard like I could whenever I boot from the source hard drive? Is it a user permission thing?

I was going to use the QNX_drive_copy script, but I can’t seem to get it to run either when booting from a floppy. I may just need to scrap booting from a floppy to do this as it seems more of a headache than it’s worth. I thought it might be easier at first. :unamused:

I don’t get to dable with QNX much until I need too, then not use it for a year or more and forget everything I’ve learned. I have learned tons from this forum. Any assistance/ideas is greatly appreciated! Thanks!