µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux - Óà Sfdisk ºÍ Perl ¶ÔÓ²ÅÌ·ÖÇø

Óà Sfdisk ºÍ Perl ¶ÔÓ²ÅÌ·ÖÇø



        
    ×÷ÕߣºMark NielsenÒëÕߣºÐ¡Ä²


    Ë÷Òý:
    ×ÊÔ´¡£
    Sfdisk ºÍ Perl Expect ģʽ½éÉÜ¡£
    ÈçºÎÓÃSfdisk»ñµÃÓ²ÅÌÐÅÏ¢¡£
    ÈçºÎÓÃSfdisk¶ÔÓ²ÅÌ´´½¨»òÕßÖØзÖÇø¡£
    ÈçºÎÓÃExpectɾ³ýËùÓзÖÇø¡£
    ÈçºÎÓÃExpect¸ü¸Ä·ÖÇøÐÅÏ¢¡£
    ×¢ÊÍ¡£
    ½ñºó±ä¸üµÄÏà¹ØÄÚÈÝ»áλÓÚ http://www.tcu-inc.com/mark/articles/Sfdisk.html¡£


    --------------------------------------------------------------------------------

    ×ÊÔ´
    http://www.perl.com/CPAN/authors/id/AUSCHUTZ/Expect.pm-1.07.tar.gz
    /usr/src/linux/Documentation/ide.txt
    man sfdisk
    man lilo
    man lilo.conf
    http://metalab.unc.edu/LDP/HOWTO/mini/LILO.html
    man hdparm #ÉÓ´ø˵Ã÷ -- ¿ÉÄÜÄã»á·¢ÏÖÕâ¶ÔÆäËûºÜ¶àÊÂÇ鶼·Ç³£ÓÐÓá£

    --------------------------------------------------------------------------------

    Sfdisk Perl Expectģʽ½éÉÜ
    ÎÒÕæÊǶÔ×Ô¼ºµÄ±íÏַdz£¼¤¶¯¡£ÎÒÖ»ÔÚRedhat 6.0ÖнøÐÐÁËÖظ´²âÊÔ¡£Debian »áÊǺܺõÄÌæ´ú¡£
    ´ËÎÄÕµÄÄ¿µÄÊǽéÉÜÈçºÎʹÓà Sfdisk ºÍ Perl Expect ģʽÀ´×Ô¶¯´¦ÀíÓ²ÅÌ·ÖÇø¡£ÎªÊ²Ã´ÒªÕâô×ö£¿ÆäʵÕâÊÇÖÚ¶à½â¾ö Linux µÄÆô¶¯Îļþ±ØÐë·ÅÔÚ1024ÖùÃæ֮ǰµÄÎÊÌâµÄ·½·¨Ö®Ò»£¬»¹ÓÐÆäËûÐí¶à°ì·¨£¬µ«ÕâƪÎÄÕÂÖÐÊÇ¿¿¸Ä±äÖùÃæÀ´½øÐеġ£Ò²¿ÉÓÃÀ´¶ÔÐÂÓ²Å̽øÐÐ×Ô¶¯·ÖÇø¡£

    .SfdiskÊÇÒ»¸öͨ¹ý scripts À´±ä¸üÓ²ÅÌ·ÖÇøµÄ¹¤¾ß£¬Ò²ÄÜÈÃÄã»ñÈ¡Ó²Å̵ÄÐÅÏ¢¡£ËäÈ»ºÜ¿á£¬µ«ÊÇÈ·ÓÐÁ¦Óв»´þÖ®´¦¡£ÆäÄÜÍê³ÉfdiskµÄ¶àÊý±ØÒªµÄÄÜÁ¦£¬µ«¾ö²»ÊÇËùÓеŦÄÜ¡£

    Disk Druid ÊÇ Redhat ÖÐÓÃÀ´ÔÚÓ²ÅÌ°²×° Linux ֮ǰ½øÐгõʼ»¯µÄ³ÌÐò¡£(¸ü¸Ä·ÖÇø´óС)

    PerlÊÇ¿á±ÐÁ˵ıà³ÌÓïÑÔ¡£Æä\"Expect\"ģʽÊǼÓÈëÏà¹ØµÄ¶ÔÓû§ÓѺ÷½Ê½Ê¹µÃ¿ÉÒÔ×Ô¶¯²Ù×÷ÃüÁî¡£»»¶øÑÔÖ®£¬¾ÍÊÇ˵µ±ÔËÐÐ Expect ģʽµÄÃèÊöÓïÑÔ³ÌÐòʱ£¬Ëü¾ÍÈçͬÄã×Ô¼ºÔÚ¼ÆËã»úµÄ¼üÅÌÉÏÊäÈëÃüÁî -- ¶ÔÈκλùÓÚ¿ØÖÆ̨ÔËÐеijÌÐò¶øÑÔ¸üÏóºêµ«¸ü¸ß¼¶¸üÓÐÓá£Perl ¾ÍÊÇÈç´ËµÄ¿á£¬Ëü¿ÉÒÔʹÓÃÈκεĶ«Î÷¡£

    ÒªÔËÐÐ Expect Perl ģʽ¾Í±ØÐëÒª°²×°Á½¸öÄ£¿é¡£
    IO-Stty-.02.tar.gz
    IO-Tty-0.02.tar.gz


    --------------------------------------------------------------------------------

    ÈçºÎÓÃSfdisk»ñÈ¡Ó²ÅÌÐÅÏ¢¡£
    ÔÚ RedHat 6.0ÖУ¬È±Ê¡¾Í°üº¬ÁËsfdisk¡£ ÎҲ¿ÉÄÜBSDµÄ¹æÔòÖÐÊÇÒª½ÚÊ¡¿Õ¼äµÄ¡£²»¹ÜÔõÑù£¬ÏÂÃæ¾ÍÊÇһЩ»ñµÃ PC¼æÈÝ»úÖÐÓ²ÅÌÖ÷¿ØÖÆÆ÷²ÎÊýµÄÃüÁî¡£
    Ó²ÅÌ·ÖÇøÐÅÏ¢£¬

    /sbin/sfdisk -g /dev/hdd

    ÒÔ×Ö½ÚΪµ¥Î»ÏÔʾӲÅ̵Ä×Ü¿Õ¼ä´óС£¬
    /sbin/sfdisk -s /dev/hdd

    ½«µÚÒ»Ó²ÅÌ5·ÖÇøµÄ id ºÅÉèΪ Linux ·ÖÇø£¬
    sfdisk --change-id /dev/hdd 5 83


    --------------------------------------------------------------------------------

    ÓÃSfdisk´´½¨»òÖØжÔÓ²ÅÌ·ÖÇø¡£
    Sfdisk µÄÇ¿´óÌØÐÔÊǶÔÓ²ÅÌÖØзÖÇø»ò´´½¨Ð·ÖÇø¡£ÒÔÈçϸñʽ½¨Á¢Ò»¸ö\"Test.data\"µÄÎļþ£¬×Ö¶ÎÖ®¼äÒÔ¶ººÅ·Ö¸ô£º
    Æðʼ£¬´óС£¬ID£¬¿ÉÆô¶¯

    Æðʼ = ÆðʼÖùÃæ(Èç¹û²»½øÐÐÖ¸¶¨ÔòΪµÚÒ»¿ÉÓÃÖùÃæ)£¬´óС = ÖùÃæÊýÁ¿(Èç¹û²»½øÐÐÖ¸¶¨ÔòÖ¸ËùÓÐÖùÃæ)£¬IDºÅ = ·ÖÇøÀàÐÍ(Linux, Swap, MSDOS, »òÆäËû)£¬¿ÉÆô¶¯=·ÖÇøÊÇ·ñÉèΪÆô¶¯·ÖÇø¡£»¹ÓÐÆäËûµÄһЩѡÏµ«Ôڴ˲»×öÌÖÂÛ¡£

    ¼ÙÉèÒªÉèÁ¢µÚÒ»·ÖÇøΪ136ÖùÃ棬 µÚ¶þ·ÖÇøΪ254ÖùÃæµÄSWAP·ÖÇø(ID=82)£¬µÚÈý·ÖÇøΪʣϵÄËùÓпռäÉèΪLinux·ÖÇø(ID=83),ÔòÎļþÈçÏÂÉèÖãº

    ¡¡

    1,136
    101,254,82
    201,,83,*

    È»ºóÖ´ÐÐÈçÏÂÃüÁÔÚ´ÓÓ²ÅÌ»òµÚ¶þÓ²ÅÌÉϽøÐÐÉèÖÃ

    /sbin/sfdisk /dev/hdd << Test.data

    ²é¿´ÊÇ·ñÒѾ­ÉèÖÃ
    /sbin/sfdisk /dev/hdd

    ÔÙ´ÎÖØÉ꣬ÍƼöÈ¥¶ÁmanpageÀ´Á˽âÔÚÎļþÖÐÈçºÎÉèÖÃÕâЩ²ÎÊý¡£ÒÔÉÏÈκÎδÉ趨µÄ×ֶν«°´Ä¬ÈÏÖµ½øÐÐÉ趨¡£

    *Òë×¢£º¶ÔÓ²ÅÌ·ÖÇø½øÐÐÉèÖÃÊǺÜΣÏյģ¬ÌرðÊÇ´æÓÐÊý¾ÝµÄÅÌ£¬ºÜ¿ÉÄܵ¼ÖÂÊý¾Ý¶ªÊ§£¬ËùÒÔÒ»¶¨Òª×Ðϸ¼ì²éÊǶÔÄĸöÓ²Å̽øÐÐÉèÖ㬷ñÔòÈκεÄÎó²Ù×÷½«µ¼ÖÂÎÞνµÄÎþÉü¡£


    --------------------------------------------------------------------------------

    ÈçºÎÀûÓà Expect À´É¾³ýÓ²Å̵ÄËùÓзÖÇø¡£
    Óà Perl script À´É¾³ýËùÓзÖÇøÊǷdz£Î£Ïյģ¬Èç¹ûÔÚÄãµÄÓ²ÅÌÉϽøÐвâÊÔ£¬ÎÒ²»µ£±£ÈκδíÎ󣬼´Ê¹ÎÒµÄÕâ¸öÎļþÊÇ´íÎóµÄ£¬Õâ¾ÍÊÇÄãҪȥðµÄ·çÏÕ¡£
    ¸ù±¾¶øÑÔ£¬ÒÔ Expect ģʽ£¬¿ÉÒÔ×Ô¶¯Ö´ÐÐÈκÎÃüÁÄãÒÔºó¿ÉÄÜ»áдһ¸ö¸´ÔӵijÌÐò -- ¶øÕâÀïÖ»ÊÇÒ»¸öÌáʾ¡£

    ½«Îļþ´æΪ \"Dufus_Move.pl\" ²¢Ö´ÐÐÒÔÏÂÃüÁî

    chmod 755 Dufus_Move.pl
    È»ºóÈçÏÂÔÚÄãµÄ´ÓÓ²ÅÌ»òµÚ¶þ¿ØÖÆÆ÷ÉÏÖ´ÐУ¬

    ./Dufus_Move.pl d

    --------------------------------------------------------------------------------

    ÓÃExpectÀ´¸Ä±äÓ²ÅÌ·ÖÇøÐÅÏ¢¡£
    Óà Perl script À´¸Ä±ä·ÖÇøÉèÖÃÊǷdz£Î£Ïյģ¬Èç¹ûÄãÔÚ×Ô¼ºµÄÓ²ÅÌÉϽøÐвâÊÔ£¬ÎÒ²»µ£±£ÈκδíÎ󣬼´Ê¹ÎÒµÄÕâ¸öÎļþÊÇ´íÎóµÄ£¬Õâ¾ÍÊÇÄãҪȥðµÄ·çÏÕ¡£
    ÎÞÂÛÈçºÎ£¬Õâ¸ö script ½«·ÖÇøµÄÖùÃæÖµÉèΪ×î´ó

    ½«Îļþ´æΪ \"Change_Cylinders.pl\" ²¢Ö´ÐÐÒÔÏÂÃüÁî

    chmod 755 Change_Cylinders.pl
    È»ºóÈçÏÂÔÚÄãµÄ´ÓÓ²ÅÌ»òµÚ¶þ¿ØÖÆÆ÷ÉÏÖ´ÐУ¬
    ./Change_Cylinders.pl d

    --------------------------------------------------------------------------------

    Comments×¢ÊÍ
    Sfdisk ÕæÊÇÒ»¸öºÜ¿áµÄ³ÌÐò£¬µ«´´½¨Ò»¸öFdiskµÄperl½çÃæ¾Í¿á´ôÁË¡£µ«¡°ËûÃÇ¡±ÎªÊ²Ã´²»¸ü¿áһϣ¬ÎÒÒ²²»ÖªµÀËûÃÇÓ¦¸ÃÊÇָ˭¡£
    Èç¹ûSfdiskÄܹ»ÖØ×öÒ»¸öÓ²ÅÌ£¬ÎҾͲ»ÔÙÐèÒªÆäËûµÄÈκι¤¾ßÁË¡£Ò²ÐíÍêÈ«ÄÜÐеÄͨ£¬µ«ÎÒ»¹Ã»¼û¹ý¡£
    ÕâÊÇÎÒµÚÒ»´ÎÕæÕýÓÃExpect×ö¸´ÔÓµÄÈÎÎñ£¬ÔÚ´ËûÓÐÁгöËùÓÐÎÒÔø×öµÄ¶«Î÷¡£

    --------------------------------------------------------------------------------

    Mark Nielsen µÄ¹¤×÷ÊÇÔÚ The Computer Underground ×öÊý¾Ý¿â±à³ÌÖúÀí£¬¼æÖ°×öZINGµÄÖƶ©¹¤»¹ÔÚ linux.com ÅÜÅÜÁúÌס£ÒÔÉÏÎÄ×ÖʹÓÃNeditºÍispell±à¼­¡£

    *Òë×¢£º¶ÔÓ²ÅÌ·ÖÇø½øÐÐÉèÖÃÊǺÜΣÏյģ¬ÌرðÊÇ´æÓÐÊý¾ÝµÄÅÌ£¬ºÜ¿ÉÄܵ¼ÖÂÊý¾Ý¶ªÊ§£¬ËùÒÔÒ»¶¨Òª×Ðϸ¼ì²éÊǶÔÄĸöÓ²Å̽øÐÐÉèÖ㬷ñÔòÈκεÄÎó²Ù×÷½«µ¼ÖÂÎÞνµÄÎþÉü¡£ÒÔÉϵÄËùÓÐÄÚÈÝСIJδ½øÐйý²âÊÔ
    ·¢²¼ÈË:netbull À´×Ô:Linux¹«±¨