一.磁盘分区
装过系统后第一块磁盘的设备号是/dev/sda,在你添加一个新的磁盘后一般情况下是/dev/sdb
*******进入fdisk界面*****
# 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 0xa64fcc39.
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').
*****p参数显示磁盘分区信息*****
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xa64fcc39
Device Boot Start End Blocks Id System
*****n参数创建分区******
创建主分区
Command (m for help): n
Command action
e extended //扩展分区
p primary partition (1-4) //主分区
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +1G
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xa64fcc39
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
*****创建扩展分区******
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (133-652, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-652, default 652):
Using default value 652
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xa64fcc39
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb4 133 652 4176900 5 Extended
*****创建逻辑分区*****
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (133-652, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-652, default 652): +1G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (265-652, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-652, default 652):
Using default value 652
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xa64fcc39
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb4 133 652 4176900 5 Extended
/dev/sdb5 133 264 1060258+ 83 Linux
/dev/sdb6 265 652 3116578+ 83 Linux
*****保存分区设置并退出fdisk*************
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
***********注意:初学者一般认为到这里就可以使用新磁盘了,但是却不是这样的,还要进行,创建文件系统,挂载文件系统后才可以使用*********
二.创建文件系统
mkfs命令创建文件系统
mkfs -t [文件系统类型] [磁盘设备名]
-t :指定要创建哪一种文件系统
Linux系统内核可以支持几十种文件系统类型;1) ext2文件系统应该说是Linux正宗的文件系统,早期的Linux都是用ext2,但随着技术的发展,大多Linux的发行版本目前并不用这个文件系统了;比如Redhat和Fedora大多都建议用ext3 ,ext3文件系统是由ext2发展而来的。对于Linux新手,我们还是建议您不要用ext2文件系统;ext2支持undelete(反删除),如果您误删除文件,有时是可以恢复的,但操作上比较麻烦; ext2支持大文件; ext2文件系统的官方主页是: 2)ext3 文件系统:是由ext2文件系统发展而来; ext3 is a Journalizing file system for Linux(ext3是一个用于Linux的日志文件系统),ext3支持大文件;但不支持反删除(undelete)操作; Redhat和Fedora都力挺ext3;至于ext3文件系统的更多特性,请访问《Linux文件系统(filesystem)资源索引》 ; 3)reiserfs 文件系统; reiserfs文件系统是一款优秀的文件系统,支持大文件,支持反删除(undelete);在我的测试ext2、reiserfs反删除文件功能的过程中,我发现reiserfs文件系统表现的最为优秀,几乎能恢复90%以上的数据,有时能恢复到100%;操作反删除比较容易;reiserfs支持大文件; 4)、Linux 支持的文件系统; Linux目前几乎支持所有的Unix类的文件系统,除了我们在安装Linux操作系统时所要选择的ext3、reiserfs和ext2外,还支持苹果MACOS的HFS,也支持其它Unix操作系统的文件系统,比如XFS、JFS、Minix fs及UFS等,您可以在kernel的源码中查看;如果您想要让系统支持哪些的文件系统得需要把该文件系统编译成模块或置入内核; 当然Linux也支持Windows文件系统NTFST和fat,但不支持NTFS文件系统的写入;支持fat文件系统的读写 Linux也支持网络文件系统,比如NFS等;
# mkfs -t ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265064 blocks
13253 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@seven ~]# mkfs -t ext3 /dev/sdb4
mke2fs 1.41.12 (17-May-2010)
mkfs.ext3: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).
三.挂载和卸载文件系统
******使用mount和umount命令可以实现挂载和卸载功能,这样用户才可以使用相应的设备存储数据*******
设置需要放置文件系统的目录/mnt/kk;然后将/dev/sdb1挂载到该目录中
# mkdir /mnt/kk
# mount /dev/sdb1 /mnt/kk、
查看/mnt/kk ,其中没有任何文件
# ls /mnt/kk
lost+found
# mkdir /mnt/kk/test
# ls /mnt/kk
lost+found test
使用df命令查看分区信息
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 18244476 2727168 14583884 16% /
tmpfs 969900 76 969824 1% /dev/shm
/dev/sda1 194241 28677 155324 16% /boot
/dev/sr0 3116336 3116336 0 100% /media/RHEL-6.6 Server.i386
/dev/sdb1 1043548 34112 956424 4% /mnt/kk
卸载文件系统
# umount /dev/sdb1
# ls /mnt/kk
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 18244476 2726532 14584520 16% /
tmpfs 969900 76 969824 1% /dev/shm
/dev/sda1 194241 28677 155324 16% /boot
/dev/sr0 3116336 3116336 0 100% /media/RHEL-6.6 Server.i386
****将某个分区或设备挂载了以后才能使用,但是当计算机重启以后,有需要重新挂载这个时候可以通过修改/etc/fstab文件实现开机自动挂载文件系统
[root@seven ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Nov 28 21:56:53 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=125de97e-b784-4948-bc00-7dbfdc11c8a5 / ext4 defaults 1 1
UUID=e69780c7-d8f5-4d34-a7a7-8abe01c2299c /boot ext4 defaults 1 2
UUID=2b532692-271a-4f6b-845f-b07a271c603f swap swap defaults 0 0
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
在/etc/fstab的最下面一行加上,使/dev/sdb1开机自动挂载
/dev/sdb1 /mnt/kk ext3 defaults 0 0