如何给linux添加一块硬盘
overview:
添加一块15G的硬盘
170 fdisk -l 列出所有硬盘
171 sudo pvcreate /dev/sdb ----------sdb为新添加的物理盘,准备供lvm使用
172 sudo vgcreate 12c /dev/sdb -------------------创建名为12c的卷组
174 sudo lvcreate -l 100%FREE -n 12clv 12c ----------------------------创建名为12lv的逻辑卷
175 sudo mkfs -t ext4 /dev/12c/12clv --------------------------创建文件系统
176 sudo mkdir /12c ----------------------------创建挂载点
177 sudo vi /etc/fstab -------------------------设置挂载的选项,挂载点
178 sudo mount /12c -------------------------- 挂载这个文件系统
eg:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 14.3 GB, 14343061504 bytes
255 heads, 63 sectors/track, 1743 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1743 13896225 8e Linux LVM
Disk /dev/sdb: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/dm-0: 13.1 GB, 13153337344 bytes
255 heads, 63 sectors/track, 1599 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/dm-1 doesn't contain a valid partition table
[root@localhost ~]# sudo pvcreate /dev/sdb
Writing physical volume data to disk "/dev/sdb"
Physical volume "/dev/sdb" successfully created
[root@localhost ~]# sudo vgcreate 12c /dev/sdb
Volume group "12c" successfully created
[root@localhost ~]# sudo lvcreate -l 100%FREE -n 12clv
Path required for Logical Volume "12clv"
Please provide a volume group name
Run `lvcreate --help' for more information.
[root@localhost ~]# sudo lvcreate -l 100%FREE -n 12clv 12c
Logical volume "12clv" created
[root@localhost ~]# sudo mkfs -t ext4 /dev/12c/12clv
mke4fs 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
983040 inodes, 3931136 blocks
196556 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 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, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune4fs -c or -i to override.
[root@localhost ~]# sudo mkdir /12c
[root@localhost ~]# sudo vi /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/12c/12clv /12c ext4 defaults 0 0
~
~
"/etc/fstab" 8L, 610C written
[root@localhost ~]# sudo mount /12c
[root@localhost ~]# cd /
[root@localhost /]# ll
total 166
drwxr-xr-x 3 root root 4096 Jun 26 07:26 12c
drwxr-xr-x 3 root root 4096 Jun 20 00:04 bin
drwxr-xr-x 4 root root 1024 Jun 19 10:34 boot
drwxr-xr-x 13 root root 3900 Jun 26 07:25 dev
drwxr-xr-x 98 root root 12288 Jun 26 07:30 etc
drwxr-xr-x 4 root root 4096 Jun 26 06:29 home
drwxr-xr-x 11 root root 4096 Jun 20 00:04 lib
drwxr-xr-x 9 root root 4096 Jun 20 00:04 lib64
drwx------ 2 root root 16384 Jun 19 10:23 lost+found
drwxr-xr-x 3 root root 4096 Jun 26 07:18 media
drwxr-xr-x 2 root root 0 Jun 26 07:18 misc
drwxr-xr-x 2 root root 4096 Feb 16 2010 mnt
drwxr-xr-x 2 root root 0 Jun 26 07:18 net
drwxr-xr-x 2 root root 4096 Feb 16 2010 opt
dr-xr-xr-x 123 root root 0 Jun 26 07:17 proc
drwxr-x--- 15 root root 4096 Jun 26 06:46 root
drwxr-xr-x 2 root root 12288 Jun 20 00:04 sbin
drwxr-xr-x 2 root root 4096 Jun 19 10:23 selinux
drwxr-xr-x 2 root root 4096 Feb 16 2010 srv
drwxr-xr-x 13 root root 0 Jun 26 07:17 sys
drwxr-xr-x 3 root root 4096 Jun 19 10:31 tftpboot
drwxrwxrwt 8 root root 4096 Jun 26 07:19 tmp
drwxr-xr-x 15 root root 4096 Jun 19 10:26 usr
drwxr-xr-x 21 root root 4096 Jun 19 10:37 var
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
12G 8.7G 2.6G 78% /
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 244M 0 244M 0% /dev/shm
/dev/mapper/12c-12clv
15G 166M 14G 2% /12c
[root@localhost /]# cd /12c
[root@localhost 12c]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
12G 8.7G 2.6G 78% /
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 244M 0 244M 0% /dev/shm
/dev/mapper/12c-12clv
15G 166M 14G 2% /12c
[root@localhost 12c]#
到此成功添加一块硬盘,并建立文件系统