Linux and Windows Shared swap Areas

Source: Internet
Author: User
Article Title: Linux and Windows Shared swap. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   1. Preface
Now, more and more people are using Linux and Windows. This should be said to be the victory of Linux. We know that Linux should use swap partitions and Windows should use swap files. If a PIII instance has 192 MB of memory, we allocate it to the Linux 192 M swap zone. Windows 2000 requires at least 200 MB. Then, we need to use nearly MB of hard disk space. If the swap zone is larger, the waste will be more impressive.
Because the swap areas of both systems are only temporary data during runtime, we use the dynamic modification of partition information for sharing purposes.
  
   2. Method Introduction
1). Back up Windows partition information.
2) When Linux is started, make the partition into a Linux swap zone and activate it.
3) When Linux is disabled, change the partition to a Windows swap zone.
  
   3. Detailed steps
1). Partition
Fdisk, which is only divided into primary partitions, regardless of extended partitions
2) install Windows.
3). install Linux (occupying a primary partition)
4). In Linux, partitions are divided into extended partitions)
5). Set the Linux swap zone (assuming/dev/hda10)
6) establish the winswap device ln-s/dev/hda10/dev/winswap
7) Start Linux and disable swap zone # swapoff-
8). Delete the partition vi/etc/fstab from the File Installation table and comment out the row (/dev/hda10)
9). Convert the partition into FAT16 or other DOS partitions.
10). Start Windows
A) format the partition.
B). Set the system swap file in this partition.
11) Start Linux and calculate the formula for Total Special Sectors:
T = r + (s * f) + (d/16)
Parameters:
Reserved Sectors at beginning: r
FAT Copies: f
Sectors per FAT: s
Root directory entries: d
See msinfo. sh.
Note: You can run msinfo. sh to obtain it.
# Msinfo. sh/dev/hda10
  
12). Back up Windows partition information
# Dd if =/dev/winswap bs = 512 count = XXX | gzip-9>/etc/winswap.gz here, XXX = T
14). Write the startup and exit scripts and place them in/etc/rc. d/xxx.
Use grep-nr * | grep swapon (or swapoff) to find the system to activate and disable the swap zone and replace them with our scripts)
In the appendix, we provide scripts for starting and disabling.
  
   4. Additional instructions
1. FAT16 is used in this article. If NTFS or others are used, you must modify the script.
2. mkswap/dev/winswap 377496 (this value needs to be modified according to your partition size)
  
   5. References:
Linux HOWTO: Swap-space
  
   6. Appendix-corresponding scripts
1. msinfo. sh script
#! /Bin/sh
#
# Msinfo. sh This shell script displays the boot sector of
# 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 "msinfo: $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 "msinfo: Can't create temp file, exiting ..."
Exit 1
Fi
  
TXTFILE = 'mktemp-q/tmp/$0. xxxxxx'
If [$? -Ne 0]; then
Echo "msinfo: Can't create temp file, exiting ..."
Rm-f $ TMPFILE
Exit 1
Fi
  
Back_title = "'printf" % 78 s "" 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 "% 30 s: % 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 "% 30 s: % 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 "% 30 s: % 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 "% 30 s: % 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 "% 30 s: % 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 "% 30 s: % 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 "% 30 s: % u \ n" "Root directory sectors" "$ root_sectors"
  
# Get Total special sectors
Let total = reserved_sectors + fat_sectors + root_sectors
Printf >>$ TXTFILE "% 30 s: % 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 = 100'" =
'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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.