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