Linux下增加硬盘

我要增加一个10G的SCSI的磁盘。

 

磁盘->(fdisk建立分区表)->分区->(mkfs建立文件系统)->文件系统->(mount将文件系统挂载到相应目录下)->目录->(最后需要编辑/etc/fstab文件,让系统在启动时就加载这些文件系统)

 

1,一般使用“fdisk -l”命令可以列出系统中当前连接的硬盘,设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 如下黄色背景就是我新添加的硬盘。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          38      305203+  83  Linux
/dev/sda2              39       10186    81513810   83  Linux
/dev/sda3           10187       10443     2064352+  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

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

2,使用fdisk命令对sdb进行分区.

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1305.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m                   --查看帮助
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
   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)

Command (m for help): n                  --表示新建分区

Command action
   e   extended
   p   primary partition (1-4)
p             p 表示建立一个原始分区
Partition number (1-4): 1               --1 表示此分区编号为1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-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

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

Command (m for help): w               ---w 保存存盘,退出fdisk.
The partition table has been altered!

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

 

3,再使用fdisk -l命令查看分区情况.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          38      305203+  83  Linux
/dev/sda2              39       10186    81513810   83  Linux
/dev/sda3           10187       10443     2064352+  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

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

 

显示/dev/sdb1上有一个sdb1分区,为linux格式, 分区后,需要对这个分区进行格式化.
 
4,这个分区进行格式化

[root@localhost ~]# 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)
1310720 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

Writing inode tables: done                           
Creating journal (32768 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.

5,将新建分区挂在到/data 上.
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sdb1 /data
 
6, df命令来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              76G   13G   59G  18% /
/dev/sda1             289M   17M  258M   6% /boot
tmpfs                 981M     0  981M   0% /dev/shm
/dev/sdb1             9.9G  151M  9.2G   2% /data

sdb1已挂载到/data上,剩余空间为9.2G

 


7,.设置新硬盘开机自动挂载

在/etc/fstab中添加新硬盘的挂载信息.添加下面一行:
/dev/sdb1  /data ext3 defaults 1 1
这样,每次开机后,系统会自动将/dev/sdb1挂载到/data上.

 

[root@localhost ~]# vi /etc/fstab
LABEL=/                 /                       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
LABEL=SWAP-sda3         swap                    swap    defaults        0 0
/dev/sdb1               /data                   ext3    defaults        1 1

 

 

 

--格式说明

/dev/sdb1              /u01            ext3                      defaults                    1                          1

要挂载的对象 挂载的目录 系统类型 文件系统访问权限 开机后是否检测 出问题后是否转储

 

 

8,重新启动服务器,再次df -h查看

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              76G   13G   59G  18% /
/dev/sda1             289M   17M  258M   6% /boot
tmpfs                 981M     0  981M   0% /dev/shm
/dev/sdb1             9.9G  151M  9.2G   2% /data
可以看出/dev/sdb1顺利的自动挂载了。

 

 


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值