添加一块硬盘
# fdisk -l
Disk /dev/vdb: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 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
用fdisk命令进入分区界面
# 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 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):
Command (m for help): n // 输入n新建一个分区
Command action
e extended //e是扩展分区
p primary partition (1-4) //p是主分区
p //选择p
Partition number (1-4): 1 //分区号
First cylinder (1-104025, default 1): //默认回车就行
Using default value 1
Last 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)
分第二个分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (52015-104025, default 52015):
Using default value 52015
Last cylinder, +cylinders or +size{K,M,G} (52015-104025, default 104025): //这里直接回车默认所有空间
Using default value 104025
查看刚刚分的2个区。可以看到vdb1和vdb2
Command (m for help): p //输入p查看分区
Disk /dev/vdb: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 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: 0xb7a8f045
Device Boot Start End Blocks Id System
/dev/vdb1 1 52014 26215024+ 83 Linux
/dev/vdb2 52015 104025 26213544 83 Linux
保存分区退出(一定要保存,不然得重来了。)
Command (m for help): w //输入w保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查看分好的分区
# fdisk -l
Disk /dev/vdb: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 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: 0xb7a8f045
Device Boot Start End Blocks Id System
/dev/vdb1 1 52014 26215024+ 83 Linux
/dev/vdb2 52015 104025 26213544 83 Linux
格式化分区
# mkfs.ext3 /dev/vdb1
# mkfs.ext3 /dev/vdb2
创建挂载文件夹
# mkdir /vdb1 /vdb2
挂载分区到文件夹
# mount /dev/vdb1 /vdb1
# mount /dev/vdb2 /vdb2
分区完成,数据写入挂载的文件夹就写入到硬盘了。
但是重启之后linux不会自动挂载,需要在/etc/fstab文件添加后面2条。保存之后下次重启就会自动挂载了。
# vim /etc/fstab
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/vdb1 /vdb1 ext3 defaults 1 2
/dev/vdb2 /vdb2 ext3 defaults 1 2
另外:可通过cat /proc/partitions 查看分区信息
[root@myslaver ~]# cat /proc/partitions
major 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