添加一块硬盘
1234567# fdisk -lDisk /dev/vdb: 53.7 GB, 53687091200 bytes16 heads, 63 sectors/track, 104025 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
用fdisk命令进入分区界面
12345678910# fdisk /dev/vdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xb5f18769.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):
12345678910111213Command (m for help): n // 输入n新建一个分区Command action e extended //e是扩展分区 p primary partition (1-4) //p是主分区p //选择pPartition number (1-4): 1 //分区号First cylinder (1-104025, default 1): //默认回车就行Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-104025, default 104025): 25600M //可以输入具体要分多少空间给这个分区,这里我分25G参考: //Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte)
分第二个分区
12345678910Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 2First cylinder (52015-104025, default 52015): Using default value 52015Last cylinder, +cylinders or +size{K,M,G} (52015-104025, default 104025): //这里直接回车默认所有空间Using default value 104025
查看刚刚分的2个区。可以看到vdb1和vdb2
1234567891011Command (m for help): p //输入p查看分区Disk /dev/vdb: 53.7 GB, 53687091200 bytes16 heads, 63 sectors/track, 104025 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb7a8f045 Device Boot Start End Blocks Id System/dev/vdb1 1 52014 26215024+ 83 Linux/dev/vdb2 52015 104025 26213544 83 Linux
保存分区退出(一定要保存,不然得重来了。)
1234Command (m for help): w //输入w保存退出The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
查看分好的分区
12345678910# fdisk -lDisk /dev/vdb: 53.7 GB, 53687091200 bytes16 heads, 63 sectors/track, 104025 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb7a8f045 Device Boot Start End Blocks Id System/dev/vdb1 1 52014 26215024+ 83 Linux/dev/vdb2 52015 104025 26213544 83 Linux
格式化分区
1mkfs.ext3 /dev/vdb1
1mkfs.ext3 /dev/vdb2
创建挂载文件夹
1mkdir /vdb1 /vdb2
挂载分区到文件夹
1mount /dev/vdb1 /vdb1# mount /dev/vdb2 /vdb2
分区完成,数据写入挂载的文件夹就写入到硬盘了。
但是重启之后linux不会自动挂载,需要在/etc/fstab文件添加后面2条。保存之后下次重启就会自动挂载了。
12345678# vim /etc/fstabtmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0/dev/vdb1 /vdb1 ext3 defaults 1 2/dev/vdb2 /vdb2 ext3 defaults 1 2
另外:可通过cat /proc/partitions 查看分区信息
12345678910[root@myslaver ~]# cat /proc/partitionsmajor minor #blocks name 252 0 52428800 vda 252 1 512000 vda1 252 2 7875584 vda2 252 16 52428800 vdb 252 17 26215024 vdb1 252 18 26213544 vdb2 253 0 7036928 dm-0 253 1 835584 dm-1