- 论坛徽章:
- 0
|
Examples of the use of sfdisk 3.0 (to partition a disk)
Input lines have fields ,,... - see sfdisk.8.
Usually no is given, and input lines start with a comma.
Before doing anything with a disk, make sure it is not in use;
unmount all its file systems, and say swapoff to its swap partitions.
(The final BLKRRPART ioctl will fail if anything else still uses
the disk, and you will have to reboot. It is easier to first make
sure that nothing uses the disk, e.g., by testing:
% umount /dev/sdb1
% sfdisk -R /dev/sdb
BLKRRPART: Device or resource busy
* Device busy for revalidation (usage=2)
% swapoff /dev/sdb3
% sfdisk -R /dev/sdb
* sdb: sdb1 sdb3
%
Note that the starred messages are kernel messages, that may be
logged somewhere, or written to some other console.
In sfdisk 3.01 sfdisk automatically does this check, unless told not to.)
1. One big partition:
sfdisk /dev/hda =32M
/dev/hda3 51+ 203 153- 156468 5 Extended
/dev/hda4 0 - 0 0 0 Empty
/dev/hda5 51+ 71- 21- 20603+ 4 DOS 16-bit FAT
-----------------------------------------------------------------------
All these rounded numbers look better in cylinder units:
% sfdisk -l /dev/hda
-----------------------------------------------------------------------
Device Boot Start End #cyls #blocks Id System
/dev/hda1 0+ 5 6- 1223+ a OS/2 Boot Manager
/dev/hda2 6 256 251 51204 6 DOS 16-bit FAT >=32M
/dev/hda3 257 1023 767 156468 5 Extended
/dev/hda4 0 - 0 0 0 Empty
/dev/hda5 257+ 357 101- 20603+ 4 DOS 16-bit FAT =32M
/dev/hda3 257 1023 767 156468 5 Extended
/dev/hda4 0 - 0 0 0 Empty
/dev/hda5 257+ 357 101- 20603+ 4 DOS 16-bit FAT =32M
7 OS/2 HPFS or QNX or Advanced UNIX
8 AIX data
9 AIX boot or Coherent
a OS/2 Boot Manager
...
4. Preserving the sectors changed by sfdisk.
% sfdisk -O save-hdd-partition-sectors /dev/hda
...
will write the sectors overwritten by sfdisk to file.
If you notice that you trashed some partition, you may
be able to restore things by
% sfdisk -I save-hdd-partition-sectors /dev/hda
%
5. Preserving some old partitions.
% sfdisk -N2 /dev/hda
...
will only change the partition /dev/hda2, and leave the rest
unchanged. The most obvious application is to change an Id:
% sfdisk -N7 /dev/hda
,,63
%
-----------------------------------------------------------------------
Old situation:
Device Boot Start End #cyls #blocks Id System
/dev/hda1 0+ 5 6- 1223+ a OS/2 Boot Manager
...
/dev/hda6 358+ 438 81- 16523+ 82 Linux swap
/dev/hda7 439+ 1023 585- 119339+ 83 Linux native
New situation:
Device Boot Start End #cyls #blocks Id System
/dev/hda1 0+ 5 6- 1223+ a OS/2 Boot Manager
...
/dev/hda6 358+ 438 81- 16523+ 82 Linux swap
/dev/hda7 439+ 1023 585- 119339+ 63 GNU HURD
-----------------------------------------------------------------------
Note that changing a logical partition into an empty partition
will decrease the number of all subsequent logical partitions.
6. Deleting a partition.
At first I thought of having an option -X# for deleting partitions,
but there are several ways in which a partition can be deleted, and
it is probably better to handle this just as a general change.
% sfdisk -d /dev/hda > ohda
will write the current tables on the file `ohda'.
-----------------------------------------------------------------------
% cat ohda
# partition table of /dev/hda
unit: sectors
/dev/hda1 : start= 1, size= 40799, Id= 5
/dev/hda2 : start= 40800, size= 40800, Id=83
/dev/hda3 : start= 81600, size= 336192, Id=83
/dev/hda4 : start= 0, size= 0, Id= 0
/dev/hda5 : start= 2, size= 40798, Id=83
-----------------------------------------------------------------------
In order to delete the partition on /dev/hda3, edit this file
and feed the result to sfdisk again.
-----------------------------------------------------------------------
% emacs ohda
% cat ohda
# partition table of /dev/hda
unit: sectors
/dev/hda1 : start= 1, size= 40799, Id= 5
/dev/hda2 : start= 40800, size= 40800, Id=83
/dev/hda3 : start= 0, size= 0, Id= 0
/dev/hda4 : start= 0, size= 0, Id= 0
/dev/hda5 : start= 2, size= 40798, Id=83
% sfdisk /dev/hda
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72643/showart_1072581.html |
|