服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 7187|回复: 3

linux下安装新硬盘并加载使用手记

[复制链接]
dirtysea 发表于 2009-5-5 15:33:53 | 显示全部楼层 |阅读模式
一、过程步骤
1、#kudzu                          //检测新硬件,这一步必须!
2、#fdisk -l                         //查看是否找到新的硬盘,查看硬盘代号。
3、#fdisk /dev/sdb             //为新硬盘分区,例如分成sdb1
     #mkfs.ext3 /dev/sdb1    //把新硬盘格式化成ext3格式

4、#mkdir /disk2                    //创建新的挂载点
5、#mount /dev/sdb1 /disk2/   //手动挂载分区,把硬盘挂到/disk2目录下。
6、#vi /etc/fstab
/dev/sdb1 /disk2 ext3 auto 1 2     //设置为开机自动挂载分区。



二、开工

2、
查看硬盘代号
[root@AMD-LINUX ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0007d856

Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1305 10281600 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes <=新硬盘
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/dm-0: 9395 MB, 9395240960 bytes
255 heads, 63 sectors/track, 1142 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

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 identifier: 0x30307800

Disk /dev/dm-1 doesn't contain a valid partition table


3、fdisk 分区
[root@AMD-LINUX ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x623223a1.
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)

Command (m for help): p <=显示信息

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x623223a1

Device Boot Start End Blocks Id System

Command (m for help): n <=新建分区
Command action
e extended
p primary partition (1-4)
p <=新建主分区
Partition number (1-4): 1 <=分区号为1,即/dev/sdb1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

Command (m for help): p <=显示分区信息

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x623223a1

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux

Command (m for help): w <=保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


4、创建挂载点
[root@AMD-LINUX ~]# mkdir /disk2

[root@AMD-LINUX ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0007d856

Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1305 10281600 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x623223a1

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux

Disk /dev/dm-0: 9395 MB, 9395240960 bytes
255 heads, 63 sectors/track, 1142 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

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 identifier: 0x30307800

Disk /dev/dm-1 doesn't contain a valid partition table

[root@AMD-LINUX ~]# mke2fs -j /dev/sdb1
mke2fs 1.40.2 (12-Jul-2007)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524112 blocks
26205 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

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

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.



5、设置为开机自动挂载分区
[root@AMD-LINUX ~]# vi /etc/fstab
/dev/sdb1     /disk2      ext3       auto     1 2

6、手动挂载分区
[root@AMD-LINUX ~]# mount /dev/sdb1 /disk2/
 楼主| dirtysea 发表于 2010-3-3 14:30:20 | 显示全部楼层
格式化分区使用mkfs命令,如“/sbin/mkfs -t ext3 /dev/hdb3”,其含义就是将分区hdb3格式化为EXT3的格式
ag:
mkfs -t ext3 /dev/hdb 就是将第2块硬盘全格式化
 楼主| dirtysea 发表于 2010-7-8 11:42:14 | 显示全部楼层
linux下为剩余空间分区并加载。(将还未分区的空余空间分区)

相关命令
fdisk /dev/sda
p
n
回车
回车
p
w <=保存退出
reboot
ls /dev
mkfs.ext3 /dev/sda9
vi /etc/fstab
/dev/sda9               /opt                    ext3    auto            1 2



操作截图
[root@TJ1CMUSICXX01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             996M  233M  712M  25% /
/dev/sda8             996M   34M  911M   4% /tmp
/dev/sda7             3.9G   73M  3.7G   2% /home
/dev/sda6             9.7G  4.1G  5.2G  44% /var
/dev/sda5             9.7G  580M  8.7G   7% /usr
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm

[root@TJ1CMUSICXX01 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 19457.
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): p

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 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        1057     8385930   82  Linux swap / Solaris
/dev/sda3            1058        1188     1052257+  83  Linux
/dev/sda4            1189       19457   146745742+   5  Extended
/dev/sda5            1189        2493    10482381   83  Linux
/dev/sda6            2494        3798    10482381   83  Linux
/dev/sda7            3799        4320     4192933+  83  Linux
/dev/sda8            4321        4451     1052226   83  Linux

Command (m for help): n
First cylinder (4452-19457, default 4452):      (起始地址直接回车)
Using default value 4452
Last cylinder or +size or +sizeM or +sizeK (4452-19457, default 19457):     (终止地址直接回车)
Using default value 19457

Command (m for help): p

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 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        1057     8385930   82  Linux swap / Solaris
/dev/sda3            1058        1188     1052257+  83  Linux
/dev/sda4            1189       19457   146745742+   5  Extended
/dev/sda5            1189        2493    10482381   83  Linux
/dev/sda6            2494        3798    10482381   83  Linux
/dev/sda7            3799        4320     4192933+  83  Linux
/dev/sda8            4321        4451     1052226   83  Linux
/dev/sda9            4452       19457   120535663+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@TJ1CMUSICXX01 ~]# ls /dev
bus      loop4     parport3  ram4     sda5      tty11  tty26  tty40  tty55  ttyS3           vcs2
console  loop5     port      ram5     sda6      tty12  tty27  tty41  tty56  urandom         vcs3
core     loop6     ppp       ram6     sda7      tty13  tty28  tty42  tty57  usbdev1.1_ep00  vcs4
cpu      loop7     ptmx      ram7     sda8      tty14  tty29  tty43  tty58  usbdev1.1_ep81  vcs5
disk     MAKEDEV   pts       ram8    sda9(有了)  tty15  tty3   tty44  tty59  usbdev2.1_ep00  vcs6
fd       mapper    ram       ram9     sg0       tty16  tty30  tty45  tty6   usbdev2.1_ep81  vcsa
full     mcelog    ram0      ramdisk  shm       tty17  tty31  tty46  tty60  usbdev3.1_ep00  vcsa1
hpet     md0       ram1      random   snapshot  tty18  tty32  tty47  tty61  usbdev3.1_ep81  vcsa2
initctl  mem       ram10     rawctl   stderr    tty19  tty33  tty48  tty62  usbdev4.1_ep00  vcsa3
input    net       ram11     root     stdin     tty2   tty34  tty49  tty63  usbdev4.1_ep81  vcsa4
kmsg     null      ram12     rtc      stdout    tty20  tty35  tty5   tty7   usbdev4.2_ep00  vcsa5
log      nvram     ram13     sda      systty    tty21  tty36  tty50  tty8   usbdev4.2_ep01  vcsa6
loop0    oldmem    ram14     sda1     tty       tty22  tty37  tty51  tty9   usbdev4.2_ep81  X0R
loop1    parport0  ram15     sda2     tty0      tty23  tty38  tty52  ttyS0  usbdev4.2_ep82  zero
loop2    parport1  ram2      sda3     tty1      tty24  tty39  tty53  ttyS1  vcs
loop3    parport2  ram3      sda4     tty10     tty25  tty4   tty54  ttyS2  vcs1
[root@TJ1CMUSICXX01 ~]# mkfs.ext3 /dev/sda9
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
15073280 inodes, 30133915 blocks
1506695 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
920 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

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 tune2fs -c or -i to override.
[root@TJ1CMUSICXX01 ~]# mkdir /opt

[root@TJ1CMUSICXX01 ~]#vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/tmp              /tmp                    ext3    defaults        1 2
LABEL=/home             /home                   ext3    defaults        1 2
LABEL=/var              /var                    ext3    defaults        1 2
LABEL=/usr              /usr                    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-sda2         swap                    swap    defaults        0 0
/dev/sda9               /opt                    ext3    auto            1 2


重启系统


[root@TJ1CMUSICXX01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             996M  233M  712M  25% /
/dev/sda8             996M   34M  911M   4% /tmp
/dev/sda7             3.9G   73M  3.7G   2% /home
/dev/sda6             9.7G  4.1G  5.2G  44% /var
/dev/sda5             9.7G  580M  8.7G   7% /usr
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda9             114G  188M  108G   1% /opt
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|运维之家

GMT+8, 2024-4-29 09:23 , Processed in 0.249439 second(s), 14 queries .

Powered by Dirtysea

© 2008-2020 Dirtysea.com.

快速回复 返回顶部 返回列表