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