linux下磁盘分区与格式化
先使用fdisk -l 列出设备的分区。我这里的/dev/sdb 磁盘是我向运行在virtualbox中的虚拟机
添加的虚拟磁盘。顺便来说下往运行在virtualbox 中的系统添加虚拟磁盘的方法。首先在virtualbox
的用户界面中选中要添加虚拟磁盘的虚拟机(虚拟机应该是关停的),单击设置,进入选中虚拟机的
设置界面,选择存储,进入选中虚拟机的存储设置界面,然后选择添加虚拟磁盘(添加的是.vdi格式
的虚拟磁盘),后面根据向导设置就好。
[root@zeng ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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/sdb doesn't contain a valid partition table
Disk /dev/sda: 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: 0x000a0d66
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 2177 17280000 83 Linux
/dev/sda3 2177 2611 3481600 82 Linux swap / Solaris
那个/dev/sdb 就是我们需要分区,格式化,挂载的设备。
再来看下系统已经挂载的设备。
[root@zeng ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 17008476 15287828 856648 95% /
tmpfs 603748 0 603748 0% /dev/shm
/dev/sda1 198337 24175 163922 13% /boot
使用fdisk 对设备/dev/sdb 进行分区。
[root@zeng ~]# fdisk /dev/sdb
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)
//使用p 列出设备现有的分区。
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xd7ea6b16
Device Boot Start End Blocks Id System
//因为我还没有对这个设备进行分区,所有没有分区信息。使用n 新增一个
分区。
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
//选择扩展分区(对应 e) 因为我的系统中已经存在3个主分区了。并把所有的
/dev/sdb 设备的所有的空间分给扩展分区。
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044):
Using default value 1044
//再次打印该设备的分区表。
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xd7ea6b16
//已经有一个扩展分区存在。
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 5 Extended
把上面操作写入磁盘分区表,并退出。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
再来查看下设备的分区是由有误。
[root@zeng ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xd7ea6b16
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 5 Extended
Disk /dev/sda: 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: 0x000a0d66
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 2177 17280000 83 Linux
/dev/sda3 2177 2611 3481600 82 Linux swap / Solaris
到现在为止我们只是创建了一个扩展分区,但是扩展分区是不能用来格式化的,所以我们
需要继续进行磁盘分区,创建逻辑分区。
[root@zeng ~]# fdisk /dev/sdb
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): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xd7ea6b16
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
//现在l 表示逻辑分区。
l
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044):
Using default value 1044
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
现在再来查看 /dev/sdb 的设备分区表。
[root@zeng ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xd7ea6b16
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 5 Extended
/dev/sdb5 1 1044 8385867 83 Linux
已经多出一个/dev/sdb5了。逻辑分区是从5开始编号的。下面对新创建的
逻辑分区/dev/sdb5 进行格式化,我这里现在ext3 文件系统。
[root@zeng ~]# mkfs -t ext3 /dev/sdb5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
//该文件系统的块大小是4KB。
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096466 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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
Writing inode tables: done
Creating journal (32768 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.
块大小的设置还是比较关键的参数,设置的大些有利于提高文件系统的
读写性能,但是如果系统存储的大多是很小的文件,存储空间的浪费将会比较
严重。比如如果操作系统中存储了很多容量比4KB小的多的文件,比如1KB,2KB
那么将会严重浪费系统的存储空间。所有在格式分区选择块大小的时候,先要
分析下将来设备(分区)用途(用来存放什么样的文件)。当然block size 的
大小影响不限以此。
分区分好了,也格式化好了,但是系统是不会把该文件系统自动挂载起来的。
[root@zeng ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 17008476 15295336 849140 95% /
tmpfs 603748 0 603748 0% /dev/shm
/dev/sda1 198337 24175 163922 13% /boot
先创建一个挂载点。
[root@zeng ~]# mkdir /mnt/sdb5
进行挂载。
[root@zeng ~]# mount /dev/sdb5 /mnt/sdb5
再来设备的挂载情况。
[root@zeng ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 17008476 15295340 849136 95% /
tmpfs 603748 0 603748 0% /dev/shm
/dev/sda1 198337 24175 163922 13% /boot
/dev/sdb5 8254208 149624 7685292 2% /mnt/sdb5
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26110315/viewspace-719509/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26110315/viewspace-719509/