1. What is it? 2. Why not one of the alternatives? 3. Requirements & Download 4. Using g4u
4.1 Preparations 4.2 Image creation 4.3 Image deployment 4.4 Copying a disk locally 4.5 Copying a partition locally 4.6 Programs available with G4U. 5. FAQs and hints on disk cloning 5.1 Supported filesystems* 5.2 Supported Operating Systems* 5.3 Supported Hardware* 5.4 A word on disk sizes 5.5 Changing compression level 5.6 List of recognized disks 5.7 Problems with images at 2GB 5.8 Can you add feature XXX? 5.9 Problems with network performance 5.10 Reducing the image size 5.11 Setting IP-number manually 5.12 Extracting the g4u kernel 5.13 Netbooting g4u via PXE 5.14 What FTP server software to use? 5.15 Non-standard applications 6. Support 6.1 Support 6.2 Reporting problems 7. Rebuilding from source 8. Links & Ressources 9. History 10. Copying, licenses & donations |
g4u
("ghost for unix") is a NetBSD-based boot-floppy or CD that allows easy
cloning of PC harddisks to deploy a common setup on a number of PCs using FTP.There are basically two functions:
Network configuration is handled via DHCP.
The harddisk is processed as an image, therefore any filesystem and
operating system can be deployed using g4u.
Cloning of local disks or partitions is also supported.
I've played with doing multicast-based deployment based on imm, but the result was so slow I decided not to persue it.
cat g4u-2.1-1.fs >/dev/diskette
/dev/fd0a
/dev/diskette
/dev/fd0
g4u-2.*.iso
ISO
file to a bootable CDROM.
G4U
g4u
does not use the filesystem information when accessing the disk,
It does NOT use the allocation tables. This means that it will transfer ALL sectors whether they are in use or NOT!g4u
compresses the output, sectors with the same data pattern take very little space.
install
, and protect it with a password like secret-g4u
.
hosts
file containing
the hostname of HDimg-store
and the FTP server's IP address. 192.168.1.3 HDimg-store
g4u
commands to reference the ftpserver as HDimg-store
which allows changing the FTP server without changing any commands run for the save.
save.sh
file containing commands simular to : disks export DISKS=`disks` parts $DISKS echo continue? read continue date date >>log export yymmdd=`date +%y%m%d` GZIP=8 uploadpart HDimg-store template-system.wd0e-$yymmdd.gz wd0e date date >>log echo "put log log-$yymmdd.txt" | ftp install@HDimg-store
g4u
on the sourcing system in order to determine them. See Image Creation
install
user can put a file by using an ftp client locally on the ftp server. g4u
. -n
tells ftp to ignore .netrc
autologin. ftp -n
open 127.0.0.1
user install secret-g4u
bin
put hosts
put save.sh
ls
bye
If you have a permission problem check the FTP server's /etc/shells
or what ever access control is implemented.
If it is necessary to use different user-account, g4u
utilities accept: login@server on the command line.
keyin:
For the second IDE disk, use :
The image will be compressed with gzip,
so it is recommended to use the
To use a different account name use
No filesystems were mounted or modified.
4.3 Image deployment
For account name other than
4.4 Copying a disk locallyG4U
on the "sourcing" system
Verify that there is a DHCP server that assigns IP addresses
and other information ( netmask, default gateway, name server) needed to access the FTP server.
ifconfig -a
expect something like:
rtk0: flags=8843>UP,BROADCAST,RUNNING,SIMPLEX*,MULTICAST> mtu 1500
address: 00:50:fc:c0:33:a8
media: Ethernet autoselect (none)
status: active
inet 192.168.0.3 netmask 0xffffff00 broadcast 192.168.0.255
This is the important information
lo0: flags=8008>LOOPBACK,MULTICAST> mtu 33192
ipconfig /all
expect:
- or - Host Name . . . . . : sourcehost
...
Ethernet adapter Local Area Connection:
...
...
IP Address. . . . . :
This is the
important
information
192.168.0.4
Subnet Mask . . . . :
255.255.255.0
Default Gateway . . :
192.168.0.1
DHCP Server . . . . :
192.168.0.1
g4u
CD or boot-floppy on the "sourcing" system.
Observe the linux kernel boot and the devices found .
NetBSD/i386 ustarfs Primary Bootstrap
<< NetBSD/i386 BIOS Boot, Revision 3.2
<< Memory: 639/187328 k
Press return to boot now, any other key for boot menu
booting fd0a:netbsd - starting in 0
isa0 at pcib0
...more boot messages...
wskbd0 at ...
...
Running MAKEDEV all ...
Next the DHCP request:
...DHCP messages...
Finally you'll get a
description of possible commands, and
the shell prompt
g4u>
ftp install@
ftpserver.IPaddress*
get hosts /etc/hosts
get save.sh
quit
disks
command.
On a IDE based PC they will be:
wd0
PrimaryIDE.master wd1
PrimaryIDE.slave
wd2
SecondaryIDE.master wd3
SecondaryIDE.slave
(for minimum compression)*
to transfer the first harddisk to the FTP server keyin: (if you make a typo use ^u to erase the line, ^H to backspace )
uploaddisk
HDimg-store
source-system.wd0.051231.gz
wd0
wd1
.
For SCSI use: s
d0 .
.gz
filename suffix for the filename to be created on the FTP server.
user-account@HDimg-store
.
- or -
where
parts disk
disk
is one of the disks printed by disks
.
(ie: wd0
, wd1
, sd0
).
Partitions are defined with letters starting from a
.
These are BSD-partitions, which have little in common with DOS MBR partitions.
Yes it is confusing.
Examples of partition names: wd0e
or sd0f
chmod a+x save.sh
save.sh
Defaults:GZIP=1
wd0d
install
GZIP=9
8 may be much better
220 ftp server here
331 Password required
230 user logged in
Remote system is ....
200 Type set to I.
remote: filename
227 entering Passive mode (nnn,nnn,nnn,nnn,nnn)
125 Data connection already open; transfer starting.
nnnMB* mm.mm MB/s*
eventually a summry will be displayed
nnnnnn+0 records out
090988808908908098 bytes transfered in ssss. secs (09890809bytes/sec)
0+783738 records in
0+783738 records out
090988808908908098 bytes transfered in ssss. secs (09890809bytes/sec)
226 transfer complete.
9999999999 bytes send in mm:ss (1.8 KB/s)
221 A vert er zain
nnnMB mm.mm MB/s
install
account now has the image file.
g4u
CD or floppy on the TARGET system to the shell prompt.
Keyin:
This will log
into the FTP server's slurpdisk your.ftp.server.com filename.gz
. install
account,
retrieve the image, uncompress it and write it back to /dev/wd0
.
install
prefix the server's address with account@
- or -
Keyin:
Note that the partition information is on the TARGET MBR, which MUST be
the same as before image creation.
, check the start sector and size values
given by parts. slurppart your.ftp.server.comIP filename.gz wd0e
For an image that includes the MBR, do a full
backup with "uploaddisk".
If you just want to copy one local disk to another local disk with
no network & server involved, the
copydisk
command is
what you want.
For example to copy the first IDE disk to the second IDE disk, use
copydisk wd0 wd1
for SCSI disks use copydisk sd0 sd1
.
A list of disks as found during system startup can be found by using the disks command.
4.5 Copying a partition locally
uploadpart
and slurppart
do, just
without the network and FTP in between), this can be done with the
copypart
command. It takes two partition names as arguments, and
copies the contents of one partition to the other.
As an example to copy first local partition wd0e
to the second one wd0f
, run:
copypart wd0e wd0f
wd0d
, w1e
, sd1f
. Be aware that the partitions to copy should have identical size (down to the sector), else bad things will happen. When copying a 'big' partition into a 'small' one, g4u won't thrash the data behind the 'small' partition, but of course the copy is not complete either. Take special note that that case could happen when you restore a copy made that way, and which went fine when you first copied your small working partition to your big backup partition!
4.6 Programs available after booting g4u.
In order to keep the size of g4u
to a minimun ONLY these programs are included:
cat, chmod, date, pwd, rm, sh
disklabel, init, mknod,
mount, mount_ffs, mount_cd9660, mount_mfs, mount_kernfs
mbrlabel, parts, newfs
route, dhclient, ifconfig
less, sed, more, umount
dd, ftp, gzip, gunzip, sleep, progress
reboot, halt, sync
not available: ping, traceroute,vi, df
(use parts), mkdir, cut
# functions for use from the shell prompt.
dmesg() { ( echo "dmesg: scroll down by pressing RETURN or SPACE!" ; cat /kern/msgbuf ) | more}
disks() { cat /kern/msgbuf | grep "^[swl]d[0-9]" }
grep() sed -n "/$1/p"
ls() echo *
help() cat .usage
For the curious, I've added a few screenshots:
5.1 Supported filesystems
5.2 Supported Operating Systems
By moving the harddisks to a PC, g4u can even be used to deploy operating systems for non-PC based SCSI machines running HP-UX, Irix, Solaris, AIX etc.
5.3 Supported Hardware
If you're unsure if your hardware is supported, simply boot g4u and see if your network card gets listed by "ifconfig -a" and if your disks get listed by the "disks" command. If not, adding relevant parts of "dmesg" output (from g4u; press space bar to scroll down) is required for analysis if you ask for help. See "Reporting problems" for more information.
5.4 A word on disk sizes
If you cannot avoid preparing an image on a big disk that'll get deployed to a small disk later, make sure the "extra" space is not occupied by a active partition or filesystem, else data loss is very likely to occur!
If you intend to deploy a "small" image to a "big" disk, the extra space that's not covered by g4u can be used for creating a partition and a filesystem. You will have to do that on your own, e.g. using your operating systems' post installation steps.
5.5 Changing compression level
gzip 9
. This saves as much disk space as possible, but also takes a
long time because of the CPU requirments at this level.GZIP
environment variable:
GZIP=8 uploaddisk your.ftp.server.com filename.gz wd0You can change compression levels between 1 (fast, little compression) and 9 (slow, maximum compression). Of course you can specify all the usual options to
uploaddisk
.
Why NOT always use the highest compression?
Depending on the data, sourcing CPU performance and network activity,
different compressions will transfer faster. Many CPUs cannot run GZIP 9
fast enough to keep the network active. This results in a cycle of CPU busy - network idle, burst of network activity, then CPU busy - network idle...
Reducing the compression will increase the network activity but the CPU will dispatch packets more frequently resulting in a reduction of the total time.
Using GZIP 1
, packets may be dispatched so fast that they interfere with other network traffic ( remember this is going to take a long time).This will also cause the file on the "storage" system to be as large as the partition (or disk) on the "sourcing system"
Some users have reported a dramatic reduction in total time using gzip 8
without significant increase in the size of the resulting image.
You will need to tune the compression to your configuration and needs.
5.6 List of recognized disks
# disks wd0 at pciide0 channel 0 drive 0:The above example shows a 6GB IDE harddisk.wd0: drive supports 16-sector pio transfers, lba addressing wd0: 6149 MB, 13328 cyl, 15 head, 63 sec, 512 bytes/sect x 12594960 sectors wd0: 32-bit data port wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 2 wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 2 (using DMA data transfers)
5.7 Problems with images greater than 2GB
So far, whatever FTP server comes with NetBSD, Solaris and Windows 2000 has been used without problems.
5.8 Can you add feature XXX?
After moving to a multi-floppy set for g4u, some of these features may be added in the future, while others (X...) are not likely. Stay tuned!
5.9 Problems with network performance
5.00 MB/s
on a
100BaseT Ethernet switch) even with a small compression level or
a fast CPU and the harddisk is idle means the network
configuration needs adjustment. Forcing 100BaseTX/Full-duplex:
ifconfig -a fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> MTU 1500 address: ..:..:..:..:.. media: Ethernet autoselect (100baseTX full-duplex) status: active inet 192.168.0.3 netmask 0xffffff00 broadcast 192.168.0.255 lo0: flags=8008Using autonegotiation (default):mtu 33192 ifconfig eee0 media 100BaseTX mediaopt Full-duplex dfxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> MTU 1500 address: ..:..:..:..:.. media: Ethernet 100baseTX full-duplex status: active inet 192.168.0.3 netmask 0xffffff00 broadcast 192.168.0.255
ifconfig fxp0 media auto ifconfig -a fxp0: flags=[...] media: Ethernet autoselect (100baseTX)
For more information, please see the ifconfig(8) manpage as well as the Auto-Negotiation Valid Configuration Table featuring "Why Can't the Speed and Duplex Be Hardcoded On Only One Link Partner?".
5.10 Reducing the image size
But there is an easy way to circumvent the problem: use the native operating system's understanding (and implementation) of the filesystem, and make sure it prepares empty/unused blocks in a way so they don't contain random garbage data but values which can be compressed easily by g4u, thus resulting in small image sizes.
Effectively, you just fill up the disk's unused blocks with zero-bytes. Open file for writing, stuff in 0-bytes until the disk is full, then close the file and remove it. The result is that all unused blocks were used by the file, and filled with data that g4u can then compress easily. Usually the operating system will just mark the blocks as unused, without changing the actual data content.
Using this technique on a 20GB disk that had 6GB Solaris 8/x86 and the rest Windows 2000 Workstation shrunk the image from ~6GB compressed to ~2GB compressed. You can probably imagine the effect of this on deployment time too. :)
To perform the filling of unused data blocks with zero-bytes, there are several ways, depending on what operating system you use on your computer, and what software you have available:
dd if=/dev/zero of=/0bits bs=20971520 # bs=20m rm /0bits
cd /d c:\ c:\win-preclone.pl c:Click here to download the win-preclone.pl perl script.
5.11 Manual IP configuration
dhclient > 0 more 0
Can't bind to dhcp address: address already in use
The items that need configuring are the
After booting g4u,
ifconfig -a
ex0
, tlp0
, but not lo0
. eth0
)
ifconfig xx0 192.168.0.222 netmask 255.255.255.0
route add default 192.168.0.1
5.12 Extracting the g4u kernel
% ( cat g4u-2.1-1.fs | dd bs=512 skip=16 ; \ ? cat g4u-2.1-2.fs | dd bs=512 skip=16 \ ? ) | tar vxf - -r--r--r-- 1 feyrer netbsd 53948 Nov 3 23:08 boot -rw-rw-r-- 1 feyrer netbsd 1479905 Nov 3 23:08 netbsdNote that the kernel ("netbsd") is actually still compressed, which is fine for the NetBSD bootloader and probably GRUB, but just in case, you may want to uncompress it:
% file netbsd netbsd: gzip compressed data, was "netbsd-INSTALL_G4U", from Unix % mv netbsd netbsd.gz % gunzip netbsd.gz % ls -la netbsd -rw-rw-r-- 1 feyrer wheel 5523084 Dec 7 18:08 netbsd % file netbsd netbsd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
% ( cat g4u-2.3-1.fs | dd bs=512 skip=16 ; \ ? cat g4u-2.3-2.fs | dd bs=512 skip=16 ; \ ? cat g4u-2.3-3.fs | dd bs=512 skip=16 \ ? ) | tar vxf - -r--r--r-- 1 feyrer netbsd 53948 Nov 3 23:08 boot -rw-rw-r-- 1 feyrer netbsd 1479905 Nov 3 23:08 netbsdNote that the kernel ("netbsd") is actually still compressed, which is fine for the NetBSD bootloader and probably GRUB, but just in case, you may want to uncompress it:
% file netbsd netbsd: gzip compressed data, was "netbsd-INSTALL_G4U", from Unix % mv netbsd netbsd.gz % gunzip netbsd.gz % ls -la netbsd -rw-rw-r-- 1 feyrer wheel 5523084 Dec 7 18:08 netbsd % file netbsd netbsd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
5.13 Netbooting g4u via PXE
A writeup of the necessary steps for g4u is available in the list archives, either in french language by Jean-Christophe Guis or in an english language translation by Steve Clement.
Another writeup that documents how to configure Fedora Core 5 to act as PXE server is available from Aaron Axelsen.
5.14 What FTP server software to use?
553 Cannot send file larger than 4 gigabytesscroll by, you can assume that that line (and any others with a number at the start) originates from your FTP server, and it is thus not g4u that's buggy but your FTP server software that has a problem.
Some known working FTP server programs are:
5.15 Non-standard applications
6.1 Support
There's a "g4u" community at Orkut which I've created as a forum for g4u. As Orkut is too slow these days (Dec 2004), I won't follow discussion on Orkut a lot, and recommend using the above-mentioned mailing lists for getting timely response.
6.2 Reporting problems
To rebuild the images:
# PKG_PATH=ftp://ftp.NetBSD.org/pub/NetBSD/packages/2.0/i386/All # export PKG_PATH # pkg_add -v cdrecordor, if you have pkgsrc installed:
# cd /usr/pkgsrc/sysutils/cdrecord # make install
% su # mkdir /usr/cvs # chown $USER /usr/cvs # ln -s cvs/src /usr/src # exit % cd /usr/cvs % env CVS_RSH=ssh cvs -d anoncvs@anoncvs.netbsd.org:/cvsroot co -D 20050517 src
% ./build.sh -N 1 -U release
% setenv T /usr/src/obj.i386/tooldir.NetBSD-2.0-i386/bin
% cd /usr/src % tar plzvxf .../g4u-2.1.tgz
% cd /usr/src/sys/dev/ata % patch <wd.c.patch-g4u % cd /usr/src/sys/dev/scsipi % patch <sd.c.patch-g4u % cd /usr/src/sys/kern % patch <subr_prf.c.patch-g4u
% cd /usr/src/distrib/i386/floppies/g4u % $T/nbmake-i386
% pwd /usr/cvs/src/distrib/i386/floppies/g4u % ls -l g4u.* -rw-rw-r-- 1 feyrer netbsd 3309568 Nov 3 23:09 g4u.iso -rw-rw-r-- 1 feyrer netbsd 1474560 Nov 3 23:08 g4u1.fs -rw-rw-r-- 1 feyrer netbsd 1474560 Nov 3 23:08 g4u2.fs
g4u is distributed under the standard BSD license:
(c) Copyright 1999-2005 Hubert Feyrer <hubert@feyrer.de>