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