fdisk分区相关操作(linux)

fdisk创建分区操作

[root@iZuf690mzf9cmk40rbz0ehZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        79G  2.0G   73G   3% /
tmpfs           499M     0  499M   0% /dev/shm
[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk -l	#查看分区详情

#以下信息表示,这个硬盘的大小是85.9GB,有255个磁面,63个扇区,10443 磁柱(cylinders),每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K
Disk /dev/vda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1       10444    83884032   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk /dev/vdb	#对空闲磁盘进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x1aa565d2.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n	 #建立一个新分区
Command action
   e   extended
   p   primary partition (1-4)	---指定分区类型  e为扩展分区   p为主分区
p
Partition number (1-4): 1	#分区号选择,定义分区数量 ,主分区最多只能有四个
First cylinder (1-41610, default 1): 	#设定起始分区的位置,硬盘空间可以用cylinder(磁柱)数来表示
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610): 	#设定结束分区的位置
Using default value 41610

Command (m for help): w	 #保存分区表
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZuf690mzf9cmk40rbz0ehZ ~]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/vda1      ext4    79G  2.0G   73G   3% /
tmpfs          tmpfs  499M     0  499M   0% /dev/shm
[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk -l

Disk /dev/vda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1       10444    83884032   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1aa565d2

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       41610    20971408+  83  Linux
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mount /dev/vdb1
mount: can't find /dev/vdb1 in /etc/fstab or /etc/mtab
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mount /dev/vdb1^C
[root@iZuf690mzf9cmk40rbz0ehZ ~]# ^C
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mksf.ext4 /dev/vdb1
-bash: mksf.ext4: command not found
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mkfs.ext4 /dev/vdb1  
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242852 blocks
262142 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mkdir /test
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mount /dev/sdb1 /test/
mount: you must specify the filesystem type
[root@iZuf690mzf9cmk40rbz0ehZ ~]# mount /dev/vdb1 /test/ 
[root@iZuf690mzf9cmk40rbz0ehZ ~]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/vda1      ext4    79G  2.0G   73G   3% /
tmpfs          tmpfs  499M     0  499M   0% /dev/shm
/dev/vdb1      ext4    20G  172M   19G   1% /test

fdisk使用解释

[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m	#输入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): 

删除fdisk分区

[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d	#删除一个分区
Selected partition 1	#显示删除分区的分区号

Command (m for help): p	#显示磁盘还有几个剩余分区(删除后)

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1aa565d2

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): w	#保存操作
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@iZuf690mzf9cmk40rbz0ehZ ~]# fdisk -l /dev/vdb	#查看已删除分区信息

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1aa565d2

   Device Boot      Start         End      Blocks   Id  System

你可能感兴趣的:(linux)