]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/sfdisk.8
Imported from util-linux-2.8 tarball.
[thirdparty/util-linux.git] / disk-utils / sfdisk.8
CommitLineData
fd6b7a7f
KZ
1.\" Copyright 1995 Andries E. Brouwer (aeb@cwi.nl)
2.\" May be distributed under the GNU General Public License
3.\" The `DOS 6.x Warning' was taken from the old fdisk.8, which says
4.\" -- Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
5.\" -- May be distributed under the GNU General Public License
6.\" The `DRDOS Warning' was taken from a net post by Stephen Tweedie.
7.\"
8.TH SFDISK 8 "1 September 1995" "Linux 1.3.23" "Linux Programmer's Manual"
9.SH NAME
10sfdisk \- Partition table manipulator for Linux
11.SH SYNOPSIS
12.BR sfdisk " [options] device"
13.br
14.BR "sfdisk \-s " [partition]
15.SH DESCRIPTION
16.B sfdisk
17has four (main) uses: list the size of a partition, list the partitions
18on a device, check the partitions on a device, and - very dangerous -
19repartition a device.
20
21.SS "List Sizes"
22.BI "sfdisk \-s " partition
23gives the size of
24.I partition
25in blocks. This may be useful in connection with programs like
26.B mkswap
27or so. Here
28.I partition
29is usually something like
30.I /dev/hda1
31or
32.IR /dev/sdb12 ,
33but may also be an entire disk, like
34.IR /dev/xda .
35.br
36.RS
37.nf
38.if t .ft CW
39% sfdisk \-s /dev/hda9
4081599
41%
42.if t .ft R
43.fi
44.RE
45If the partition argument is omitted,
46.B sfdisk
47will list the sizes of all disks, and the total:
48.br
49.RS
50.nf
51.if t .ft CW
52% sfdisk \-s
53/dev/hda: 208896
54/dev/hdb: 1025136
55/dev/hdc: 1031063
56/dev/sda: 8877895
57/dev/sdb: 1758927
58total: 12901917 blocks
59%
60.if t .ft R
61.fi
62.RE
63
64.SS "List Partitions"
65The second type of invocation:
66.BI "sfdisk \-l " "[options] device"
67will list the partitions on this device.
68If the device argument is omitted, the partitions on all hard disks
69are listed.
70.br
71.nf
72.if t .ft CW
73% sfdisk \-l /dev/hdc
74
75Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
76Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
77
78 Device Boot Start End #cyls #blocks Id System
79/dev/hdc1 0+ 406 407\- 205096+ 83 Linux native
80/dev/hdc2 407 813 407 205128 83 Linux native
81/dev/hdc3 814 2044 1231 620424 83 Linux native
82/dev/hdc4 0 \- 0 0 0 Empty
83%
84.if t .ft R
85.fi
86The trailing \- and + signs indicate that rounding has taken place,
87and that the actual value is slightly less (more).
88To see the exact values, ask for a listing with sectors as unit.
89
90.SS "Check partitions"
91The third type of invocation:
92.BI "sfdisk \-V " device
93will apply various consistency checks to the partition tables on
94.IR device .
95It prints `OK' or complains. The \-V option can be used together
96with \-l. In a shell script one might use
97.BI "sfdisk \-V \-q " device
98which only returns a status.
99
100.SS "Create partitions"
101The fourth type of invocation:
102.BI "sfdisk " device
103will cause
104.B sfdisk
105to read the specification for the desired partitioning of
106.I device
107from its standard input, and then to change the partition tables
108on that disk. Thus, it is possible to use
109.B sfdisk
110from a shell script. When
111.B sfdisk
112determines that its standard input is a terminal, it will be
113conversational; otherwise it will abort on any error.
114.LP
115BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST
116.LP
117As a precaution, one can save the sectors changed by
118.BR sfdisk :
119.RS
120.nf
121.if t .ft CW
122% sfdisk /dev/hdd \-O hdd-partition-sectors.save
123%
124.if t .ft R
125.fi
126.RE
127.LP
128Then, if you discover that you did something stupid before anything
129else has been written to disk, it may be possible to recover
130the old situation with
131.RS
132.nf
133.if t .ft CW
134% sfdisk /dev/hdd \-I hdd-partition-sectors.save
135%
136.if t .ft R
137.fi
138.RE
139
140There are many options.
141
142.SH OPTIONS
143.TP
144.BR \-v " or " \-\-version
145Print version number of
146.B sfdisk
147and exit immediately.
148.TP
149.BR \-? " or " \-\-help
150Print a usage message and exit immediately.
151.TP
152.BR \-T " or " \-\-list-types
153Print the recognized types (system Id's).
154.TP
155.BR \-s " or " \-\-show\-size
156List the size of a partition.
157.TP
158.BR \-g " or " \-\-show\-geometry
159List the kernel's idea of the geometry of the indicated disk(s).
160.TP
161.BR \-l " or " \-\-list
162List the partitions of a device.
163.TP
164.BR \-d
165Dump the partitions of a device in a format useful as input
166to sfdisk. For example,
167.br
168.nf
169.if t .ft CW
170 % sfdisk -d /dev/hda > hda.out
171 % sfdisk /dev/hda < hda.out
172.if t .ft R
173.fi
174will correct the bad last extended partition that the OS/2
2b6fc908 175fdisk creates.
fd6b7a7f
KZ
176.TP
177.BR \-V " or " \-\-verify
178Test whether partitions seem correct. (See above.)
179.TP
180.BR \-i " or " \-\-increment
181Number cylinders etc. starting from 1 instead of 0.
182.TP
183.BI \-N " number"
184Change only the single partition indicated. For example:
185.br
186.nf
187.if t .ft CW
188 % sfdisk /dev/hdb \-N5
189 ,,,*
190 %
191.if t .ft R
192.fi
193will make the fifth partition on /dev/hdb bootable (`active')
194and change nothing else. (Probably this fifth partition
195is called /dev/hdb5, but you are free to call it something else,
196like `/my_equipment/disks/2/5' or so).
197.TP
198.BI \-A " number"
199Make the indicated partition(s) active, and all others inactive.
200.TP
201.BI \-c " or " \-\-id " number [Id]"
202If no Id argument given: print the partition Id of the indicated
203partition. If an Id argument is present: change the type (Id) of
204the indicated partition to the given value.
205This option has the two very long forms \-\-print\-id and \-\-change\-id.
206For example:
207.br
208.nf
209.if t .ft CW
210 % sfdisk --print-id /dev/hdb 5
211 6
212 % sfdisk --change-id /dev/hdb 5 83
213 OK
214.if t .ft R
215.fi
216first reports that /dev/hdb5 has Id 6, and then changes that into 83.
217.TP
218.BR \-uS " or " \-uB " or " \-uC " or " \-uM
219Accept or report in units of sectors (blocks, cylinders, megabytes,
220respectively). The default is cylinders, at least when the geometry
221is known.
222.TP
223.BR \-x " or " \-\-show\-extended
224Also list non-primary extended partitions on output,
225and expect descriptors for them on input.
226.TP
227.BI \-C " cylinders"
228Specify the number of cylinders, possibly overriding what the kernel thinks.
229.TP
230.BI \-H " heads"
231Specify the number of heads, possibly overriding what the kernel thinks.
232.TP
233.BI \-S " sectors"
234Specify the number of sectors, possibly overriding what the kernel thinks.
235.TP
236.BR \-f " or " \-\-force
237Do what I say, even if it is stupid.
238.TP
239.BR \-q " or " \-\-quiet
240Suppress warning messages.
241.TP
242.BR \-L " or " \-\-Linux
243Do not complain about things irrelevant for Linux.
244.TP
245.BR \-D " or " \-\-DOS
246For DOS-compatibility: waste a little space.
247(More precisely: if a partition cannot contain sector 0,
248e.g. because that is the MBR of the device, or contains
249the partition table of an extended partition, then
250.B sfdisk
251would make it start the next sector. However, when this
252option is given it skips to the start of the next track,
253wasting for example 33 sectors (in case of 34 sectors/track),
254just like certain versions of DOS do.)
255Certain Disk Managers and boot loaders (such as OSBS, but not
256LILO or the OS/2 Boot Manager) also live in this empty space,
257so maybe you want this option if you use one.
258.TP
259.BR \-\-IBM " or " \-\-leave\-last
260Certain IBM diagnostic programs assume that they can use the
261last cylinder on a disk for disk-testing purposes. If you think
262you might ever run such programs, use this option to tell
263.B sfdisk
264that it should not allocate the last cylinder.
265Sometimes the last cylinder contains a bad sector table.
266.TP
267.B \-n
268Go through all the motions, but do not actually write to disk.
269.TP
270.B \-R
271Only execute the BLKRRPART ioctl (to make the kernel re-read
272the partition table). This can be useful for checking in advance
273that the final BLKRRPART will be successful, and also when you
274changed the partition table `by hand' (e.g., using dd from a backup).
275If the kernel complains (`device busy for revalidation (usage = 2)')
276then something still uses the device, and you still have to unmount
277some file system, or say swapoff to some swap partition.
278.TP
279.B \-\-no\-reread
280When starting a repartitioning of a disk, sfdisk checks that this disk
281is not mounted, or in use as a swap device, and refuses to continue
282if it is. This option suppresses the test. (On the other hand, the \-f
283option would force sfdisk to continue even when this test fails.)
284.TP
285.BI \-O " file"
286Just before writing the new partition, output the sectors
287that are going to be overwritten to
288.I file
289(where hopefully
290.I file
291resides on another disk, or on a floppy).
292.TP
293.BI \-I " file"
294After destroying your filesystems with an unfortunate
295.B sfdisk
296command, you would have been able to restore the old situation
297if only you had preserved it using the \-O flag.
298
299.SH THEORY
300Block 0 of a disk (the Master Boot Record) contains among
301other things four partition descriptors. The partitions
302described here are called
303.I primary
304partitions.
305.LP
306A partition descriptor has 6 fields:
307.br
308.nf
309.RS
310struct partition {
311 unsigned char bootable; /* 0 or 0x80 */
312 hsc begin_hsc;
313 unsigned char id;
314 hsc end_hsc;
315 unsigned int starting_sector;
316 unsigned int nr_of_sectors;
317}
318.RE
319.fi
320.LP
321The two hsc fields indicate head, sector and cylinder of the
322begin and the end of the partition. Since each hsc field only
323takes 3 bytes, only 24 bits are available, which does not
324suffice for big disks (say > 8GB). In fact, due to the wasteful
325representation (that uses a byte for the number of heads, which
326is typically 16), problems already start with 0.5GB.
327However Linux does not use these fields, and problems can arise
328only at boot time, before Linux has been started. For more
329details, see the
330.B lilo
331documentation.
332.LP
333Each partition has a type, its `Id', and if this type is 5
334.IR "" "(`" "extended partition" "')"
335the starting sector of the partition
336again contains 4 partition descriptors. MSDOS only uses the
337first two of these: the first one an actual data partition,
338and the second one again an extended partition (or empty).
339In this way one gets a chain of extended partitions.
340Other operating systems have slightly different conventions.
341Linux also accepts type 85 as equivalent to 5 - this can be
342useful if one wants to have extended partitions under Linux past
343the 1024 cylinder boundary, without DOS FDISK hanging.
344(If there is no good reason, you should just use 5, which is
345understood by other systems.)
346.LP
347Partitions that are not primary or extended are called
348.IR logical .
349Often, one cannot boot from logical partitions (because the
350process of finding them is more involved than just looking
351at the MBR).
352Note that of an extended partition only the Id and the start
353are used. There are various conventions about what to write
354in the other fields. One should not try to use extended partitions
355for data storage or swap.
356
357.SH "INPUT FORMAT"
358.B sfdisk
359reads lines of the form
360.br
361.RS
362<start> <size> <id> <bootable> <c,h,s> <c,h,s>
363.RE
364where each line fills one partition descriptor.
365.LP
366Fields are separated by whitespace, or comma or semicolon possibly
367followed by whitespace; initial and trailing whitespace is ignored.
368Numbers can be octal, decimal or hexadecimal, decimal is default.
369When a field is absent or empty, a default value is used.
370.LP
371The <c,h,s> parts can (and probably should) be omitted -
372.B sfdisk
373computes them from <start> and <size> and the disk geometry
374as given by the kernel or specified using the \-H, \-S, \-C flags.
375.LP
376Bootable is specified as [*|\-], with as default not-bootable.
377(The value of this field is irrelevant for Linux - when Linux
378runs it has been booted already - but might play a role for
379certain boot loaders and for other operating systems.
380For example, when there are several primary DOS partitions,
381DOS assigns C: to the first among these that is bootable.)
382.LP
383Id is given in hex, without the 0x prefix, or is [E|S|L|X], where
384L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E
385is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
386.LP
387The default value of start is the first nonassigned sector/cylinder/...
388.LP
389The default value of size is as much as possible (until next
390partition or end-of-disk).
391.LP
392However, for the four partitions inside an extended partition,
393the defaults are: Linux partition, Extended partition, Empty, Empty.
394.LP
395But when the \-N option (change a single partition only) is given,
396the default for each field is its previous value.
397
398.SH EXAMPLE
399The command
400.RS
401.nf
402.if t .ft CW
403sfdisk /dev/hdc << EOF
4040,407
405,407
406;
407;
408EOF
409.if t .ft R
410.fi
411.RE
412will partition /dev/hdc just as indicated above.
413
414With the \-x option, the number of input lines must be a multiple of 4:
415you have to list the two empty partitions that you never want
416using two blank lines. Without the \-x option, you give one line
417for the partitions inside a extended partition, instead of four,
418and terminate with end-of-file (^D).
419(And
420.B sfdisk
421will assume that your input line represents the first of four,
422that the second one is extended, and the 3rd and 4th are empty.)
423
424.SH "DOS 6.x WARNING"
425
426The DOS 6.x FORMAT command looks for some information in the first
427sector of the data area of the partition, and treats this information
428as more reliable than the information in the partition table. DOS
429FORMAT expects DOS FDISK to clear the first 512 bytes of the data area
430of a partition whenever a size change occurs. DOS FORMAT will look at
431this extra information even if the /U flag is given -- we consider
432this a bug in DOS FORMAT and DOS FDISK.
433.LP
434The bottom line is that if you use sfdisk to change the size of a
435DOS partition table entry, then you must also use
436.B dd
437to zero the first 512 bytes of that partition before using DOS FORMAT to
438format the partition. For example, if you were using sfdisk to make a DOS
439partition table entry for /dev/hda1, then (after exiting sfdisk and
440rebooting Linux so that the partition table information is valid) you
441would use the command "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to zero
442the first 512 bytes of the partition.
443.B BE EXTREMELY CAREFUL
444if you use the
445.B dd
446command, since a small typo can make all of the data on your disk useless.
447
448For best results, you should always use an OS-specific partition table
449program. For example, you should make DOS partitions with the DOS FDISK
450program and Linux partitions with the Linux sfdisk program.
451
452.SH "DRDOS WARNINGS"
453
454Stephen Tweedie reported (930515): `Most reports of superblock
455corruption turn out to be due to bad partitioning, with one filesystem
456overrunning the start of the next and corrupting its superblock.
457I have even had this problem with the supposedly-reliable DRDOS. This
458was quite possibly due to DRDOS-6.0's FDISK command. Unless I created
459a blank track or cylinder between the DRDOS partition and the
460immediately following one, DRDOS would happily stamp all over the
461start of the next partition. Mind you, as long as I keep a little
462free disk space after any DRDOS partition, I don't have any other
463problems with the two coexisting on the one drive.'
464
465A. V. Le Blanc writes in README.esfdisk: `Dr. DOS 5.0 and 6.0 has been
466reported to have problems cooperating with Linux, and with this version
467of efdisk in particular. This efdisk sets the system type
468to hexadecimal 81. Dr. DOS seems to confuse
469this with hexadecimal 1, a DOS code. If you use Dr. DOS, use the
470efdisk command 't' to change the system code of any Linux partitions
471to some number less than hexadecimal 80; I suggest 41 and 42 for
472the moment.'
473
474A. V. Le Blanc writes in his README.fdisk: `DR-DOS 5.0 and 6.0
475are reported to have difficulties with partition ID codes of 80 or more.
476The Linux `fdisk' used to set the system type
477of new partitions to hexadecimal 81. DR-DOS seems to confuse this with
478hexadecimal 1, a DOS code. The values 82 for swap and 83 for file
479systems should not cause problems with DR-DOS. If they do, you may use
480the `fdisk' command `t' to change the system code of any Linux
481partitions to some number less than hexadecimal 80; I suggest 42 and 43
482for the moment.'
483
484In fact, it seems that only 4 bits are significant for the DRDOS FDISK,
485so that for example 11 and 21 are listed as DOS 2.0. However, DRDOS
486itself seems to use the full byte. I have not been able to reproduce
487any corruption with DRDOS or its fdisk.
488
489.SH BUGS
490A corresponding interactive
491.B cfdisk
492(with curses interface) is still lacking.
493.LP
494There are too many options.
495
496.SH AUTHOR
497A. E. Brouwer (aeb@cwi.nl)