knoppix@Microknoppix:~$ su -
root@Microknoppix:~# fdisk /dev/sda
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):
大多数磁盘拥有超过 1024 个柱面,因此您通常会看到清单 3 中显示的警告。类型 m 将显示一个可用的单字母命令列表,如清单 4 所示。
清单 4. fdisk 中的帮助
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
使用 p 命令来显示这个特定磁盘上的现有分区,清单 5 显示输出。
清单 5. 显示现有分区表
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9634 9730 779152+ 83 Linux
/dev/sda3 9731 116679 859067842+ 5 Extended
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
Command (m for help):
这个特殊磁盘是一个 1TB 磁盘,包含一个略低于 80GB 的 Windows/XP 分区。它是一个主分区,标记为 bootable,这是 Windows 系统的典型特征。
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Selected partition 4
First cylinder (9112-121601, default 9112):
Using default value 9112
Last cylinder, +cylinders or +size{K,M,G} (9112-9633, default 9633): +521
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9634 9730 779152+ 83 Linux
/dev/sda3 9731 116679 859067842+ 5 Extended
/dev/sda4 9112 9633 4192965 83 Linux
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
Command (m for help): n
First cylinder (53906-116679, default 53906):
Using default value 53906
Last cylinder, +cylinders or +size{K,M,G} (53906-116679, default 116679): +40G
Command (m for help): n
First cylinder (59129-116679, default 59129):
Using default value 59129
Last cylinder, +cylinders or +size{K,M,G} (59129-116679, default 116679): +2000M
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9634 9730 779152+ 83 Linux
/dev/sda3 9731 116679 859067842+ 5 Extended
/dev/sda4 9112 9633 4192965 83 Linux
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
/dev/sda8 53906 59128 41953716 83 Linux
/dev/sda9 59129 59384 2056288+ 83 Linux
Command (m for help): t
Partition number (1-9): 4
Hex code (type L to list codes): 82
Changed system type of partition 4 to 82 (Linux swap / Solaris)
Command (m for help): t
Partition number (1-9): 9
Hex code (type L to list codes): b
Changed system type of partition 9 to b (W95 FAT32)
Command (m for help):
保存分区表
到目前为止,我们只是对分区表进行了内存中编辑。我们可以用 q 命令退出,不保存更改。如果某些分区不能满足您的要求,您可以使用 d 命令来删除一个或多个分区,以便重新定义它们。如果您对设置满意,则可以使用 v 命令来验证您的设置,然后使用 w 命令来写入新的分区表并退出。参见清单 9。如果您再次运行 fdisk -l 命令,您将看到,Linux 现在已能够识别新分区。与其他操作系统不同的是,Linux 并不总是需要重新启动才能看到更改。举例来说,如果 /dev/hda3 变成 /dev/hda2,则需要重新启动,因为原来的 /dev/hda2 已被删除。如果需要重新启动,fdisk 应该会告诉您。
清单 9. 保存分区表
Command (m for help): v
999521580 unallocated 512-byte sectors
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
root@Microknoppix:~# fdisk -l /dev/sda
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9634 9730 779152+ 83 Linux
/dev/sda3 9731 116679 859067842+ 5 Extended
/dev/sda4 9112 9633 4192965 82 Linux swap / Solaris
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
/dev/sda8 53906 59128 41953716 83 Linux
/dev/sda9 59129 59384 2056288+ b W95 FAT32
Partition table entries are not in disk order
高级 fdisk
您可能已注意到,我们没有更改任意分区上的 bootable 标志。现在,我们的磁盘还有 Windows Master Boot Record (MBR),因此将启动标记为 bootable 的第一个主分区(我们的示例中为 NTFS 分区)。
LILO 和 GRUB 都不使用 bootable 标志。如果其中一个安装在 MBR 中,那么它就能够引导 Windows/XP 分区。您也可以将 LILO 或 GRUB 安装到您的 /boot 分区(/dev/hda2)中,将该分区标记为 bootable 并移除 /dev/hda1 的 bootable 标志。如果机器今后将恢复为 Windows 专用机器,那么保留原始 MBR 可能会有用。
如果需要,您还可以使用 fdisk 来修复分区表中的分区顺序。这通常将会更改分区编号,因此您可能需要完成其他工作才能将您的系统恢复为工作系统。要进行这个更改,使用 f 子命令切换到专家模式,然后使用 r 子命令修复分区顺序,如清单 10 所示。如果您只是想看看新的分区顺序而不实际更改,可以使用 q 子命令退出(本例的做法),而不是将更新后的分区表写到磁盘中。
清单 10. 修复分区表顺序
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9634 9730 779152+ 83 Linux
/dev/sda3 9731 116679 859067842+ 5 Extended
/dev/sda4 9112 9633 4192965 82 Linux swap / Solaris
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
/dev/sda8 53906 59128 41953716 83 Linux
/dev/sda9 59129 59384 2056288+ b W95 FAT32
Partition table entries are not in disk order
Command (m for help): x
Expert command (m for help): f
Done.
Expert command (m for help): r
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000de20f
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9111 73184076 7 HPFS/NTFS
/dev/sda2 9112 9633 4192965 82 Linux swap / Solaris
/dev/sda3 9634 9730 779152+ 83 Linux
/dev/sda4 9731 116679 859067842+ 5 Extended
/dev/sda5 9731 20917 89859546 83 Linux
/dev/sda6 20918 39644 150424596 83 Linux
/dev/sda7 39645 53905 114551451 83 Linux
/dev/sda8 53906 59128 41953716 83 Linux
/dev/sda9 59129 59384 2056288+ b W95 FAT32
vfat 文件系统(也称为 FAT32)没有日志功能,且缺乏完整的 Linux 文件系统实现所需的许多特性。它可用于在 Windows 和 Linux 系统之间交换数据,因为 Windows 和 Linux 都能读取它。不要将这个文件系统用于 Linux,除非要在 Windows 和 Linux 之间共享数据。如果您在一个 vfat 磁盘上解压缩一个 Linux 归档文件,那么您将丢失权限(比如执行权限),还会丢失该归档文件中可能存储的符号链接。
[root@echidna ~]# mkfs -t ext3 /dev/sda8
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2624496 inodes, 10488429 blocks
524421 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
321 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624