在linux系统下面经常要使用到fdisk对硬盘进行分区
一、查看系统硬盘信息
[root@zabbix-c1 ~]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x00049d20 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 281 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 281 26109 207461376 83 Linux Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x00000000 Disk /dev/sdc: 3221.2 GB, 3221225472000 bytes 255 heads, 63 sectors/track, 391625 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: 0x00000000
二、通过查看结果可以看到,系统中有3块硬盘,分别是/dev/sda,/dev/sdb,/dev/sdc。
对/dev/sdb进行分区
[root@zabbix-c1 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xc1760957. 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‘). #输入m显示帮助信息 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) #输入n创建一个新分区 Command (m for help): n Command action e extended #表示扩展分区 p primary partition (1-4) #表示主分区 #输入p,创建主分区 p Partition number (1-4): 1 #输入主分区标号,最多只能有4个主分区 First cylinder (1-2610, default 1): Using default value 1 #输入+200M,表示创建一个200M的分区 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M #输入p查看分区信息 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0xc1760957 Device Boot Start End Blocks Id System /dev/sdb1 1 26 208813+ 83 Linux #输入w,将分区信息写入磁盘中 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
通过fdisk再次查看硬盘信息,查看是否有新创建的硬盘存在。
[root@zabbix-c1 ~]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x00049d20 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 281 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 281 26109 207461376 83 Linux Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0xc1760957 #刚才对/dev/sdb创建的200M分区已显示出来 Device Boot Start End Blocks Id System /dev/sdb1 1 26 208813+ 83 Linux Disk /dev/sdc: 3221.2 GB, 3221225472000 bytes 255 heads, 63 sectors/track, 391625 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: 0x00000000
将分区挂载到/data目录下
#修改的分区信息刷新到内核中 [root@zabbix-c1 ~]# partprobe /dev/sdb1 #将分区格式化成ext4文件系统 [root@zabbix-c1 ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 52208 inodes, 208812 blocks 10440 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 26 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 创建挂载目录并挂载 [root@zabbix-c1 ~]# mkdir /data [root@zabbix-c1 ~]# mount /dev/sdb1 /data 3查看挂载后的结果 [root@zabbix-c1 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 195G 1.4G 184G 1% / tmpfs 495M 0 495M 0% /dev/shm /dev/sda1 194M 28M 156M 16% /boot /dev/sdb1 198M 5.8M 182M 4% /data #新创建的200M分区已经能够使用
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1641620
原文地址:http://ly36843.blog.51cto.com/3120113/1641620