代码改变世界

llinux mount 新建磁盘到指定目录

2011-09-23 16:11  周国选  阅读(967)  评论(0编辑  收藏  举报

因为安装数据库,需要较大的磁盘容量,需要把一块新磁盘挂载到/opt上
1 对磁盘做分区:

root@rac1:/root>fdisk /dev/sdb
The number of cylinders for this disk is set to 182024.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-182024, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-182024, default 182024):
Using default value 182024
Command (m for help): p
Disk /dev/sdb: 1497.1 GB, 1497198755840 bytes
255 heads, 63 sectors/track, 182024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 182024 1462107748+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

2 创建ext3 文件系统:
root@rac1:/root>mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
182763520 inodes, 365526937 blocks
18276346 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
11155 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3 创建标签
root@rac1:/root>e2label /dev/sdb1 /opt
root@rac1:/root>mount /dev/sdb1 /opt
4 mount 到/opt (如果opt里面有数据,则需要先做备份,mount之后,再拷贝到/opt目录)
root@rac1:/root>df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.5G 3.0G 6.1G 33% /
/dev/sda3 4.8G 138M 4.4G 4% /tmp
/dev/sda6 255G 27G 215G 12% /home
/dev/sda1 99M 14M 80M 15% /boot
tmpfs 12G 0 12G 0% /dev/shm
/dev/sdb1 1.4T 198M 1.3T 1% /opt
5 修改/etc/fstab 文件
root@rac1:/root>vi /etc/fstab

LABEL=/ / ext3 defaults 1 1
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/home /home ext3 defaults 1 2
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
LABEL=SWAP-sda5 swap swap defaults 0 0
LABEL=/opt /opt ext3 defaults 1 2

"/etc/fstab" 11L, 761C written
测试:
root@rac1:/root>umount /opt/
root@rac1:/root>df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.5G 3.0G 6.1G 33% /
/dev/sda3 4.8G 138M 4.4G 4% /tmp
/dev/sda6 255G 27G 215G 12% /home
/dev/sda1 99M 14M 80M 15% /boot
tmpfs 12G 0 12G 0% /dev/shm
root@rac1:/root>mount -a
root@rac1:/root>df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.5G 3.0G 6.1G 33% /
/dev/sda3 4.8G 138M 4.4G 4% /tmp
/dev/sda6 255G 27G 215G 12% /home
/dev/sda1 99M 14M 80M 15% /boot
tmpfs 12G 0 12G 0% /dev/shm
/dev/sdb1 1.4T 198M 1.3T 1% /opt
root@rac1:/root>ls /opt/
lost+found
root@rac1:/root>