
正文
Linux中磁盘分区、格式化、挂载等管理
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1. 添加磁盘,查看磁盘状况
[root@db1 /]# fdisk -l
Disk /dev/sda: 10.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Device Boot Start End Blocks Id System
/dev/sda1 * + Linux
/dev/sda2 + linux swap
Partition table entries are not in disk order
Disk /dev/sdb: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Device Boot Start End Blocks Id System
从结果看出,多了一个/dev/sdb的盘
2. 用fdisk 对/dev/sdb 进行分区
[root@db1 /]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder or +size or +sizeM or +sizeK (-, default ):
Using default value Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
再次查看分区情况,多出来一个/dev/sdb1 的区,这个1是我们在前面指定的,如果我们指定2,就变成 sdb2了。
[root@db1 /]# fdisk -l Disk /dev/sda: 10.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Device Boot Start End Blocks Id System
/dev/sda1 * + Linux
/dev/sda2 + Linux swap
Partition table entries are not in disk order Disk /dev/sdb: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
[root@db1 /]#
如果创建完之后,/proc/partitions 查看不到对应的分区,使用parprobe 命令刷新一下就可以了:
[root@web1 ~]# cat /proc/partitions
major minor #blocks name sda
sda1
sda2
sda3
[root@web1 ~]# partprobe /dev/sda
[root@web1 ~]# cat /proc/partitions
major minor #blocks name sda
sda1
sda2
sda3
sda4
[root@web1 ~]#
3. 格式化 /dev/sdb1 分区
[root@db1 /]# mkfs -t ext3 /dev/sdb1
mke2fs 1.35 (-Feb-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
4. 创建目录 并将 /dev/sdb1 挂在到该目录下
[root@db1 /]# ls
backup dev initrd media opt sbin sys usr
bin etc lib misc proc selinux tftpboot var
boot home lost+found mnt root srv tmp
[root@db1 /]# mkdir /u01
[root@db1 /]# ls
backup dev initrd media opt sbin sys u01
bin etc lib misc proc selinux tftpboot usr
boot home lost+found mnt root srv tmp var
[root@db1 /]# mount /dev/sdb1 /u01
5. 验证挂载是否成功
[root@db1 /]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 % /
none % /dev/shm
/dev/sdb1 % /backup
6. 设置开机自动挂载
[root@db1 /]# vi /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults
none /dev/pts devpts gid=,mode=
none /dev/shm tmpfs defaults
none /proc proc defaults
none /sys sysfs defaults
LABEL=SWAP-sda2 swap swap defaults
/dev/sdb1 /u01 ext3 defaults
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,m
anaged
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,m
anaged
本文摘自:http://blog.csdn.net/tianlesoftware/article/details/5642883,感谢原作者分享。







