大概步骤:
A.关闭服务器,安装新硬盘
B.开启服务器,新硬盘分区
C.对分区格式化
D.选择挂载点,加载,同步数据
E./etc/fstab文件,磁盘自动挂载
F.对于SWAP分区用特殊的方式进行格式化和挂载
检查系统的mount状况,这里看到SWAP空间是没有挂载点的
[root@localhost huxiaoming]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw) #特殊-内存地址空间相关#
sysfs on /sys type sysfs (rw) #特殊-硬件相关,例如总线配置#
devpts on /dev/pts type devpts (rw,gid=5,mode=620) #特殊-动态对应会话#
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0"
)
#内存空间作系统#
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /home type ext4 (rw)
/dev/sda5 on /tmp type ext4 (rw)
/dev/sda6 on /usr type ext4 (rw)
/dev/sda7 on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@localhost huxiaoming]# fdisk -l
Disk /dev/sda: 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: 0x000e5deb
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 1301 10240000 83 Linux
/dev/sda3 1301 2321 8192000 83 Linux
/dev/sda4 2321 5222 23305216 5 Extended
/dev/sda5 2321 2958 5120000 83 Linux
/dev/sda6 2959 3596 5120000 83 Linux
/dev/sda7 3596 4234 5120000 83 Linux
/dev/sda8 4234 4744 4096000 82 Linux swap / Solaris[root@localhost huxiaoming]# swapon –s #这里可以看到SWAP的位置#
Filename Type Size Used Priority /dev/sda8 partition 4095992 0 -1
开始关机
[root@localhost huxiaoming]# sync; sync; shutdown -H now
这里补一句:有人会问shutdown和init 0一样吗?
其实shutdown可以看成是init 0的上一层,规定了一系列动作,通知了大家之后才去调用init 0
添加硬盘:
我这里用的是ESXI,直接从存储上分10G硬盘过来
[root@localhost huxiaoming]# fdisk –l #这里可以看到SDB已经出来了#
Disk /dev/sda: 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: 0x000e5deb
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 1301 10240000 83 Linux
/dev/sda3 1301 2321 8192000 83 Linux
/dev/sda4 2321 5222 23305216 5 Extended
/dev/sda5 2321 2958 5120000 83 Linux
/dev/sda6 2959 3596 5120000 83 Linux
/dev/sda7 3596 4234 5120000 83 Linux
/dev/sda8 4234 4744 4096000 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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[root@localhost huxiaoming]# fdisk /dev/sdb #使用fdisk工具编辑此块硬盘# Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x908de78e.
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').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delet
e 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)
我们可以查看现有磁盘是如何分区的,可以看到使用的是83 linux分区方式Disk /dev/sda: 42.9 GB, 42949672960 bytes255 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: 0x000e5deb
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
#共有5221个柱面,sda1从第一柱面开始,到26柱面结束#
26个柱面* 8 M = 208 MB---- 哈哈是不是猜到它就是挂给boot了,记住这个公式# Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83Linux
/dev/sda3 1301 2321 8192000 83 Linux
/dev/sda4 2321 5222 23305216 5Extended
/dev/sda5 2321 2958 5120000 83 Linux
/dev/sda6 2959 3596 5120000 83 Linux
/dev/sda7 3596 4234 5120000 83 Linux
/dev/sda8 4234 4744 4096000 82 Linux swap / Solaris
此时我们回到fdisk /dev/sdb
Command (m for help): n # add a new partition 添加新的分区表#
Command action #采用扩展还是主分区,我们先划分主分区,前面章节有主分区和扩展分区的#
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
这里很好计算,可以用的柱面为1305*8MB的空间
我们可以自己调整柱面的范围,来看是否预留空间给前面的柱面,默认是从第一柱面开始
我们这里给第一个主分区分配2G的空间,只要输入+2G 就好了
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +2G
Command (m for help): p #print 输出一下看到了从1-262个柱面被占用分出了一个sdb1#
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x9cdf6057Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
剩下的263柱面到1305柱面我都想分给sdb2 如下执行
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (263-1305, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-1305, default 1305):
Using default value 1305
Command (m for help): p #输出结果可以看出,按照我们的意图,磁盘已经分好了# Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x9cdf6057
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 1305 83777+ 83 Linux
分完之后,我们要选择W选项,将刚才的划分,写入分区表
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost huxiaoming]# fdisk -l
Disk /dev/sda: 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: 0x000e5deb
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 1301 10240000 83 Linux
/dev/sda3 1301 2321 8192000 83 Linux
/dev/sda4 2321 5222 23305216 5 Extended
/dev/sda5 2321 2958 5120000 83 Linux
/dev/sda6 2959 3596 5120000 83 Linux
/dev/sda7 3596 4234 5120000 83 Linux
/dev/sda8 4234 4744 4096000 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x9cdf6057
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 1305 83777+ 83 Linux
分区完了要干嘛呢?和Windows一样,需要格式化。可以看到有如下文件格式类型[root@localhost huxiaoming]# mkfs
mkfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.ext4dev mkfs.msdos mkfs.vfat
我们这里用ext4的方式来进行格式化
[root@localhost huxiaoming]# mkfs.ext4 -help
mkfs.ext4: invalid option -- 'h'
Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-f fragment-size]
[-i bytes-per-inode] [-I inode-size] [-J journal-options]
[-G meta group size] [-N number-of-inodes]
[-m reserved-blocks-percentage] [-o creator-os]
[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
[-T fs-type] [-U UUID] [-jnqvFKSV] device [blocks-count]
[-T fs-type] [-U UUID] [-jnqvFKSV] device [blocks-count]
[root@localhost huxiaoming]# 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
1318 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
在RHEL5以前的版本,分完分区,内核是不会自动识别的,需要通过partprobe命令提前执行,然后在mkfs.ext3来做格式化
这里,我们可以通过加卷标的方式来定义sdb1和sdb2,例如我想把sdb1分配给/var/log 做日志用,把sdb2分给/home/huxiaoming存放个人文件
[root@localhost /]# man e2label 看下这个命令语法
SYNOPSIS
e2label device [ new-label ]
[root@localhost /]# e2label /dev/sdb1 logfolder
[root@localhost /]# e2label /dev/sdb2 xiaoming
e2label: Bad magic number in super-block while trying to open /dev/sdb2
Couldn't find valid filesystem superblock. #这里原因是我们还没有把sdb2格式化#
[root@localhost /]# 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
524288 inodes, 2094474 blocks
104723 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=21474838
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.
执行完毕之后,挂载磁盘
[root@localhost /]# mount /dev/sdb1 /var/log
[root@localhost /]# mount /dev/sdb2 /home/huxiaoming
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 383M 8.8G 5% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 194M 34M 151M 19% /boot
/dev/sda3 7.7G 148M 7.2G 2% /home
/dev/sda5 4.9G 138M 4.5G 3% /tmp
/dev/sda6 4.9G 2.9G 1.7G % /usr
/dev/sda7 4.9G 212M 4.4G 5% /var
/dev/sdb1 2.0G 68M 1.9G 4% /var/log
/dev/sdb2 7.9G 146M 7.4G 2% /home/huxiaoming
卸载磁盘
[root@localhost /]# umount /dev/sdb2 /home/huxiaoming
umount: /home/huxiaoming: not mounted
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 383M 8.8G 5% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 194M 34M 151M 19% /boot
/dev/sda3 7.7G 148M 7.2G 2% /home
/dev/sda5 4.9G 138M 4.5G 3% /tmp
/dev/sda6 4.9G 2.9G 1.7G % /usr
/dev/sda7 4.9G 212M 4.4G 5% /var
/dev/sdb1 2.0G 68M 1.9G 4% /var/log
也可以用label来挂载,前面我们说过
[root@localhost /]# e2label /dev/sdb2 "xiaoming"
[root@localhost /]# mount -L "xiaoming" /home/huxiaoming[root@localhost /]# tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: logfolder
Last mounted on: Filesystem UUID: 4e9ea2e6-d8b9-4358-a67c-d17e16ff6e3e Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: (none) Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 1318 Block count: 526120 Reserved block count: 26306 Free blocks: 500688 Free inodes: 131637 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 128 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 7744 Inode blocks per group: 484 Flex block group size: 16 Filesystem created: Sat Feb 22 13:28:38 2014 Last mount time: Sat Feb 22 13:33:20 2014 Last write time: Sat Feb 22 13:39:12 2014 Mount count: 1 Maximum mount count: 38 Last checked: Sat Feb 22 13:28:38 2014 Check interval: 15552000 (6 months) Next check after: Thu Aug 21 14:28:38 2014 Lifetime writes: 97 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8Default directory hash: half_md4 Directory Hash Seed: f0ca59dd-5349-4013-8d21-fdd99191d3e5 Journal backup: inode blocks下载本文