Linux 和 Windows 共享交換區(轉)
Linux 和 Windows 共享交換區(轉)[@more@]1. 前言現在,越來越多的人在一臺使用Linux 和 Windows. 這應該說是Linux的勝利. 我們知道, Linux 要使用交換分割槽,Windows 要使用交換檔案。如果一臺PIII, 有192M 記憶體,我們分配給Linux 192M 交換區, Windows 2000 至少要200M. 那麼,我們要用近400M硬碟空間。如果交換區更大,浪費就更可觀了。由於兩個系統的交換區都只是執行時的臨時資料,所以,我們採用動態修改分割槽資訊的方法來達到共享目的.2. 方法簡介1). 備份Windows 分割槽資訊。2). 當啟動Linux時, 將該分割槽做成Linux 交換區,並將其啟用。3) 當Linux 關閉時,將該分割槽重新變成Windows 交換區。3. 具體步驟1). 分割槽Fdisk, 只分主分割槽, 不分擴充套件分割槽2). 安裝 Windows.3). 安裝Linux (佔一個主分割槽)4). 在Linux 下, 分擴充套件分割槽)5). 設定Linux交換區(假定/dev/hda10)6). 建立winswap 裝置ln -s /dev/hda10 /dev/winswap7). 啟動Linux, 關閉交換區# swapoff -a8). 從檔案安裝表中刪除該分割槽vi /etc/fstab註釋掉該行 (/dev/hda10)9). 將該分割槽該成 FAT16 或其他 DOS 分割槽.10). 啟動 Windowsa). 格式化該分割槽b). 將系統的交換檔案設在該分割槽.11). 啟動 Linux, 計算Total Special Sectors公式:T = r + (s * f) + (d / 16)引數:Reserved Sectors at beginning : rFAT Copies : fSectors per FAT : sRoot directory entries : d參見: msinfo.sh註解: 可以執行 msinfo.sh 來獲得.# msinfo.sh /dev/hda1012). 備份Windows 分割槽資訊# dd if=/dev/winswap bs=512 count=XXX | gzip -9 > /etc/winswap.gz這裡, XXX = T14). 編寫啟動, 退出指令碼, 並把它們放在 /etc/rc.d/xxx.可用 grep -nr * | grep swapon (或 swapoff) 來找系統啟用和關閉交換區, 將它們替換稱我們的指令碼)我們在附錄中提供了啟動和關閉的指令碼.4. 附加說明1. 本文使用的是FAT16, 如果使用NTFS 或其它, 必須修改指令碼.2. mkswap /dev/winswap 377496 (這個值需要修改, 依照你的分割槽大小)5. 參考資料:Linux HOWTO: Swap-space6. 附錄 -- 相應的指令碼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 argumentsif [ $# -ne 1 ]; thenecho "Usage: msinfo "exit 1fi# check whether the input name is a block deviceif [ ! -b $1 ]; thenecho "msinfo: $1 is not a block device"exit 1fi# create two temporary files for useTMPFILE=`mktemp -q /tmp/$0.XXXXXX`if [ $? -ne 0 ]; thenecho "msinfo: Can't create temp file, exiting..."exit 1fiTXTFILE=`mktemp -q /tmp/$0.XXXXXX`if [ $? -ne 0 ]; thenecho "msinfo: Can't create temp file, exiting..."rm -f $TMPFILEexit 1fiback_title="`printf "%78s" "msinfo, Information about FAT16 filesystem --RahulJoshi"`"dialog --title "Boot sector of $1" --backtitle "$back_title" --infobox" Analysing boot sector for $1 Please wait ..." 14 60# truncate TXTFILE to zero lengthecho > $TXTFILE# get Formatting DOS versiondd 2>/dev/null if=$1 bs=1 count=8 skip=3 | dd 2>/dev/null of=$TMPFILEprintf >>$TXTFILE "%30s : %s " "Formatting DOS version" "`cat $TMPFILE`"# get file systemdd 2>/dev/null if=$1 bs=1 count=8 skip=54 | dd 2>/dev/null of=$TMPFILEprintf >>$TXTFILE "%30s : %s " "Filesystem" "`cat $TMPFILE`"# check if filesystem in a FAT16if [ "`cat $TMPFILE`" != "FAT16 " ]; thendialog --title "Boot sector of $1" --backtitle "$back_title" --infobox" Can't find a FAT16 filesystem on $1" 14 60exit 2fi# get volume label in boot sectordd 2>/dev/null if=$1 bs=1 count=11 skip=43 | dd 2>/dev/null of=$TMPFILEprintf >>$TXTFILE "%30s : %s " "Volume label in boot sector" "`cat$TMPFILE`"# get Sector sizedd 2>/dev/null if=$1 bs=1 count=2 skip=11| od -An -tdS | dd 2>/dev/nullof=$TMPFILEprintf >>$TXTFILE "%30s : %d " "Sector size" `cat $TMPFILE`sector_size=`cat $TMPFILE`# get Reserved sectorsdd 2>/dev/null if=$1 bs=1 count=2 skip=14| od -An -tdS | dd 2>/dev/nullof=$TMPFILEprintf >>$TXTFILE "%30s : %d " " Reserved sectors" `cat $TMPFILE`reserved_sectors=`cat $TMPFILE`# get FAT sectorsdd 2>/dev/null if=$1 bs=1 count=1 skip=16| od -An -tdS | dd 2>/dev/nullof=$TMPFILEfat_count=`cat $TMPFILE`dd 2>/dev/null if=$1 bs=1 count=2 skip=22| od -An -tdS | dd 2>/dev/nullof=$TMPFILEsectors_per_fat=`cat $TMPFILE`# calculate the no of sectors allocated for FAT'slet fat_sectors=fat_count*sectors_per_fatprintf >>$TXTFILE "%30s : %u (%u x %u) " "FAT sectors" "$fat_sectors""$fat_count" "$sectors_per_fat"# get root directory sectorsdd 2>/dev/null if=$1 bs=1 count=2 skip=17| od -An -tdS | dd 2>/dev/nullof=$TMPFILEroot_sectors=`cat $TMPFILE`# calculate the no of sectors allocated for root directorylet root_sectors=root_sectors*32/sector_sizeprintf >>$TXTFILE "%30s : %u " "Root directory sectors" "$root_sectors"# get Total special sectorslet total=reserved_sectors+fat_sectors+root_sectorsprintf >>$TXTFILE "%30s : %u " "Total special sectors" "$total"# display the information in a message boxdialog --title "Boot sector of $1" --backtitle "$back_title" --msgbox"`cat $TXTFILE`" 14 60# delete temporary filesrm -f $TMPFILErm -f $TXTFILE# end of msinfo.sh2. 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 notactivated=0# check for signatures 6 times before giving upwhile [ $loopcount -lt 6 ]doif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" ='SWAPSPACE2' ]; thenecho "Linux signature found, iteration $loopcount"echo "Activating swap partitions"swapon /dev/winswapactivated=1breakelif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=5 skip=54`" ='FAT16' ]; thenecho "DOS signature found, iteration $loopcount"echo "Making swap partition"mkswap /dev/winswap 377496echo "Activating swap partitions"swapon /dev/winswapactivated=1breakelselet loopcount=loopcount+1fidoneif [ $activated -ne 1 ] ; thenecho "Swap signature not found after $loopcount tries"echo "No swapping partitions activated"exit 1fi3. 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 notactivated=0# check for signatures 6 times before giving upwhile [ $loopcount -lt 6 ]doif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" ='SWAPSPACE2' ]; thenecho "Linux signature found, iteration $loopcount"echo "Activating swap partitions"swapon /dev/winswapactivated=1breakelif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=5 skip=54`" ='FAT16' ]; thenecho "DOS signature found, iteration $loopcount"echo "Making swap partition"mkswap /dev/winswap 377496echo "Activating swap partitions"swapon /dev/winswapactivated=1breakelselet loopcount=loopcount+1fidoneif [ $activated -ne 1 ] ; thenecho "Swap signature not found after $loopcount tries"echo "No swapping partitions activated"exit 1fi (linux知識寶庫
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8225414/viewspace-945398/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LINUX和WINDOWS之間的磁碟共享(轉)LinuxWindows
- Linux與Windows共享檔案Samba(轉)LinuxWindowsSamba
- 二層、三層交換機和四層交換機的區別(轉)
- linux與mac和windows的 檔案共享LinuxMacWindows
- Linux掛載Windows網路共享目錄(轉)LinuxWindows
- 簡單實現Windows和Linux檔案共享WindowsLinux
- Windows檔案共享LinuxWindowsLinux
- 銀行業:感覺不到Windows和Linux的區別(轉)行業WindowsLinux
- FreeBSD和Linux共享swap分割槽(轉)Linux
- [Linux] Mount windows共享給linux使用LinuxWindows
- LInux掛載windows共享磁碟LinuxWindows
- Linux訪問Windows共享方法LinuxWindows
- linux和windows系統的區別LinuxWindows
- UNIX系統交換區的管理(轉)
- 管理型交換機和非管理型交換機區別
- 二層交換機和三層交換機的區別
- windows引導BSD和linux(轉)WindowsLinux
- Linux和Windows有啥區別?Linux基礎LinuxWindows
- 轉載---交換機、集線器、路由器區別和作用路由器
- linux掛載windows共享目錄LinuxWindows
- 工業級交換機和網路級交換機區別?
- 交換機埠滿了 怎麼樣才能共享上網(轉)
- Linux與Windows9x/2000的印表機共享(轉)LinuxWindows
- 交換技術:軟交換機的概念、特徵和作用(轉)特徵
- windows共享到linux系統檔案WindowsLinux
- linux掛載windows共享資料夾LinuxWindows
- Linux訪問Windows共享檔案目錄LinuxWindows
- linux 訪問windows共享資料夾LinuxWindows
- LINUX共享WINDOWS磁碟的NFS好工具LinuxWindowsNFS
- Linux和windows系統之間的區別LinuxWindows
- Linux 核心和 Windows 核心有什麼區別?LinuxWindows
- 軟交換與硬交換的區別
- 【Linux運維基礎】交換機和路由器的區別是什麼?Linux運維路由器
- 番外篇:windows端共享檔案給LinuxWindowsLinux
- linux和Windows實現檔案共享之samba的安裝與配置LinuxWindowsSamba
- windows xp和linux虛擬機器之間使用ftp共享檔案WindowsLinux虛擬機FTP
- linux核心和windows核心的一些區別LinuxWindows
- Linux和Windows有什麼區別啊?Linux怎麼樣?LinuxWindows