機(jī)電之家資源網(wǎng)
單片機(jī)首頁(yè)|單片機(jī)基礎(chǔ)|單片機(jī)應(yīng)用|單片機(jī)開(kāi)發(fā)|單片機(jī)文案|軟件資料下載|音響制作|電路圖下載 |嵌入式開(kāi)發(fā)
培訓(xùn)信息
贊助商
Linux 和 Windows 共享交換區(qū)
Linux 和 Windows 共享交換區(qū)
 更新時(shí)間:2009-8-12 16:56:03  點(diǎn)擊數(shù):0
【字體: 字體顏色
      1. 前言 
      現(xiàn)在,越來(lái)越多的人在一臺(tái)使用Linux 和 Windows. 這應(yīng)該說(shuō)是Linux的勝利. 我們知
      道, Linux 要使用交換分區(qū), 
      Windows 要使用交換文件。如果一臺(tái)PIII, 有192M 內(nèi)存,我們分配給Linux 192M 交換
      區(qū), Windows 2000 至少要 
      200M. 那么,我們要用近400M硬盤(pán)空間。如果交換區(qū)更大,浪費(fèi)就更可觀了。 
      由于兩個(gè)系統(tǒng)的交換區(qū)都只是運(yùn)行時(shí)的臨時(shí)數(shù)據(jù),所以,我們采用動(dòng)態(tài)修改分區(qū)信息的方法
      來(lái)達(dá)到共享目的. 

      2. 方法簡(jiǎn)介 
      1). 備份Windows 分區(qū)信息。 
      2). 當(dāng)啟動(dòng)Linux時(shí), 將該分區(qū)做成Linux 交換區(qū),并將其激活。 
      3) 當(dāng)Linux 關(guān)閉時(shí),將該分區(qū)重新變成Windows 交換區(qū)。 

      3. 具體步驟 
      1). 分區(qū) 
      Fdisk, 只分主分區(qū), 不分?jǐn)U展分區(qū) 
      2). 安裝 Windows. 
      3). 安裝Linux (占一個(gè)主分區(qū)) 
      4). 在Linux 下, 分?jǐn)U展分區(qū)) 
      5). 設(shè)定Linux交換區(qū)(假定/dev/hda10) 
      6). 建立winswap 設(shè)備 
      ln -s /dev/hda10 /dev/winswap 
      7). 啟動(dòng)Linux, 關(guān)閉交換區(qū) 
      # swapoff -a 
      8). 從文件安裝表中刪除該分區(qū) 
      vi /etc/fstab 
      注釋掉該行 (/dev/hda10) 
      9). 將該分區(qū)該成 FAT16 或其他 DOS 分區(qū). 
      10). 啟動(dòng) Windows 
      a). 格式化該分區(qū) 
      b). 將系統(tǒng)的交換文件設(shè)在該分區(qū). 
      11). 啟動(dòng) Linux, 計(jì)算Total Special Sectors 
      公式: 
      T = r + (s * f) + (d / 16) 
      參數(shù): 
      Reserved Sectors at beginning : r 
      FAT Copies : f 
      Sectors per FAT : s 
      Root directory entries : d 
      參見(jiàn): msinfo.sh 
      注解: 可以運(yùn)行 msinfo.sh 來(lái)獲得. 
      # msinfo.sh /dev/hda10 

      12). 備份Windows 分區(qū)信息 
      # dd if=/dev/winswap bs=512 count=XXX | gzip -9 > /etc/winswap.gz 
      這里, XXX = T 
      14). 編寫(xiě)啟動(dòng), 退出腳本, 并把它們放在 /etc/rc.d/xxx. 
      可用 grep -nr * | grep swapon (或 swapoff) 來(lái)找系統(tǒng)激活和關(guān)閉交換區(qū), 將它們
      替換稱(chēng)我們 
      的腳本) 
      我們?cè)诟戒浿刑峁┝藛?dòng)和關(guān)閉的腳本. 
      4. 附加說(shuō)明 
      1. 本文使用的是FAT16, 如果使用NTFS 或其它, 必須修改腳本. 
      2. mkswap /dev/winswap 377496 (這個(gè)值需要修改, 依照你的分區(qū)大小) 

      5. 參考資料: 
      Linux HOWT Swap-space 

      6. 附錄 -- 相應(yīng)的腳本 
      1. msinfo.sh 腳本 
      #!/bin/sh 
      # 
      # msinfo.sh This shell script displays the boot sector of the 
      # given partition. 
      # 
      # Author: Rahul U. Joshi 
      # 
      # Modifications Removed the use of expr and replaced it by the let 
      # command. 


      # check for command line arguments 
      if [ $# -ne 1 ]; then 
      echo "Usage: msinfo " 
      exit 1 
      fi 

      # check whether the input name is a block device 
      if [ ! -b $1 ]; then 
      echo "msinf $1 is not a block device" 
      exit 1 
      fi 

      # create two temporary files for use 
      TMPFILE=`mktemp -q /tmp/$0.XXXXXX` 
      if [ $? -ne 0 ]; then 
      echo "msinf Can't create temp file, exiting..." 
      exit 1 
      fi 

      TXTFILE=`mktemp -q /tmp/$0.XXXXXX` 
      if [ $? -ne 0 ]; then 
      echo "msinf Can't create temp file, exiting..." 
      rm -f $TMPFILE 
      exit 1 
      fi 

      back_title="`printf "%78s" "msinfo, Information about FAT16 filesystem --
      Rahul 
      Joshi"`" 

      dialog --title "Boot sector of $1" --backtitle "$back_title" --infobox
      "\nAnalysing boot sector for $1\nPlease wait ..." 14 60 

      # truncate TXTFILE to zero length 
      echo > $TXTFILE 

      # get Formatting DOS version 
      dd 2>/dev/null if=$1 bs=1 count=8 skip=3 | dd 2>/dev/null of=$TMPFILE 
      printf >>$TXTFILE "%30s : %s\n" "Formatting DOS version" "`cat $TMPFILE`"


      # get file system 
      dd 2>/dev/null if=$1 bs=1 count=8 skip=54 | dd 2>/dev/null of=$TMPFILE 
      printf >>$TXTFILE "%30s : %s\n" "Filesystem" "`cat $TMPFILE`" 

      # check if filesystem in a FAT16 
      if [ "`cat $TMPFILE`" != "FAT16 " ]; then 
      dialog --title "Boot sector of $1" --backtitle "$back_title" --infobox
      "\nCan't find a FAT16 filesystem on $1" 14 60 
      exit 2 
      fi 

      # get volume label in boot sector 
      dd 2>/dev/null if=$1 bs=1 count=11 skip=43 | dd 2>/dev/null of=$TMPFILE 
      printf >>$TXTFILE "%30s : %s\n" "Volume label in boot sector" "`cat
      $TMPFILE`" 

      # get Sector size 
      dd 2>/dev/null if=$1 bs=1 count=2 skip=11| od -An -tdS | dd 2>/dev/null
      of=$TMPFILE 
      printf >>$TXTFILE "%30s : %d\n" "Sector size" `cat $TMPFILE` 
      sector_size=`cat $TMPFILE` 


      # get Reserved sectors 
      dd 2>/dev/null if=$1 bs=1 count=2 skip=14| od -An -tdS | dd 2>/dev/null
      of=$TMPFILE 
      printf >>$TXTFILE "%30s : %d\n" " Reserved sectors" `cat $TMPFILE` 
      reserved_sectors=`cat $TMPFILE` 


      # get FAT sectors 
      dd 2>/dev/null if=$1 bs=1 count=1 skip=16| od -An -tdS | dd 2>/dev/null
      of=$TMPFILE 
      fat_count=`cat $TMPFILE` 

      dd 2>/dev/null if=$1 bs=1 count=2 skip=22| od -An -tdS | dd 2>/dev/null
      of=$TMPFILE 
      sectors_per_fat=`cat $TMPFILE` 

      # calculate the no of sectors allocated for FAT's 
      let fat_sectors=fat_count*sectors_per_fat 

      printf >>$TXTFILE "%30s : %u (%u x %u) \n" "FAT sectors" "$fat_sectors"
      "$fat_count" "$sectors_per_fat" 


      # get root directory sectors 
      dd 2>/dev/null if=$1 bs=1 count=2 skip=17| od -An -tdS | dd 2>/dev/null
      of=$TMPFILE 
      root_sectors=`cat $TMPFILE` 

      # calculate the no of sectors allocated for root directory 
      let root_sectors=root_sectors*32/sector_size 

      printf >>$TXTFILE "%30s : %u\n" "Root directory sectors" "$root_sectors" 


      # get Total special sectors 
      let total=reserved_sectors+fat_sectors+root_sectors 
      printf >>$TXTFILE "%30s : %u\n" "Total special sectors" "$total" 

      # display the information in a message box 
      dialog --title "Boot sector of $1" --backtitle "$back_title" --msgbox
      "`cat $TXTFILE`" 14 60 

      # delete temporary files 
      rm -f $TMPFILE 
      rm -f $TXTFILE 

      # end of msinfo.sh 

      2. swapinit.sh 
      #!/bin/sh 
      # 
      # /etc/rc.d/init.d/swapinit.sh - activate the swap partition 
      # 
      # written by Rahul U. Joshi 
      # Verify and initialize swap space 
      # 

      echo -n 'Verifying swap space... ' 

      loopcount=0 

      # flag to indicate whether the partition has been activated or not 
      activated=0 

      # check for signatures 6 times before giving up 
      while [ $loopcount -lt 6 ] 
      do 
      if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" =
      'SWAPSPACE2' ]; then 

      echo "Linux signature found, iteration $loopcount" 
      echo "Activating swap partitions" 
      swapon /dev/winswap 
      activated=1 
      break 

      elif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=5 skip=54`" =
      'FAT16' ]; then 
      echo "DOS signature found, iteration $loopcount" 
      echo "Making swap partition" 
      mkswap /dev/winswap 377496 
      echo "Activating swap partitions" 
      swapon /dev/winswap 
      activated=1 
      break 

      else 
      let loopcount=loopcount+1 
      fi 

      done 


      if [ $activated -ne 1 ] ; then 
      echo "Swap signature not found after $loopcount tries" 
      echo "No swapping partitions activated" 
      exit 1 
      fi 

      3. swaphalt.sh 
      #!/bin/sh 
      # 
      # /etc/rc.d/init.d/swapinit.sh - activate the swap partition 
      # 
      # written by Rahul U. Joshi 
      # Verify and initialize swap space 
      # 

      echo -n 'Verifying swap space... ' 

      loopcount=0 

      # flag to indicate whether the partition has been activated or not 
      activated=0 

      # check for signatures 6 times before giving up 
      while [ $loopcount -lt 6 ] 
      do 
      if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" =
      'SWAPSPACE2' ]; then 

      echo "Linux signature found, iteration $loopcount" 
      echo "Activating swap partitions" 
      swapon /dev/winswap 
      activated=1 
      break 

      elif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=5 skip=54`" =
      'FAT16' ]; then 
      echo "DOS signature found, iteration $loopcount" 
      echo "Making swap partition" 
      mkswap /dev/winswap 377496 
      echo "Activating swap partitions" 
      swapon /dev/winswap 
      activated=1 
      break 

      else 
      let loopcount=loopcount+1 
      fi 

      done 


      if [ $activated -ne 1 ] ; then 
      echo "Swap signature not found after $loopcount tries" 
      echo "No swapping partitions activated" 
      exit 1 
      fi

  • 上一篇: 如何在RedHat中列出彩色文件
  • 下一篇: Debian GNU/Linux 完全安裝手冊(cè)
  • 發(fā)表評(píng)論   告訴好友   打印此文  收藏此頁(yè)  關(guān)閉窗口  返回頂部
    熱點(diǎn)文章
     
    推薦文章
     
    相關(guān)文章
    網(wǎng)友評(píng)論:(只顯示最新5條。)
    關(guān)于我們 | 聯(lián)系我們 | 廣告合作 | 付款方式 | 使用幫助 | 機(jī)電之家 | 會(huì)員助手 | 免費(fèi)鏈接

    點(diǎn)擊這里給我發(fā)消息66821730(技術(shù)支持)點(diǎn)擊這里給我發(fā)消息66821730(廣告投放) 點(diǎn)擊這里給我發(fā)消息41031197(編輯) 點(diǎn)擊這里給我發(fā)消息58733127(審核)
    本站提供的機(jī)電設(shè)備,機(jī)電供求等信息由機(jī)電企業(yè)自行提供,該企業(yè)負(fù)責(zé)信息內(nèi)容的真實(shí)性、準(zhǔn)確性和合法性。
    機(jī)電之家對(duì)此不承擔(dān)任何保證責(zé)任,有侵犯您利益的地方請(qǐng)聯(lián)系機(jī)電之家,機(jī)電之家將及時(shí)作出處理。
    Copyright 2007 機(jī)電之家 Inc All Rights Reserved.機(jī)電之家-由機(jī)電一體化網(wǎng)更名-聲明
    電話:0571-87774297 傳真:0571-87774298
    杭州濱興科技有限公司提供技術(shù)支持

    主辦:杭州市高新區(qū)(濱江)機(jī)電一體化學(xué)會(huì)
    中國(guó)行業(yè)電子商務(wù)100強(qiáng)網(wǎng)站

    網(wǎng)站經(jīng)營(yíng)許可證:浙B2-20080178-1