使用 fdisk /dev/vdb 进入磁盘设备进行操作, 可以进行分区、保存分区表、打印分区表等等操作
$ fdisk /dev/vdbWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0x11171dc8.
以下是一些常用的命令:
m打开帮助n添加新分区p打印分区表w保存分区表并退出q不保存分区表并退出l列出所有支持的分区格式
获取帮助 (m)
Command (m for help): mCommand actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)
列出所有支持的分区格式 (l)
Command (m for help): l0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS accessa OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/Ob W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStorc W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fse W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPTf W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT1e Hidden W95 FAT1 80 Old Minix
创建新分区 (n)
- Partition type 分区类型 (直接回车就好)
- p: 主分区
- e: 扩展分区
- Partition number 分区序号 (直接回车就好)
- First sector 起始扇区 (直接回车就好)
- Last sector 分区大小, 输入 +100G 表示为此分区分配 100G 的空间
Command (m for help): nPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p):Using default response pPartition number (1-4, default 1):First sector (2048-1048575999, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): +100GPartition 1 of type Linux and of size 100 GiB is set
多次输入 n 命令, 可对磁盘进行多个分区划分
打印分区表 (p)
创建完分区后, 使用 p 命令打印分区表
Command (m for help): pDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x11171dc8Device Boot Start End Blocks Id System/dev/vdb1 2048 209717247 104857600 83 Linux/dev/vdb2 209717248 419432447 104857600 83 Linux/dev/vdb3 419432448 629147647 104857600 83 Linux/dev/vdb4 629149696 1048575999 209713152 83 Linux
保存分区表 (w)
使用 w 命令对已划分的分区表进行保存
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
查看新的磁盘设备
创建完分区表并退出后, 使用 ls /dev/vdb* 可以看到, 已划分的4个分区都已出现
$ ls /dev/vdb*/dev/vdb /dev/vdb1 /dev/vdb2 /dev/vdb3 /dev/vdb4
再次使用 fdisk -l 查看磁盘信息
fdisk -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0008d73aDevice Boot Start End Blocks Id System/dev/vda1 * 2048 83884031 41940992 83 LinuxDisk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x11171dc8Device Boot Start End Blocks Id System/dev/vdb1 2048 209717247 104857600 83 Linux/dev/vdb2 209717248 419432447 104857600 83 Linux/dev/vdb3 419432448 629147647 104857600 83 Linux/dev/vdb4 629149696 1048575999 209713152 83 LinuxDisk /dev/mapper/vg_f08a5cd7b4e31c2b93f7d6c385860882-brick_3d7dc9f1e6346efc7361d0f4ec4ddf8c: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 262144 bytes / 262144 bytesDisk /dev/mapper/vg_f08a5cd7b4e31c2b93f7d6c385860882-brick_0027aec42ae3a4b5171cc7fddea50bc0: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 262144 bytes / 262144 bytes
可以看到 /dev/vdb 的4个分区都已分配。
分区格式化
使用 mkfs 进行磁盘格式化, 通过 -t 选项指定文件系统的格式
$ mkfs -t ext3 /dev/vdb1mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks6553600 inodes, 26214400 blocks1310720 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296800 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information:done
