查看硬盘信息:fdisk -l
磁盘1:/dev/sda
磁盘2:/dev/sdb
磁盘1为系统盘,磁盘2为新增的硬盘,磁盘2为新盘,没分区。先将磁盘2分区。
查看磁盘信息的另一命令是:df
例如: df -h
查看硬盘格式:df -T
用man df 查看更多的参数
第二部分:分区
[root@minimal621 ~]# 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): m #查看menu,给出操作信息
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 #显示此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 #修改分区的ID号
u change display/entry units
v verify the partition table
w write table to disk and exit #退出并保存
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x82e698b5
Device Boot Start End Blocks Id System
#由此处信息可知,磁盘2没有任何分区
#下面新增一个分区:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1): #此处直接按回车即可,默认是从1开始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): 1024 #此处随便填写,主要是涉及分区的大小
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x82e698b5
Device Boot Start End Blocks Id System
/dev/sdb1 1 1024 8225248+ 83 Linux
#再次显示分区信息,此时可以看到刚刚分的ID为1的区:/dev/sdb1
#增加其他分区和上面的操作是一样的
#分区结果如下:
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x82e698b5
Device Boot Start End Blocks Id System
/dev/sdb1 1 1024 8225248+ 83 Linux
/dev/sdb2 1025 2048 8225280 83 Linux
/dev/sdb3 2049 5221 25487122+ 83 Linux
#最后按w保存退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第三部分:格式化分区
#下面格式化分区:
#linux的磁盘格式有ext2 ext3 ext4,我选用的是ext4,ext2、ext3的格式化是一样的
[root@minimal621 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
514080 inodes, 2056312 blocks
102815 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2109734912
63 block groups
32768 blocks per group, 32768 fragments per group
8160 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 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@minimal621 ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
514080 inodes, 2056320 blocks
102816 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2109734912
63 block groups
32768 blocks per group, 32768 fragments per group
8160 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 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@minimal621 ~]# mkfs.ext4 /dev/sdb3
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1594320 inodes, 6371780 blocks
318589 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
195 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@minimal621 ~]#
#运行fdisk -l 查看刚分好的磁盘:
[root@minimal621 ~]# fdisk -l
Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x000dfcad
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 10444 83782656 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x82e698b5
Device Boot Start End Blocks Id System
/dev/sdb1 1 1024 8225248+ 83 Linux
/dev/sdb2 1025 2048 8225280 83 Linux
/dev/sdb3 2049 5221 25487122+ 83 Linux
第四部分:加载分区
#分好以后,还无法直接使用,需要加载才能使用。后面会说到加载lvm分区。
#先建立分区加载位置,也就是文件夹
[root@minimal621 mnt]# ls
[root@minimal621 mnt]# cd /
[root@minimal621 /]# ls #准备建立一个sdb1文件夹用来加载/dev/sdb1分区,查看根目录下已有的文件夹
bin cgroup etc lib lost+found mnt oracle root selinux sys usr
boot dev home lib64 media opt proc sbin srv tmp var
[root@minimal621 /]# mkdir /sdb1 #在根目录下建立sdb1文件夹
[root@minimal621 /]# ls #查看 sdb1文件夹建立成功
bin dev lib media oracle sbin srv usr
boot etc lib64 mnt proc sdb1 sys var
cgroup home lost+found opt root selinux tmp
[root@minimal621 /]# ls /sdb1 #查看/sdb1文件夹下面是否有文件存在
[root@minimal621 /]# mount /dev/sdb1 /sdb1 #加载分区/dev/sdb1到/sdb1下
[root@minimal621 /]# ls /sdb1 #加载成功后查看/sdb1下有什么变化,多了一个lost+found文件夹,类似于微软的recycle
lost+found
[root@minimal621 /]# cd /sdb1
[root@minimal621 sdb1]# mkdir test #在分区/sdb1建立一个test文件夹
[root@minimal621 sdb1]# ll
total 20
drwx------ 2 root root 16384 Jan 10 00:32 lost+found
drwxr-xr-x 2 root root 4096 Jan 10 00:46 test
[root@minimal621 sdb1]# pwd #查看当前所在位置
/sdb1
[root@minimal621 sdb1]# touch test/test.txt #在test文件夹下建立一个test文本
[root@minimal621 sdb1]# ls
lost+found test
[root@minimal621 test]# cd #退出,即让/dev/sdb1不处于打开状态,否则无法umount
[root@minimal621 ~]# umount /dev/sdb1 #卸载/dev/sdb1
[root@minimal621 ~]# cd /sdb1
[root@minimal621 sdb1]# ls
[root@minimal621 sdb1]#
#上面是手动加载磁盘,但每次开机都要这样操作的话,会灰常蛋疼。或许有人会想到写个shell脚本,然后crontab -e 运行,这种人真是太有才。^_^
#我们可以通过修改 /etc/fstab 来让系统每次开机都加载/dev/sdb的分区:
#先看看fstab已有内容:
[root@chinesefonts ~]# find /etc/fstab
/etc/fstab
[root@chinesefonts ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Sep 20 18:52:32 2012
#
# 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
#
/dev/mapper/vg_chinesefonts-lv_root / ext4 defaults 1 1
UUID=40e54c98-37c6-4154-b142-a65cbfb40277 /boot ext4 defaults 1 2
/dev/mapper/vg_chinesefonts-lv_home /home ext4 defaults 1 2
/dev/mapper/vg_chinesefonts-lv_swap 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
[root@chinesefonts ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Sep 20 18:52:32 2012
#
# 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
#
/dev/mapper/vg_chinesefonts-lv_root / ext4 defaults 1 1
UUID=40e54c98-37c6-4154-b142-a65cbfb40277 /boot ext4 defaults 1 2
/dev/mapper/vg_chinesefonts-lv_home /home ext4 defaults 1 2
/dev/mapper/vg_chinesefonts-lv_swap 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
/dev/sdb1 /sdb1 ext4 defaults 0 0
/dev/sdb2 /mnt/sdb2 ext4 defaults 0 0
/dev/sdb3 /mnt/sdb3 ext4 defaults 0 0
#红色字体是自己添加上去的,这样每次开机都会自动加载/dev/sdb磁盘了
#那如何加载LVM的分区呢,我是这样做的,先查看lvm的分区table,再用table挂载上去的。
Device Boot Start End Blocks Id System
/dev/sdc1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdc2 13 2611 20868096 8e Linux LVM
#用 fdisk -l 查看磁盘,然后看磁盘信息,找到类似/dev/mapper/vg_centosminimal-LogVol01 的,再用mount加载即可
mkdir /mnt/lvm/01
mount /dev/mapper/vg_centosminimal-LogVol01 /mnt/lvm/01
#其中/dev/mapper/vg_centosminimal-LogVol01 是lvm的一个分区