linuxnewbie.org.gif
Tuesday, 12-Dec-2000 10:32:58 EST
Newbized Help Files articles discussion board bookshelf sensei's log advertising info

Using fdisk

(cont'd)

Creating Partitions

I'm going to do two examples that are hopefully pretty illustrative and will help you figure out the magic behind fdisk.

Creating a swap partition
I'm not sure if you can run a Linux system without a swap partition or not, but I wouldn't ever want to. So, this is one of the more important partitions. It has no special restrictions on it, really. Actually, for older (2.0) kernels some of them can only handle swap partitions that are not any larger than 128MB. But, by now those kernels are rarely in use anymore and ought to be upgraded anyway.

In this example, I'm going to create a swap partition of 256MB at the end of my drive. So, once I'm in fdisk, I want to choose the "n" option for "add a new partition". This is what I get:


Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)

I sort of explained the difference between these two earlier. Since I don't have any more room for another primary partition (partitions 1-3 contain all of my cylinders), I have to make it a logical partition, so I choose "l".


l
First cylinder (1351-2491, default 1351): 

Unless you have a good reason for leaving space between your partitions (and they do exist), it's almost always best to choose the default, which is the first available cylinder. You can actually type it in or just hit Enter.


Using default value 1351
Last cylinder or +size or +sizeM or +sizeK (1351-2491,
default 2491): 

Now here's the best feature of fdisk. You don't have to calculate the cylinders you want a partition to take up, you can just give it a size in MB or KB and it will get it as close as possible for you. Since I want this to be a 256MB swap partition I enter "+256M" (without quotes):


Last cylinder or +size or +sizeM or +sizeK (1351-2491,
default 2491): +256M

Command (m for help): 

And now I'm back at a command prompt. Let's print out the partition table again (p) and see if that change took place:


Command (m for help): p

Disk /dev/hdb: 255 heads, 63 sectors, 2491 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1   *         1       195   1566306   a5  BSD/386
/dev/hdb2           196       212    136552+  82  Linux swap
/dev/hdb3           213      2491  18306067+   5  Extended
/dev/hdb5           213       474   2104514+  83  Linux
/dev/hdb6           475       506    257039+  83  Linux
/dev/hdb7           507       532    208844+  83  Linux
/dev/hdb8           795       925   1052257   83  Linux
/dev/hdb9           926      1056   1052257   83  Linux
/dev/hdb10         1057      1088    257008+  83  Linux
/dev/hdb11         1089      1350   2104483+  83  Linux
/dev/hdb12          533       794   2104483+  83  Linux
/dev/hdb13         1351      1383    265041   83  Linux

Command (m for help): 

Well, I now have a 259MB partition at the end. But, there's a problem. It's a "Linux" partition (ID = 83) and not a "Linux swap" partition (ID = 82). After a quick look at the list of commands (m), I see the "t" option - "change a partition's system id". This sounds right, so let's give it a shot.


Command (m for help): t
Partition number (1-13): 

Of course, we just created partition #13, so I choose that one:

Partition number (1-13): 13        
Hex code (type L to list codes): 

Now I look up and see that the hex code (ID) for "Linux swap" is 82, but I just want to make sure, so I hit "L", and surely enough, you can see that 82 is indeed "Linux swap", so we enter in 82:

Hex code (type L to list codes): 82
Changed system type of partition 13 to 82 (Linux swap)

Excellent! Now let's print the partition table again just to make sure that the changes took effect. I get this line for our partition:

/dev/hdb13         1351      1383    265041   82  Linux swap

Wonderful. We have created a Linux swap partition. Now in order for it to actually be written onto the hard drive we must write the partition table to the disk. That is option "w" - "write table to disk and exit". When I call it I get this:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.

So, now we have a new partition on our disk for swap. All that's left now is to actually set up the swap "filesystem" on it so that the system can read and write to it correctly. I'm not going to cover that in this particular NHF though I plan on writing another one about it.

[- next page: ext2 and deleting partitions -]


Would you like to have your article published online? Send them in to newfiles@linuxnewbie.org

The Linux Channel at internet.com
Linux Planet
Linux Today
Linux Central
Linuxnewbie.org
PHPBuilder
Just Linux
Linux Programming
Linux Start
BSD Today
Apache Today
Enterprise Linux Today
BSD Central
All Linux Devices
SITE DESCRIPTIONS
[-What's New-]
Order a Linuxnewbie T-Shirt
Easy Webcam NHF
Directory Navigation NHF
Installing Snort 1.6.3 on SuSE 6.x-7.x
Customizing vim
The SysVinit NHF
Installing ALSA for the VT82C686 integrated sound
USB Creative Video Blaster II for Linux
Configuring the Intellimouse Explorer in XFree86 V4+
The beginnings of a distro NHF
Getting Past Carnivore?
Getting and Installing PGP
Getting your ATI Rage 128 Working
How to create a multiple partition system
Using Fdisk
Introduction to Programming in C/C++ with Vim
Adding a Hard drive in Linux -- In five steps
Installing ALSA for the Yamaha DS-XG Sound Card
Getting your Diamond Rio Mp3 Player to work with Linux
Bash Programming Cheat Sheet
Installing NVIDIA Drivers for Mandrake
Setting up Portsentry
Hard Drive Speed Tweak for Linux
Sensei's Log
Chat room
Join: Linuxnewbie.org SETI Black Belts!
Send in your news
Click the image to add Linuxnewbie.org to your MyNetscape Page
[-LNO Newsletter-]

[-Archive-]
The beginnings of a distro NHF
Connecting to the Internet using KPPP
Getting your SBLive to work
Unreal Tournament NHF
LWE Day 2 Pictures
LWE Day 1 Pictures
The LNO FAQ!
WoW (Words of Wisdom)
Other sites news
What is Linux?
What is Linux? part deux (ups & downs)
Search newsgroups
The List
ALS Report
Feedback Form
jobs.linuxtoday.com.gif
Match: Format: Sort by:
Search:
[-Quick Links-]

Copyright 2000 internet.com Corp. All Rights Reserved. Legal Notices Privacy Policy

internet.com.gif