HOWTO Clone Disk Images on Linux Booted from a Network

Guilherme Tupynamba'

gtupy (at) uol.com.br

擔杮岅栿丗朏夑桋巎 -

yasufumi.haga@nifty.com

2002擭 9寧 9擔

Revision History                                                      
Revision 0.3         2002擭 9寧 24擔          Revised by: gct         
嵏撉偺彆尵傪慻傒崬傓                                                  
Revision 0.2         2002擭 9寧 23擔          Revised by: jyg         
儅僀僫乕夵掶                                                          
Revision 0.1         2002擭 9寧 9擔           Revised by: gct         
僪儔僼僩戞堦斉                                                        

杮暥彂偱偼丄Grub 僽乕僩儘乕僟乕傪梡偄偰丄 BOOTP/TFTP 偱 Linux 傪僽乕僩
偱偒傞傛偆偵偡傞曽朄偲丄 TFTP 僒乕僶乕偲偺娫偱丄僨傿僗僋傗僷乕僥傿僔儑
儞偺僀儊乕僕偺僙乕僽乛儕僗僩傾傪偱偒傞傛偆偵偡傞曽朄傪夝愢偟傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

Table of Contents
1. 朄揑崘抦帠崁
   
    1.1. 柶愑忦崁
    1.2. 挊嶌尃
    1.3. 僼傿乕僪僶僢僋
   
2. 偼偠傔偵
   
    2.1. 僨傿僗僋僀儊乕僕偺僋儘乕儞傪嶌傞棟桼
    2.2. 僱僢僩儚乕僋偐傜僽乕僩偡傞棟桼
    2.3. 僱僢僩儚乕僋僽乕僩偺奣棯
   
3. DHCP 僒乕僶乕偲 TFTP 僒乕僶乕偺愝掕
   
    3.1. DHCP 偺愝掕
    3.2. TFTP 偺愝掕
    3.3. 暿偺僒乕僶乕傪巊梡偡傞
   
4. 僽乕僩僼傽僀儖偺弨旛
   
    4.1. 僇乕僱儖
    4.2. initrd 忋偺僼傽僀儖
    4.3. initrd 偺嶌惉
   
5. Grub 傪梡偄偨僼儘僢僺乕僨傿僗僋偐傜偺僽乕僩
   
    5.1. Grub 偺儊僯儏乕僼傽僀儖
    5.2. 僱僢僩儚乕僋僒億乕僩傪偮偗偨 Grub 偺僐儞僷僀儖
    5.3. 僽乕僩僼儘僢僺乕僨傿僗僋偺嶌惉
   
6. clone 僗僋儕僾僩偺幚峴
   
    6.1. 僨傿僗僋僀儊乕僕偺曐懚偲儕僗僩傾
    6.2. fdisk 偺巊梡
   
7. 僜儕儏乕僔儑儞偺奼挘
   
    7.1. 僼傽僀儖僔僗僥儉偱偼側偔丄僼傽僀儖偺曐懚偲儕僗僩傾
    7.2. 儅僗僞乕僽乕僩儗僐乕僪偺愝掕
    7.3. 昁梫側儌僕儏乕儖偺儘乕僪
    7.4. grub.conf偱梊傔掕媊偝傟偰偄傞憖嶌
   
8. 擔杮岅斉幱帿
A. initrd 忋偺僼傽僀儖堦棗
B. Clone 僗僋儕僾僩
References

1. 朄揑崘抦帠崁

1.1. 柶愑忦崁

偙偙偱榑偠偰偄傞帠暱偵偮偄偰偼丄愢柧偟偰偄傞曽朄傪梡偄傞偵偁偨傝丄偦偺
媄弍忋偺奣擮傗僐儅儞僪傪弉抦偟偰偄傞偙偲偑慜採偵側偭偰偄傑偡丅杮暥彂偵
宖嵹偝傟偰偄傞僐儅儞僪傪幚峴偵晄埨傪姶偠偨傝丄僋儘乕儞僗僋儕僾僩傪棟夝
偟偰偄側偄応崌偼丄偙偺巜帵偼幚峴偟側偄偱壓偝偄丅

壛偊偰丄/dev/hda 偲 /dev/hda1 偺堘偄偑暘偐傜側偄応崌偼丄杮 HOWTO 偼巊梡
偟側偄偱壓偝偄丅偙傟偼丄偍偦傜偔僷乕僥傿僔儑儞偺儕僗僩傾偲丄慡僨乕僞偺
憆幐偺堘偄偵側傝傑偡丅偙偙偱榑偠偰偄傞撪梕偺岆傝偑尨場偺僄儔乕偱偁偭偰
傕丄偆傑偔峴偐側偐偭偨帠偵懳偡傞愑擟偼丄昅幰偼偄偭偝偄晧傢側偄偙偲傪妎
偊偰偍偄偰壓偝偄丅

杮暥彂偺栚揑忋丄僒乕僶乕偲僋儔僀傾儞僩偺椉曽偱丄 RedHat 7.3 僨傿僗僩儕
價儏乕僔儑儞傪巊梡偟傑偟偨丅戝偟偨堘偄偼弌側偄偲巚偄傑偡偑丄懠偺僨傿僗
僩儕價儏乕僔儑儞傗僇僗僞儉僙僢僩傾僢僾偺娐嫬偱偼丄僥僗僩偼峴側偄傑偣傫
偱偟偨丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

1.2. 挊嶌尃

挊嶌尃 (c) 2002 偼丄Guilherme Tupynamba' 偑桳偟偰偄傑偡丅

杮暥彂偺暋惢丄攝晍丄側偄偟曄峏偼丄 Free Software Foundation偑岞奐偟偰偄
傞丄僼儕乕暥彂棙梡嫋戻宊栺彂 <http://www.gnu.org/copyleft/fdl.html> 乮
GNU Free Documentation License 乯偺僶乕僕儑儞 1.1 側偄偟偼偦傟埲崀偺忦
審壓偱嫋壜偡傞丅偨偩偟丄曄峏晄壜擻晹暘偑柍偄偙偲丄昞昞巻偑柍偄偙偲丄偍
傛傃棤昞巻偑柍偄偙偲丅僋儘乕儞僗僋儕僾僩偼丄 GNU 堦斒岞廜棙梡嫋戻宊栺彂
(GPL) <http://www.gnu.org/copyleft/gpl.html> 偺忦審偱儔僀僙儞僗偝傟偰偄
傞丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

1.3. 僼傿乕僪僶僢僋

杮暥彂偵娭偡傞偛堄尒偵偼摿偵姶幱偟傑偡丅偛堄尒偼捈愙丄<gtupy (at)
uol.com.br> 埗偰偵偍婅偄偟傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

2. 偼偠傔偵

2.1. 僨傿僗僋僀儊乕僕偺僋儘乕儞傪嶌傞棟桼

僨傿僗僋僀儊乕僕偺僋儘乕儞傪嶌傞庡側棟桼偼丄朿戝側悢偺儅僔儞偵懳偡傞丄
僆儁儗乕僥傿儞僌僔僗僥儉傗婎杮揑側傾僾儕働乕僔儑儞僙僢僩偺僀儞僗僩乕儖
傪妝偵峴側偆偨傔偱偡丅昗弨偵側傞堦戜偺儅僔儞傪梡堄偟丄偦偺嵟弶偺偒傟偄
側僀儊乕僕傪曐懚偟偰偍偒丄懠偺儅僔儞偵儕僗僩傾偡傞傛偆偵偡傟偽丄楯椡傪
愡栺偟丄庤弴傪娙棯壔偡傞偙偲偵側傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

2.2. 僱僢僩儚乕僋偐傜僽乕僩偡傞棟桼

僴乕僪僨傿僗僋偐傜僽乕僩偟偰偟傑偆偲丄僀儊乕僕傪僐僺乕偡傞尒崬傒偑彮側
偔側偭偰偟傑偄傑偡丅椺傪嫇偘傟偽丄僽乕僩偟偨僆儁儗乕僥傿儞僌僔僗僥儉偑
儅僂儞僩偟偰偄傞僷乕僥傿僔儑儞偲偺娫偱丄僐僺乕傪埨慡偵峴側偆偙偲偼晄壜
擻偱偟傚偆丅傑偨丄僆儁儗乕僥傿儞僌僔僗僥儉偑 Linux 偱偼側偄応崌傕偁傝傑
偡丅偙偺応崌偼丄僆僾僔儑儞傪帺桼偵巊偭偨丄僋儘乕儞嶌惉偑偱偒側偔側傝傑
偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

2.3. 僱僢僩儚乕僋僽乕僩偺奣棯

僋儔僀傾儞僩婡偼 Grub 偱丄僼儘僢僺乕僨傿僗僋偐傜僽乕僩偟傑偡丅偦傟偐傜
Grub 偺 BOOTP 僒億乕僩傪梡偄偰丄 DHCP 僒乕僶乕偐傜 IP 傾僪儗僗傪庢摼偟
傑偡丅師偵丄僋儔僀傾儞僩婡偼 TFTP 僒乕僶乕偐傜僇乕僱儖偲 initrd 僀儊乕
僕傪庢摼偟傑偡丅 initrd 僀儊乕僕傪儊儌儕偵儅僂儞僩偟偰偟傑偊偽丄弶婜壔
僗僋儕僾僩偑摦偒丄偙偺僀儊乕僕偵奿擺偟偰偁傞僾儘僌儔儉偲僼傽僀儖傪棙梡
偟傑偡丅偙偺僗僋儕僾僩傪巊偊偽丄 TFTP 僒乕僶乕偵僽儘僢僋僨僶僀僗偺撪梕
傪曐懚偟偨傝丄 TFTP 僒乕僶乕偐傜撪梕傪僽儘僢僋僨僶僀僗偵彂偒崬傓偙偲偑
偱偒傞傛偆偵側傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

3. DHCP 僒乕僶乕偲 TFTP 僒乕僶乕偺愝掕

DHCP 僒乕僶乕偼 Grub (BOOTP) 傪僽乕僩偟丄偦偺屻偱 Linux 傪僽乕僩偡傞嵺
丄僋儔僀傾儞僩偵 IP 傾僪儗僗傪採嫙偡傞偺偵昁梫側傕偺偱偡丅 TFTP 僒乕僶
乕偼丄Linux 偺僽乕僩梡偵丄僱僢僩儚乕僋偱棙梡偱偱偒傞僽乕僩僀儊乕僕傪嶌
惉偡傞偺偵昁梫偵側傝傑偡丅僨傿僗僋僀儊乕僕偺曐懚乛儕僗僩傾傪壜擻偵偡傞
嵺偵傕丄 TFTP 僒乕僶乕偼昁梫偵側傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

3.1. DHCP 偺愝掕

DHCP 偺徻嵶偼杮暥彂偺斖醗傪墇偊傑偡丅 "Linux Networking HOWTO" 偵 DHCP
偺復偑偁傝傑偡丅

DHCP 偺愝掕偼旕忢偵娙扨偱偡丅偱傕丄懠偺恖偑娗棟偟偰偄傞僱僢僩儚乕僋偵偄
傞応崌偼丄摦嶌拞偺 DHCP 僒乕僶乕傪巊偆曽偑尗柧偱偡丅帺暘偱僱僢僩儚乕僋
傪娗棟偟偰偄傞偺側傜丄偙偺庤弴偵偟偨偑偭偰傕偐傑偄傑偣傫丅

傑偩 DHCP 傪僀儞僗僩乕儖偟偰偄側偄応崌偼丄 rpm 僷僢働乕僕偐傜僀儞僗僩乕
儖偟偰壓偝偄丅晛捠偼 Linux 偺僨傿僗僩儕價儏乕僔儑儞偺拞偵尒偮偐傝傑偡丅

# rpm -ihv dhcp-*.rpm                                                  
                                                                       

/etc/dhcpd.conf 僼傽僀儖傪曇廤偟偰丄 DHCP 僒乕價僗傪愝掕偟偰壓偝偄丅杮
暥彂拞偺愝掕偼丄僒乕僶乕偺 IP 傾僪儗僗偑 10.0.0.1 偱丄 253 戜傑偱偺僋儔
僀傾儞僩偵 IP 傾僪儗僗傪採嫙偟傑偡丅帺暘偺娐嫬偵墳偠偰丄 /etc/
dhcpd.conf 傪愝掕偟偰壓偝偄丅

#/etc/dhcpd.conf                                                       
server-identifier dhcp.clonedomain.com;                                
default-lease-time      172800;                                        
max-lease-time          604800;                                        
option domain-name      "clonedomain.com";                             
subnet 10.0.0.0 netmask 255.255.255.0 {                                
        range dynamic-bootp 10.0.0.2 10.0.0.254;                       
}                                                                      
                                                                       

dhcpd 僒乕僶乕偺僗僞乕僩

/etc/rc.d/init.d/dhcpd start.

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

3.2. TFTP 偺愝掕

TFTP 偺愝掕傕丄DHCP 偲傎偲傫偳摨偠偔傜偄娙扨偱偡丅

傑偢丄rpm 僷僢働乕僕偐傜僀儞僗僩乕儖偟傑偡丅

# rpm -ihv tftp-server-*.rpm                                           
                                                                       

偦偟偰丄僼傽僀儖傪奿擺偡傞僨傿儗僋僩儕傪嶌傝傑偡丅

# mkdir /tftpboot                                                      
# chown nobody:nobody /tftpboot                                        
                                                                       

nobody 偲偄偆偺偼丄 ftfpd 偑僼傽僀儖傪傾僋僙僗偡傞嵺偵愝掕偡傞丄僨傿僼
僅儖僩偺儐乕僓乕 ID 偵側傞偺偱丄 /tftpboot 偲偄偆僨傿儗僋僩儕偺強桳幰偼
丄 nobody 偵偟傑偡丅

/etc/xinetd.d/tftp 僼傽僀儖傪師偺傛偆偵曇廤偟傑偡丅

service tftp                                                           
{                                                                      
        socket_type     = dgram                                        
        protocol        = udp                                          
        wait            = yes                                          
        user            = root                                         
        server          = /usr/sbin/in.tftpd                           
        server_args     = -c -s /tftpboot                              
        disable         = no                                           
        per_source      = 11                                           
        cps             = 100 2                                        
}                                                                      
                                                                       

僨傿僼僅儖僩偺僼傽僀儖偐傜曄峏偡傞偺偼丄 disable = no乮僒乕價僗傪桳岠偵
偡傞乯僷儔儊乕僞偲丄僒乕僶乕偵梌偊傞堷悢 -c 偱偡丅屻幰偺堷悢傪梌偊傞偲
丄僼傽僀儖偺惗惉偑壜擻偵側傝傑偡丅偙傟偼僽乕僩僀儊乕僕傗僨傿僗僋僀儊乕
僕傪曐懚偟偨偄応崌偵昁梫偵側傝傑偡丅捠忢偺憖嶌偱偼丄TFTP 傪撉傒庢傝偺傒
偵偟偰偍偔昁梫偑偁傞偐傕抦傟傑偣傫丅

xinetd 傪嵞儘乕僪偟傑偡丅

/etc/rc.d/init.d/xinetd reload

僒乕僶乕偺僥僗僩偵偼丄tftp 僐儅儞僪偑巊偊傑偡丅偙偺僐儅儞僪偼丄 tftp
rpm 僷僢働乕僕乮僋儔僀傾儞僩梡乯傪僀儞僗僩乕儖偡傟偽棙梡偱偒傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

3.3. 暿偺僒乕僶乕傪巊梡偡傞

DHCP 偲 TFTP 偵娭偟偰偼丄暿偺僒乕僶乕傪巊梡偡傞偙偲傕偱偒傑偡丅偙傟偼摦
嶌拞偺 DHCP 僒乕僶乕傪巊梡偡傞応崌偵昁梫偵側傞偐傕偟傟傑偣傫丅 DHCP 偺
next-server 僷儔儊乕僞傪愝掕偟偰丄 TFTP 僒乕僶乕傪巜偡傛偆偵偟偨傝丄
Grub 偱 tftpserver 僐儅儞僪傪巊偆偙偲偑偱偒傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

4. 僽乕僩僼傽僀儖偺弨旛

偙傟偱僒乕僶乕偺愝掕偼偱偒傑偟偨丅師偼僋儔僀傾儞僩傪僽乕僩偝偣傞僼傽僀
儖傪弨旛偡傞昁梫偑偁傝傑偡丅偙傟偵偼擇偮偺僼傽僀儖偑昁梫偵側傝傑偡丅偦
傟偼丄僇乕僱儖偲弶婜 RAM 僨傿僗僋(initrd) 偱偡丅屻幰偼丄僇乕僱儖偑儖乕
僩僼傽僀儖僔僗僥儉偲偟偰儅僂儞僩偡傞傕偺偱偡丅杮暥彂偱偼丄杮愡偲師愡偱
奣愢偟偨庤弴偼丄僋儔僀傾儞僩婡偱嶌惉偟偨傕偺偲偟偰偄傑偡丅僨傿僗僋僀儊
乕僕偺曐懚乛儕僗僩傾偺嵺偼丄晛捠儘乕僇儖偺僴乕僪僨傿僗僋偵 Linux 傪僀儞
僗僩乕儖偡傞昁梫偼偁傝傑偣傫丅偱傕丄悢懡偔偺儅僔儞偵僨傿僗僋僀儊乕僕傪
攝抲偡傞応崌偼丄奺儅僔儞偺儌僨儖偲側傞丄堦戜偺儅僔儞偵 Linux 傪僀儞僗僩
乕儖偡傞偙偲偐傜巒傔偰壓偝偄丅 DHCP 傪巊偄丄慜愡偱愝掕偟偨偙偲傪 TFTP
僋儔僀傾儞僩偱僥僗僩偟偰壓偝偄丅摿偵巜掕偟側偄尷傝丄僐儅儞僪偼尰嵼偺僨
傿儗僋僩儕撪偱丄儐乕僓乕 root 偑 bash 僔僃儖偱幚峴偟傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

4.1. 僇乕僱儖

埑弅偝傟偨僇乕僱儖偺僼傽僀儖傪摿掕偟傑偡丅

# cd /boot                                                             
# ls vmlinuz-$(uname -r)                                               
vmlinuz-2.4.18-3                                                       
                                                                       

偙偺僶乕僕儑儞偼丄僔僗僥儉偵傛偭偰條乆偱偡丅偙偺僼傽僀儖傪 TFTP 僒乕僶
乕偵傾僢僾儘乕僪偟丄柤慜傪 vmlinuz 偵曄偊傑偡丅

# tftp 10.0.0.1                                                        
tftp> binary                                                           
tftp> put vmlinuz-2.4.18-3 vmlinuz                                     
Sent 1030147 bytes in 2.3 seconds                                      
tftp> quit                                                             
                                                                       

僇乕僱儖偺僼傽僀儖柤偼丄僴乕僪僂僃傾偑堎側偭偨傝丄僇乕僱儖偺僶乕僕儑儞
偵傛偭偰偼丄偦偺傑傑偵偟偰偍偔昁梫偑偁傞偐傕抦傟側偄偟丄暿偺柤慜偵偡傞
昁梫偑偁傞偐傕抦傟傑偣傫丅偙偙偱偼丄僇乕僱儖偲 initrd 偵娭偟偰丄摨偠柤
慜傪梡偄傑偡丅偙偆偡傟偽丄僇乕僱儖傗 initrd 僀儊乕僕傪曄峏偟偰傕丄暿偺
僽乕僩僼儘僢僺乕僨傿僗僋傪嶌惉偡傞昁梫偑側偔側傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

4.2. initrd 忋偺僼傽僀儖

師偵丄僋儔僀傾儞僩梡偵儖乕僩僼傽僀儖僔僗僥儉偺僀儊乕僕傪嶌惉偟傑偡丅偙
偺僼傽僀儖偺姰慡側儕僗僩偼丄Appendix A 偵偁傝傑偡丅

偙偺僼傽僀儖偼丄嫮椡側僔僃儖(bash)傪梡堄偡傞偨傔偺丄嵟掅尷偺愝掕偲偟偰
丄摦嶌拞偺僔僗僥儉偐傜帩偭偰偒傑偟偨丅僋儔僀傾儞僩梡偺僱僢僩儚乕僋儐乕
僥傿儕僥傿 (dhcpcd 傗 tftp)丄傗僐僺乕丒埑弅儐乕僥傿儕僥傿 (dd, gzip)丄
娗棟梡僐儅儞僪 (mknod 傗 mount, fdisk 偦傟偵 insmod) 傕偁傝傑偡丅

尰嵼偺僨傿儗僋僩儕偱丄 initrd.lst 偲偄偆柤慜偺僨傿儗僋僩儕傪嶌惉偟丄偙
傟傜偺僼傽僀儖傪偦偙偵抲偄偰壓偝偄丅帺暘偺僔僗僥儉偱偙傟傜偺僼傽僀儖偑
懚嵼偡傞偐偳偆偐傪妋偐傔傞偵偼丄師偺僐儅儞僪傪幚峴偟偰壓偝偄丅

# ls -d $(<initrd.lst) > /dev/null                                     
                                                                       

埲壓偺傛偆側僄儔乕偑弌椡偝傟傞偼偢偱偡丅

ls: /bin/clone: No such file or directory                              
ls: /bin/tftp: No such file or directory                               
ls: /lib/3c59x.o: No such file or directory                            
                                                                       

嵟弶偺僄儔乕偼丄尰嵼偺僨傿儗僋僩儕偵嶌傞偙偲偵側偭偰偄傞僗僋儕僾僩偱偡
丅擇斣栚偺僄儔乕偼丄 /bin 偱偼側偔丄 /usr/bin 僨傿儗僋僩儕偱尒偮偐偭偨 
tftp 僾儘僌儔儉偱偡丅嶰斣栚偼僱僢僩儚乕僋僀儞僞僼僃乕僗僇乕僪偺儌僕儏乕
儖乮偨傇傫帺暘偺偱偼側偄偱偟傚偆乯偱丄 /lib/modules/$(uname -r)/kernel/
drivers/net 偱尒偮偐偭偨傕偺偱偡丅

偙偺嶰偮偺僼傽僀儖偵偮偄偰偼丄埲崀偺愡偱屄暿偵偡偖榑偠傑偡丅懠偵傕柍偄
僼傽僀儖偑偁傟偽丄僀儞僗僩乕儖偺偟朰傟偲偐丄僶乕僕儑儞偺堘偄丄僨傿僗僩
儕價儏乕僔儑儞傗僴乕僪僂僃傾偺堘偄傪挷傋偰壓偝偄丅偦偟偰丄偙偺儕僗僩偼
帺暘偺僔僗僥儉偺崌偆傛偆偵挷惍偟偰壓偝偄丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

4.3. initrd 偺嶌惉

師偼僀儊乕僕傪嶌惉偡傞抜奒偱偡丅杮暥彂偱偺愝掕偩偲丄 4 儊僈僶僀僩偺戝偒
偝偑偁傟偽丄廩暘僼傽僀儖偑曐帩偱偒傑偡丅昁梫側傜僒僀僘傪戝偒偔偟偰傕偐
傑偄傑偣傫丅

# dd if=/dev/zero of=initrd bs=1024 count=4096                         
4096+0 records in                                                      
4096+0 records out                                                     
# yes | mkfs initrd                                                    
mke2fs 1.27 (8-Mar-2002)                                               
initrd is not a block special device.                                  
Proceed anyway? (y,n) Filesystem label=                                
blah blah blah...                                                      
# mkdir mnt                                                            
# mount -o loop initrd mnt/                                            
# egrep -v "clone|3c59x|tftp" initrd.lst | cpio -pdm mnt               
4876 blocks                                                            
                                                                       

偝偰丄egrep 僐儅儞僪偱丄僼傽僀儖偑嶰偮彍奜偝傟傑偟偨丅偦偙偱丄tftp 僾儘
僌儔儉傪丄 /usr/bin 偐傜僀儊乕僕僨傿儗僋僩儕偵僐僺乕偟傑偡丅

# cp -p /usr/bin/tftp mnt/bin/                                         
                                                                       

僱僢僩儚乕僋僀儞僞僼僃乕僗僇乕僪梡偵偼丄惓偟偄儌僕儏乕儖傪摿掕偟偰壓偝
偄丅偦偺僼傽僀儖傪摿掕偡傞偵偼丄 lspci 僐儅儞僪偲丄 lsmod 僐儅儞僪偺弌
椡傪梡偄傑偡丅偦偺儌僕儏乕儖偼丄 /lib/modules/$(uname -r)/kernel/
drivers/net 偵偁傝傑偡丅

    Note: 3c59x 偲偄偆柤慜傪巊偭偰偄傞偲偙傠偑偁傟偽丄偡傋偰帺暘偺働乕
    僗偵崌偭偨儌僕儏乕儖柤偵撉傒曄偊偰壓偝偄丅
   
# cp -p /lib/modules/$(uname -r)/kernel/drivers/net/3c59x.o mnt/lib/   
                                                                       

Appendix B 偵偁傞僋儘乕儞僗僋儕僾僩傪曇廤偟偰丄 Section 6 偱愢柧偟偨曄
悢傪曄峏偟傑偡丅偦偺僼傽僀儖傪幚峴壜擻側僷乕儈僢僔儑儞偵偟偰丄僀儊乕僕
僨傿儗僋僩儕偵僐僺乕偟偰壓偝偄丅

# chmod +x clone                                                       
# cp -p clone mnt/bin/                                                 
                                                                       

initrd 僀儊乕僕傪傾儞儅僂儞僩偟丄埑弅偟偰偐傜丄 TFTP 僒乕僶乕偵憲傝傑偡
丅

# umount mnt/                                                          
# gzip initrd                                                          
# tftp 10.0.0.1                                                        
tftp> binary                                                           
tftp> put initrd.gz                                                    
Sent 1155530 bytes in 2.8 seconds                                      
tftp> quit                                                             
                                                                       

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

5. Grub 傪梡偄偨僼儘僢僺乕僨傿僗僋偐傜偺僽乕僩

師偺抜奒偼丄Grub 傪梡偄偨僽乕僩僼儘僢僺乕僨傿僗僋偺嶌惉偱偡丅 Grub 偲偼
丄GRand Unified Bootloader 偺偙偲偱偡丅偙傟偼 BOOTP 偲 TFTP 偑埖偊傞偺
偱丄僱僢僩儚乕僋偐傜僽乕僩偱偒傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

5.1. Grub 偺儊僯儏乕僼傽僀儖

尰嵼偺僨傿儗僋僩儕偱丄 grub.conf 偲偄偆柤慜偱丄埲壓偺傛偆側撪梕偺僼傽僀
儖傪嶌傝傑偡丅

default=0                                                                  
timeout=1                                                                  
title Clone                                                                
        bootp                                                              
        root (nd)                                                          
        kernel /vmlinuz rw root=/dev/ram ramdisk_size=4096 init=/bin/clone 
        initrd /initrd.gz                                                  
                                                                           

嵟屻偺 4 峴偼丄僱僢僩儚乕僋偐傜僽乕僩偡傞偺偵巊偆丄 Grub 偺僐儅儞僪偱偡
丅

 丒 bootp 偼丄 DHCP 僒乕僶乕偐傜 IP 傾僪儗僗傪庢摼偡傞偺偵巊偄傑偡丅
   
 丒 root (nd) 偼丄僱僢僩儚乕僋乮TFTP 僒乕僶乕乯偺儖乕僩傪愝掕偡傞偺偵巊
    偄傑偡丅 tftpserver <tftp server> 僐儅儞僪傪巊偊偽丄偙偺僐儅儞僪偺
    慜偵丄暿偺 TFTP 僒乕僶乕傪愝掕偱偒傑偡丅
   
 丒 kernel 偼丄僇乕僱儖僼傽僀儖偲偦偺僷儔儊乕僞傪巜掕偟傑偡丅
   
     仩 rw 偼丄儖乕僩僼傽僀儖僔僗僥儉傪彂偒崬傒壜擻偵偟偰儅僂儞僩偡傞傛
        偆巜掕偟傑偡丅
       
     仩 root 偼丄乮RAM 儊儌儕撪偺乯儖乕僩僼傽僀儖僔僗僥儉傪偳偙偵儅僂儞
        僩偡傞偺偐傪巜掕偟傑偡丅
       
     仩 ramdisk_size 偼丄 RAM 僨傿僗僋偺僒僀僘傪巜掕偟傑偡丅 4096 乮k僶
        僀僩乯偑僨傿僼僅儖僩偺戝偒偝偱偡偑丄傕偭偲戝偒側僀儊乕僕偑昁梫
        側傜丄偦傟偵墳偠偰偙偺僷儔儊乕僞傪曄峏偟偰壓偝偄丅
       
     仩 init 偼丄乮init 偲 sh 偑柍偄応崌偵乯丄儐乕僓乕儌乕僪偱摦偔嵟弶
        偺僾儘僌儔儉乮偙偺応崌偼 clone 僗僋儕僾僩乯傪巜掕偟傑偡丅
       
 丒 initrd 偼丄儖乕僩僼傽僀儖僔僗僥儉偺僀儊乕僕傪曐帩偟偰偄傞僼傽僀儖傪
    巜掕偟傑偡丅
   
劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

5.2. 僱僢僩儚乕僋僒億乕僩傪偮偗偨 Grub 偺僐儞僷僀儖

Grub 傪僐儞僷僀儖偡傞応崌偼丄嵟弶偵僜乕僗偺 tar 儃乕儖傪 the Grub web
site <http://www.gnu.org/software/grub/> 偐傜僟僂儞儘乕僪偟丄揥奐偟傑偡
丅偦偟偰丄嶌惉偟偨偽偐傝偺儊僯儏乕僼傽僀儖偲丄僱僢僩儚乕僋僀儞僞僼僃乕
僗僇乕僪偺宆傪堷悢偵巜掕偟偰丄 configure 傪幚峴偟傑偡丅偦傟偐傜偄偮傕偺
偲偍傝丄make 傪幚峴偟傑偡丅

# tar xzf grub-0.92.tar.gz                                             
# cd grub-0.92                                                         
# ./configure --enable-preset-menu=../grub.conf --enable-3c90x         
# make                                                                 
                                                                       

孞傝曉偟傑偡偑丄 3c90x 偲偄偆宆傪尒偨傜丄帺暘偑巊偭偰偄傞僱僢僩儚乕僋僀
儞僞僼僃乕僗僇乕僪偺宆偵撉傒曄偊偰偔偩偝偄丅偦偺嵺丄嵟弶偵丄Grub 偑偦偺
宆傪僒億乕僩偟偰偄傞偐偳偆偐挷傋偰壓偝偄丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

5.3. 僽乕僩僼儘僢僺乕僨傿僗僋偺嶌惉

堦搙 Grub 傪僐儞僷僀儖偟偨傜丄僽乕僩僼儘僢僺乕僨傿僗僋偺僀儊乕僕偼丄
stage1/stage1 僼傽僀儖偲 stage2/stage2 僼傽僀儖傪楢寢偡傟偽偱偒傑偡丅偙
偺僼儘僢僺乕僨傿僗僋傪嶌惉偡傞偵偼丄師偺僐儅儞僪傪幚峴偟偰壓偝偄丅

# cat stage1/stage1 stage2/stage2 | dd of=/dev/fd0                     
                                                                       

偙傟偱丄僽乕僩僼儘僢僺乕僨傿僗僋偑偱偒偨偼偢偱偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

6. clone 僗僋儕僾僩偺幚峴

Appendix B偱帵偟偰偄傞丄 clone 僗僋儕僾僩偼昁恵偱偼偁傝傑偣傫丅 init=/
bin/bash 傪僇乕僱儖僷儔儊乕僞偵偟偰丄棙梡壜擻側僐儅儞僪傗僾儘僌儔儉偑幚
峴偱偒傞僔僃儖偱廔偭偰傕偐傑偄傑偣傫丅

偙偺僗僋儕僾僩傪偙偙偵昞偟偨偺偼丄惓幃側傗傝曽偺僐儅儞僪傪帵偟丄僞僀僾
儈僗偐傜旐奞偑惗偠傞壜擻惈傪尭傜偡偨傔偱偡丅 tftp_server 傗 nic_module
丄 major_a丄 family_a 偦傟偵 image_a 偲偄偭偨曄悢偼丄帺暘偺娐嫬傗傾僾儕
働乕僔儑儞偺崌傢偣偰曄峏偡傞昁梫偑偁傝傑偡丅

拲堄偟偰梸偟偄偺偼丄攝楍 major_a 偲攝楍 family_a 偼懳墳偟偰偄傞偲偄偆偙
偲偱偡丅強掕偺僼傽儈儕乕柤偵岆偭偨儊僕儍乕斣崋傪梌偊傞偲丄儐乕僓乕偵岆
夝傪彽偔偙偲偵側傝傑偡丅廳梫側僨僶僀僗乮僨傿僗僋偲僷乕僥傿僔儑儞偺慡懱
乯偺儊僕儍乕斣崋偲儅僀僫乕斣崋偼丄 /dev 僨傿儗僋僩儕偺儕僗僩偱傢偐傝傑
偡丅儊僕儍乕斣崋偲儅僀僫乕斣崋偼丄 ls -l 僐儅儞僪偺弌椡偵偁傞丄僇儞儅偱
嬫愗傜傟偨丄捠忢偺僼傽僀儖偩偲僼傽僀儖僒僀僘偑偁傞応強偵偁傝傑偡丅

# ls -l /dev/fd0 /dev/hda /dev/hda1 /dev/hdc                           
brw-rw----    1 root     disk       2,   0 Apr 11 11:25 /dev/fd0       
brw-rw----    1 root     disk       3,   0 Apr 11 11:25 /dev/hda       
brw-rw----    1 root     disk       3,   1 Apr 11 11:25 /dev/hda1      
brw-rw----    1 root     disk      22,   0 Apr 11 11:25 /dev/hdc       
                                                                       

set -e 僐儅儞僪偼丄僔僃儖偵僗僋儕僾僩傪傾儃乕僩偡傞傛偆巜帵偡傞傕偺偱丄
僛儘埲奜偺僐乕僪偑曉傞偼偢偱偡丅捠忢偺廔傝曽偺傛偆偵丄 "Kernel panic:
Attempted to kill init!" 偲偄偆儊僢僙乕僕偑偦傟偵懕偒傑偡丅偱傕丄偆傠偨
偊側偄偱両偙偺娐嫬偱偼丄偙傟偑晛捠側偺偱偡丅僐儞僺儏乕僞傪棊偲偡偩偗偱
偐傑偄傑偣傫丅僗僋儕僾僩傪廔傜偣偰偙偺尒嬯偟偄儊僢僙乕僕傪旔偗傞慜偵丄
Ctrl-Alt-Del 傪墴偟偰丄偒偪傫偲儕僽乕僩偟偰壓偝偄丅

insmod 僐儅儞僪偼丄僱僢僩儚乕僋僀儞僞僼僃乕僗儌僕儏乕儖傪儘乕僪偡傞僐儅
儞僪偱丄 dhcpcd 僐儅儞僪偼丄 DHCP 僋儔僀傾儞僩傪僗僞乕僩偝偣傞僐儅儞僪
偱偡丅 Grub 偑偦偺僽乕僩拞偵 DHCP 傪巊梡偟偨偲偄偆偙偲偲丄 Linux 偑摨偠
偙偲傪偟偨偲偄偆偙偲偑丄柍娭學側偙偲偵拲堄偟偰壓偝偄丅

偙偺僗僋儕僾僩偱偼丄奺乆孞傝曉偟傪峴側偆偨傔偵丄戝偒側儖乕僾張棟傪峴側
偭偰偄傑偡丅傑偢丄師偺嶰庬椶偺憖嶌偺拞偺偳傟傪峴側偆偐傪恥偄偰偒傑偡丅
僱僢僩儚乕僋偐傜僨僶僀僗傊偺僐僺乕丄僨僶僀僗偐傜僱僢僩儚乕僋傊偺僐僺乕
丄 fdisk 偺幚峴丅師偵丄巊梡偡傞僽儘僢僋僨僶僀僗偑偳傟偐傪恥偄偰偒傑偡丅
major_a 攝楍偼丄巊梡偱偒傞僽儘僢僋僨僶僀僗偺儊僕儍乕斣崋傪帩偭偰偄傑偡
丅傑偨丄family_a 偵偼丄僨僶僀僗僼傽儈儕乕屄乆偺柤徧偑擖偭偰偄傑偡丅偦偺
屻丄巊梡偡傞僽儘僢僋僨僶僀僗偺儅僀僫乕斣崋傪恥偄偰偒傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

6.1. 僨傿僗僋僀儊乕僕偺曐懚偲儕僗僩傾

僐僺乕憖嶌偺撪偺堦偮傪慖傇偲丄僗僋儕僾僩偼曐懚側偄偟偼儕僗僩傾偡傞僀儊
乕僕偺柤慜傪恥偄偰偒傑偡丅僀儊乕僕柤徧偼丄image_a 攝楍偺梫慺偵尷掕偝傟
偰偄傑偡丅偦偺柤慜偑懚嵼偟側偗傟偽丄僀儊乕僕偲摨偠柤慜偺丄柤慜晅偒僷僀
僾傪嶌傝傑偡丅嵟屻偵丄dd 偲 tftp 傪摨帪偵婲摦偟丄僀儊乕僕傪揮憲偟傑偡丅
偄偮傕偺 ftp 偲偼堘偄丄 tftp 偼柤慜晅偒僷僀僾傪丄偪傚偆偳晛捠偺僼傽僀儖
偺傛偆偵 put 偟偨傝 get 偟偨傝偟傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

6.2. fdisk 偺巊梡

fdisk 傪慖傇偲丄僽儘僢僋僨僶僀僗偵懳偟偰婲摦偝傟傑偡丅 fdisk 偼晛捠丄堦
偮偺僷乕僥傿僔儑儞偱偼側偔丄媡偵僨傿僗僋慡懱偵懳偟偰幚峴偝傟傑偡丅拲堄
偟偰梸偟偄偺偼丄捠忢 /dev/hda 偲屇傫偱偄傞傕偺偑丄 clone 僗僋儕僾僩偱偼
/dev/hda0 偲側傞偙偲偱偡丅偍朷傒側傜丄僗僋儕僾僩拞偵 fdisk 傪抲偄偰丄僷
乕僥傿僔儑儞惗惉傪帺摦壔偡傞偙偲傕壜擻偱偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

7. 僜儕儏乕僔儑儞偺奼挘

7.1. 僼傽僀儖僔僗僥儉偱偼側偔丄僼傽僀儖偺曐懚偲儕僗僩傾

曐懚偟偨偄偺偑僨傿僗僋僀儊乕僕慡懱偱偼側偔丄僼傽僀儖僔僗僥儉偺拞偵偁傞
僼傽僀儖偩偗側傜丄 dd 偺戙傢傝偵丄 tar 傗 cpio 偱丄帡偨傛偆側僜儕儏乕僔
儑儞偑巊偊傑偡丅僼傽僀儖僔僗僥儉傪儅僂儞僩偡傞昁梫偼偁傝傑偡丅埲壓偵帵
偡傛偆偵丄 clone 僗僋儕僾僩偵傕偭偲僐儅儞僪傪捛壛偟偰壓偝偄丅

# mkdir /mnt                                                           
# mount ${device_name} /mnt                                            
# mknod ${image} p                                                     
# tftp ${tftp_server} <<-EOT &                                         
binary                                                                 
put ${image}                                                           
EOT                                                                    
tar czf ${image}                                                       
                                                                       

or

# tftp ${tftp_server} <<-EOT &                                         
binary                                                                 
get ${image}                                                           
EOT                                                                    
tar xzf ${image}                                                       
                                                                       

initrd 僀儊乕僕偵偼丄僗僋儕僾僩偑巊偊傞傛偆偵丄 mkdir 僾儘僌儔儉偲 tar
僾儘僌儔儉傪抲偄偰偍偔昁梫偑偁傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

7.2. 儅僗僞乕僽乕僩儗僐乕僪偺愝掕

杮暥彂偺撪梕傪梡偄偰僷乕僥傿僔儑儞偺嵞曇傗僒僀僘曄峏傪峴側偭偨忬嫷偱偼
丄僨傿僗僋偑僽乕僩偣偢偵廔傞偐傕偟傟傑偣傫丅偦偺応崌偼丄乮僀儊乕僕拞偺 
grub 偵娷傑傟偰偄傞乯 Grub 偺 setup 僐儅儞僪傪幚峴偟偰壓偝偄丅偙傟偱栤
戣偑夝寛偡傞偼偢偱偡丅徻嵶偼丄 Grub 偺僪僉儏儊儞僩傪嶲徠偟偰壓偝偄丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

7.3. 昁梫側儌僕儏乕儖偺儘乕僪

僇乕僱儖偵傛偭偰偼丄 SCSI 僨僶僀僗偺傛偆側僽儘僢僋僨僶僀僗偵傾僋僙僗偡
傞偨傔偵丄梋暘側儌僕儏乕儖偑昁梫偵側傞偐傕偟傟傑偣傫丅 initrd 僀儊乕僕
偺 /lib 僨傿儗僋僩儕偵昁梫側儌僕儏乕儖傪抲偄偰丄 clone 僗僋儕僾僩偱丄懳
墳偡傞 insmod 僐儅儞僪傪幚峴偟偰壓偝偄丅摨偠偙偲偼僼傽僀儖僔僗僥儉偵傕
尵偊傑偡丅椺偊偽丄fat 僼傽僀儖僔僗僥儉偺僀儊乕僕偱偼側偔丄僼傽僀儖傪曐
懚偟偨偗傟偽丄 fat.o 偲 vfat.o 儌僕儏乕儖偑昁梫偵側傝傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

7.4. grub.conf偱梊傔掕媊偝傟偰偄傞憖嶌

Grub 偺儊僯儏乕僼傽僀儖 grub.conf 偼僇僗僞儅僀僘偟偰丄偄偔偮偐偺僐僺乕
僆僾僔儑儞傪採帵偡傞傛偆偵偟偰傕椙偄偟丄僨傿僗僋偺僷乕僥傿僔儑儞嵞嶌惉
傗丄僱僢僩儚乕僋偐傜巜掕偟偨僀儊乕僕傪庢摼偡傞傛偆側丄梊傔掕媊偟偰偍偄
偨憖嶌傪幚峴偡傞傛偆偵偟偰傕偐傑偄傑偣傫丅孞傝曉偟傑偡偑丄偙偙偱帵偝傟
偨峫偊曽傪梡偄偰摿掕偺嶌嬈偵墳梡偡傟偽丄偦偺嶌嬈偑払惉偱偒傞傛偆偵側傞
偺偱偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

8. 擔杮岅斉幱帿

峑惓偵偁偨傝丄JF 僾儘僕僃僋僩偺奆條偵偛嫤椡偄偨偩偒傑偟偨丅偙偺応傪庁傝
偰屼楃怽偟忋偘傑偡丅

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

A. initrd 忋偺僼傽僀儖堦棗

/bin/                                                                  
/bin/bash                                                              
/bin/clone                                                             
/bin/dd                                                                
/bin/gzip                                                              
/bin/mknod                                                             
/bin/mount                                                             
/bin/tftp                                                              
/dev/                                                                  
/dev/console                                                           
/dev/null                                                              
/etc/                                                                  
/etc/dhcpc/                                                            
/etc/hosts                                                             
/etc/nsswitch.conf                                                     
/etc/protocols                                                         
/etc/services                                                          
/lib/                                                                  
/lib/3c59x.o                                                           
/lib/i686/                                                             
/lib/i686/libc-2.2.5.so                                                
/lib/i686/libc.so.6                                                    
/lib/ld-2.2.5.so                                                       
/lib/ld-linux.so.2                                                     
/lib/libdl-2.2.5.so                                                    
/lib/libdl.so.2                                                        
/lib/libnss_files-2.2.5.so                                             
/lib/libnss_files.so.2                                                 
/lib/libtermcap.so.2                                                   
/lib/libtermcap.so.2.0.8                                               
/proc/                                                                 
/sbin/                                                                 
/sbin/dhcpcd                                                           
/sbin/fdisk                                                            
/sbin/insmod                                                           
/tmp/                                                                  
/var/                                                                  
/var/run/                                                              
                                                                       

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

B. Clone 僗僋儕僾僩

#!/bin/bash                                                            
                                                                       
set -e                                                                 
                                                                       
export PATH=/sbin:/bin                                                 
                                                                       
tftp_server=10.0.0.1                                                   
nic_module=3c59x.o                                                     
major_a=(2 3 22)                                                       
family_a=(fd hda hdc)                                                  
image_a=(img0001 img0002 img0003 img0004)                              
                                                                       
operation_a=(   "Copy from network to device" \                        
                "Copy from device to network" \                        
                "Run fdisk")                                           
                                                                       
mount -t proc proc /proc                                               
insmod /lib/${nic_module}                                              
/sbin/dhcpcd                                                           
                                                                       
while true; do \                                                       
        [ ! -z "${image}" ] && unset image                             
        echo                                                           
        echo "Clone Menu"                                              
        echo                                                           
        echo "Operation"                                               
        echo                                                           
        PS3="Choose operation (1-${#operation_a[*]}): "                
        select operation in "${operation_a[@]}"; do \                  
                [ -z "${operation}" ] && continue                      
                echo                                                   
                echo $REPLY - $operation                               
                echo                                                   
                break                                                  
        done                                                           
                                                                       
        echo "Device Family"                                           
        echo                                                           
        PS3="Choose device family (1-${#family_a[*]}): "               
        select family in "${family_a[@]}"; do \                        
                [ -z "${family}" ] && continue                         
                echo                                                   
                echo $REPLY - $family                                  
                echo                                                   
                break                                                  
        done                                                           
                                                                       
        major_i=$[REPLY-1]                                             
        major=${major_a[$major_i]}                                     
                                                                       
        echo "Minor Number"                                            
        echo                                                           
        PS3="Choose minor number (0-255): "                            
        echo -n "$PS3" >&2                                             
        read minor                                                     
        minor=$[minor%256]                                             
        echo                                                           
        echo $minor                                                    
        echo                                                           
                                                                       
        if [ "${operation}" != "${operation_a[2]}" ]; then \           
                echo "Image"                                           
                echo                                                   
                PS3="Choose image (1-${#image_a[*]}): "                
                select image in "${image_a[@]}"; do \                  
                        [ -z "${image}" ] && continue                  
                        echo                                           
                        echo $REPLY - $image                           
                        echo                                           
                        break                                          
                done                                                   
                image_i=$[REPLY-1]                                     
                image=${image_a[${image_i}]}                           
        fi                                                             
                                                                       
        echo                                                           
        echo -e "Operation:\t$operation"                               
        device_name=/dev/${family_a[${major_i}]}${minor}               
        echo -e "Device:\t\t${device_name} ($major, $minor)"           
        [ ! -z "${image}" ] && echo -e "Image:\t\t${image}"            
        echo                                                           
                                                                       
        echo "Confirmation"                                            
        echo                                                           
        PS3="Ok/Cancel (1-2): "                                        
        select ok in Ok Cancel; do \                                   
                [ -z "${ok}" ] && continue                             
                echo                                                   
                echo $REPLY - $ok                                      
                echo                                                   
                break                                                  
        done                                                           
        if [ "${ok}" = "Ok" ]; then \                                  
                if [ ! -b ${device_name} ]; then \                     
                        echo "Creating ${device_name}"                 
                        mknod ${device_name} b ${major} ${minor}       
                fi                                                     
                if [ ! -z "${image}" ]; then \                         
                        if [ ! -p ${image} ]; then \                   
                                echo "Creating pipe"                   
                                mknod ${image} p                       
                        fi                                             
                fi                                                     
                if [ "${operation}" = "${operation_a[0]}" ]; then \    
                        tftp ${tftp_server} <<-EOT &                   
                        binary                                         
                        get ${image}                                   
                        EOT                                            
                        gzip -c -d < ${image} | dd of=${device_name}   
                elif [ "${operation}" = "${operation_a[1]}" ]; then \  
                        tftp ${tftp_server} <<-EOT &                   
                        binary                                         
                        put ${image}                                   
                        EOT                                            
                        dd if=${device_name} | gzip -c > ${image}      
                elif [ "${operation}" = "${operation_a[2]}" ]; then \  
                        fdisk ${device_name}                           
                fi                                                     
                echo                                                   
        fi                                                             
                                                                       
        echo "Continuation"                                            
        echo                                                           
        PS3="Continue/Exit (1-2): "                                    
        select new in Continue Exit; do \                              
                [ -z "${new}" ] && continue                            
                echo                                                   
                echo $REPLY - $new                                     
                echo                                                   
                break                                                  
        done                                                           
        [ "${new}" = "Exit" ] && break                                 
done                                                                   
exit 0                                                                 
                                                                       

劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒 

References

[1] GRUB.

http://www.gnu.org/software/grub/

