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