Article View: comp.os.linux.setup
Article #202Re: Writing fat16 partition from image file
From: Rod Smith
Date: Tue, 04 Aug 1998 00:00
Date: Tue, 04 Aug 1998 00:00
108 lines
5924 bytes
5924 bytes
[Posted and mailed] In article <6q5uq5$338$1@bunyip.cc.uq.edu.au>, "Darren Mackay" <dcmackay@tech-center.com> writes: Note: In the below, I use /dev/sda1 as an example only; any other partition designation would work as well, if that's the source/target. > Is is possible to this in linux? > > 1. Create an image file of a fat16 partition. If you mean, create a big empty file (say, via "dd if=/dev/zero of=foo.img bs=x count=y") and then use mkdosfs to create a FAT filesystem on it, I don't know. If you mean, do something like "dd if=/dev/sda1 of=foo.img" on an EXISTING FAT partition, then the answer is a definite "yes." I've done this before and successfully restored it, both with FAT-16 and NTFS partitions (not FAT-32 that I can recall, but I don't see why it wouldn't work). > 2. Can the image file be written directly to empty drive space How empty is empty? If you mean you've got the partition set up but it's got no data on it, then yes. In my example above, you'd just reverse the process -- "dd if=foo.img of=/dev/sda1". If you mean that the entire drive is empty, you'd first need to create an appropriate partition. Also, be aware that any change in the partition size, disk geometry, etc., could ruin the results. More on this later. > 3. How can I set the active partition using a script I don't know, but see below. > This will be used hopefully for automated cloning of DOS/Win, > Win95 and Win98 workstations (workstations using dhcp clients, > same hardware config and computer name has to be manually set), > also, I would like a quick method for getting machine back to > running after users stuff around with their computer, etc... If you're building a bunch of standardized PCs with identical hard drives, using a partition image might make sense. In fact, if the hard drives are absolutely identical, it might make sense to forget about an image of the PARTITION, and do an image of the ENTIRE DRIVE -- e.g., "dd if=/dev/sda of=foo.img" (note /dev/sda, not /dev/sda1). This will have the advantage of preserving the active partition information and obviating the need to muck with fdisk at all. If the disk geometries aren't identical, however, there's a good chance that your restored partition won't be bootable, or even useable. This is especially the case if you do the whole-drive method. If you just do the partition, you'll have to be very careful that the target partition is at least as large as the original. If it's smaller, dd will simply not restore the whole thing, and it might work for a while, but the FAT will indicate that the partition is bigger than it is, so as soon as an attempt is made to write to a part of the drive that's past the partition's ACTUAL end, Bad Things will happen. If the source partition is smaller than the target, my experience indicates that it will work but might confuse disk utilities like Partition Magic or Norton Utilities. One more flexible approach would be to use tar to back up the individual files. E.g.: mount -t vfat /dev/sda1 /mnt/dos tar cvf foo.tar /mnt/dos umount /mnt/dos Then to restore on another physical disk (I'm assuming the disks are physically swapped, and that the new one has been partitioned): mkdosfs /dev/sda1 mount -t vfat /dev/sda1 /mnt/dos cd / tar xvf foo.tar umount /mnt/dos (Of course, you might want or need more parameters on various of these commands, to specify creating a FAT-32 filesystem, to gzip the tar file, etc. You could also do a "FORMAT C:" on the drive from DOS instead of using mkdosfs.) I've also done this many times. It works quite well, even with FAT-32 partitions (assuming you've got appropriate support in your kernel), with a few caveats. Specifically, you lose certain DOS file attributes, like the system, hidden, and archive bits. Previously hidden files may then re-appear after restoration. Filename case may get changed in some cases; namely, if the original partition has an all-lowercase 8.3 name that's stored as all-lowercase via the special VFAT entries, it'll be restored without the VFAT extensions, leading to a capitalized or all-uppercase entry in programs, depending upon how they handle it. I've heard that this approach may not handle filenames with certain non-ASCII characters well, which may be important in non-English-speaking countries (but perhaps this has changed with some of the additions made with FAT-32 support). You'll also need to boot a DOS/Win95/Win98 floppy and do a SYS C: to make the partition bootable, if it's supposed to be bootable. Anyhow, if your hard disks are a mish-mash of different models, this is the way to go. If they're all identical, a "dd" of the entire disk, including partition table, may be the quickest way to do things. You could always mount the image via a loopback device and use tar to copy the files over to the new disk if you've got a handful of oddball target disks, too. -- Rod Smith rodsmith@fast9.uceprotect.net http://www.users.fast.net/~rodsmith NOTE: Remove the digit and following word from my address to mail me
Technical Details
Message-ID:
<6q84ak$opr$1@news1.fast.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6q5uq5$338$1@bunyip.cc.uq.edu.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1103af,3a4b808ac28d8a36 X-Google-Attributes: gid1103af,public X-Google-Thread: f9b51,3a4b808ac28d8a36 X-Google-Attributes: gidf9b51,public X-Google-Thread: 102983,3a4b808ac28d8a36 X-Google-Attributes: gid102983,public From: rodsmith@fast9.uceprotect.net (Rod Smith) Subject: Re: Writing fat16 partition from image file Date: 1998/08/04 Message-ID: <6q84ak$opr$1@news1.fast.net> X-Deja-AN: 377970005 References: <6q5uq5$338$1@bunyip.cc.uq.edu.au> To: "Darren Mackay" <dcmackay@tech-center.com> Content-Type: text/plain; charset=us-ascii Organization: FASTNET(tm) PA/NJ/DE Internet Mime-Version: 1.0 Newsgroups: comp.os.linux.setup,comp.os.linux.misc,aus.computers.linux