LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2007, 07:27 PM   #1
rezwits
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
swap file instead of swap disk "dd" error


Hi all,

I recently just got finished with a Triple boot install on my MacBook of 10.5, 4.0r1 (etch), and XP SP2. Everything (almost) went alright with all my installs, even got thru the wireless on the MacBook using the madwifi under one battery charge.

The problem I am having though, is with this particular setup I am unable to have a swap partition for Linux. So I had to use the instructions I found for creating a swapfile instead of using a swap disk (partition). What happened though is when I used the "dd if=/dev/zero of=/swap bs=1024 count=1048576", I substituted 1024 and 1048576 with 3072 and 3145728 respectively because I have 3 GB of RAM installed and issued the command and then it kinda took a long time instead of returning a prompt. I knew it kinda would take a little time so I waited then I couldn't take it I ^c'ed and canceled out. But then the system told me the process did 7.8 GB of transfer or something (as I recall). So I checked the swap file in / to see how big it was. It wasn't any bigger than normal, but unfortunately out of a 20 GB partition for install all that remained was 9.2 or so GBs. Which is like 7.8 GB for some file (possible swap size, but like I said whe I did ls it didn't size up right) and 3.0 GB for the Linux install.

My question is how can I get this damn swap file removed and create a swapfile the proper size. Can I rename the swap file "swapfile.old" then create a new swap file (but need help with that cause the dd command never quits) then use:

mkswap /swap
swapon /swap
chmod 600 /swap

and then restart then delete the swap.old file?

Thanks for any help I can get...

oh one note, what does the dd command do anyway or stand for... ta
 
Old 12-15-2007, 09:30 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
You can simply delete the first file. Remember that the size is the block size times the count. A 3 GB swap size sounds excessive. You probably only need a large swap if it is used for suspending. 500MB or 1GB should be more than plenty for normal usage.

Read the man page for the dd command. You can use the offset option to only write the last block.
for example:
Code:
dd if=/dev/zero of=testfile bs=256 count=1 seek=$((1024*1024-1))
1+0 records in
1+0 records out
256 bytes (256 B) copied, 6.8723e-05 s, 3.7 MB/s
jschiwal@hpamd64:~> ls -l testfile
-rw-r--r-- 1 jschiwal jschiwal 268435456 Dec 15 21:28 testfile
Simply subtract 1 from your old count value and use it for seek instead, and use a "count=1". The command will be almost instant.

It would only be worthwhile zero'ing out a partition (before installing, when reusing a drive) if you plan to perform an image backup later after the initial install. ( you wouldn't backup swap of course ) Doing so, you can compress the backup through gzip or bzip2 before saving it.

Last edited by jschiwal; 12-15-2007 at 09:37 PM.
 
Old 12-15-2007, 09:43 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,645

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
Mmmm - 3 Gig; why the hell are you worried about swap ???. 9 Gig ???.

Standard x86 Linux won't use anymore than 2 Gig of a swap extent. And it'll quite happily run without swap at all. Delete the file and start again. Try half a Gig unless you hit problems, then just add more.
You are aware this can be a logical partition - doesn't need to be primary.
 
Old 12-15-2007, 09:57 PM   #4
gd2shoe
Member
 
Registered: Jun 2004
Location: Northern CA
Distribution: Debian
Posts: 835

Rep: Reputation: 49
3072 * 3145728 = 9GB, not 3GB

Instead, if you are set on a 3GB swap (very large) instead, use:
dd if=/dev/zero of=/swap bs=1M count=3072
dd moves MBs a lot faster than KBs. This will still take some time, but nowhere near what you spent on it last time.

You can remove the old file immediately (assuming you haven't formatted it as swap, and mounted it) using:
rm /swap

So, just delete the huge file, run the dd command, mkswap, and swapon. Then edit your /etc/fstab file to make it permanent.
 
Old 12-15-2007, 11:30 PM   #5
rezwits
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks all of you guys, this completely answered my questions. I thought this was the primary swap, cause I have 1.5 GB ram on a Mac OS X system and the swap size gets to be 12.5 GB, but I guess I am getting confused to how the mac using swap vs how linux does. Cause I thought that if the system was running threads (processes) that the swap would get up there like my mac does. But the statement "You are aware this can be a logical partition - doesn't need to be primary", kinda confuses me a little. Cause this is how I always thought swap worked... nah forget that , Merry Xmas...

I fixed it the way it should be...
 
Old 12-16-2007, 12:34 AM   #6
gd2shoe
Member
 
Registered: Jun 2004
Location: Northern CA
Distribution: Debian
Posts: 835

Rep: Reputation: 49
Historically on a Windows box swap is done to a file. Historically on a Linux box, swap is done to a dedicated partition. It CAN be done to a file though. On Windows (and presumably on a Mac) the system will automatically adjust the file size to suit need. This is not the case on Linux. If need be, though, you can have more than one swap file, and use swapon and swapoff to enable and disable them.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't swap ps to disk by press "Ctrl+Z" hus Mandriva 2 01-17-2005 04:31 AM
"howto hot-swap an ide-raid-disk with promise fasttrak tx2000pro" mweis Linux - Hardware 0 05-24-2004 03:55 AM
Swap file "drive" or partition for new PC/speed questions? robbow52 Linux - Hardware 4 01-08-2004 04:59 PM
Getting the error "E297 : Write error in swap file " sudhir_gunda Linux - General 3 12-29-2003 08:07 AM
"E297: Write error in swap file" :-( sudhir_gunda Linux From Scratch 2 12-29-2003 01:41 AM


All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration