在虚拟机中为虚拟机linux添加一个2G容量的SCSI硬盘,启动系统
一,查看系统磁盘
- root@ubuntu-server:/dev# ls -l /dev |grep -e 'sd[a-z]'
- brw-rw---- 1 root disk 8, 0 2012-05-06 06:13 sda
- brw-rw---- 1 root disk 8, 1 2012-05-05 22:14 sda1
- brw-rw---- 1 root disk 8, 2 2012-05-06 06:13 sda2
- brw-rw---- 1 root disk 8, 5 2012-05-06 06:13 sda5
- brw-rw---- 1 root disk 8, 16 2012-05-06 06:13 sdb
可以看到系统有两块磁盘sda,sdb
二,使用fdisk磁盘分区工具对sdb新盘分区
- root@ubuntu-server:/dev# fdisk /dev/sdb
- Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
- Building a new DOS disklabel. 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)
- Command (m for help):
根据提示键入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)
提示是创建主分区还是扩展分区
注意:如果已经有扩展分区,系统会问,是要新增主分区还是逻辑分区,如果还没有扩展分区,系统会问,是要新增主分区还是扩展分区。如果已经用完4个主分区+扩展分区,那么就只有逻辑分区可以选择。
键入p,创建主分区
- p
- Partition number (1-4): 1(分区编号,可随意)
- First cylinder (1-261, default 1): (分区开始柱面)
- Using default value 1
- Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 150(分区结束柱面)
键入p可查看当前分区状态,键入w,使分区生效(或键入q,取消退出)
- Command (m for help): p
- Disk /dev/sdb: 2147 MB, 2147483648 bytes
- 255 heads, 63 sectors/track, 261 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 150 1204843+ 83 Linux
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
用同样的方式可以把余下的磁盘空间分成主分区或扩展分区
二,使用mke2fs格式化分区
磁盘分区后必须格式化才能挂载到系统中使用
首先查看sdb盘分区
- root@ubuntu-server:/dev# ls -l /dev |grep -e 'sdb'
- brw-rw---- 1 root disk 8, 16 2012-05-05 22:59 sdb
- brw-rw---- 1 root disk 8, 17 2012-05-05 22:59 sdb1
- brw-rw---- 1 root disk 8, 18 2012-05-05 22:59 sdb2
格式化sdb1
- root@ubuntu-server:/dev# mke2fs -j /dev/sdb1(-j参数,会把分区文件系统主动升级为ext3)
- mke2fs 1.39 (29-May-2006)
- Filesystem label=
- OS type: Linux
- Block size=4096 (log=2)
- Fragment size=4096 (log=2)
- 150720 inodes, 301210 blocks
- 15060 blocks (5.00%) reserved for the super user
- ......
格式化sdb2
三,挂载分区
- root@ubuntu-server:~# mkdir /mnt/sdb1
- root@ubuntu-server:~# mkdir /mnt/sdb2
- root@ubuntu-server:~# mount -t ext3 /dev/sdb1 /mnt/sdb1
- root@ubuntu-server:~# mount -t ext3 /dev/sdb2 /mnt/sdb2
查看分区
- root@ubuntu-server:~# df
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/sda1 7882560 577604 6904540 8% /
- varrun 257944 52 257892 1% /var/run
- varlock 257944 0 257944 0% /var/lock
- procbususb 10240 96 10144 1% /proc/bus/usb
- udev 10240 96 10144 1% /dev
- devshm 257944 0 257944 0% /dev/shm
- /dev/sdb1 1185872 34584 1091048 4% /mnt/sdb1
- /dev/sdb2 877572 17296 815696 3% /mnt/sdb2
阅读(1739) | 评论(0) | 转发(0) |