CentOS挂载新硬盘

1.查看当前硬盘使用状况:

df -h
[email protected]_160_34_centos:~> df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.5G  6.1G  20% /

2.查看新硬盘 

 fdisk -l 
 1 [email protected]_160_34_centos:~> fdisk -l
 2
 3 Disk /dev/xvda: 8589 MB, 8589934592 bytes
 4 255 heads, 63 sectors/track, 1044 cylinders
 5 Units = cylinders of 16065 * 512 = 8225280 bytes
 6 Sector size (logical/physical): 512 bytes / 512 bytes
 7 I/O size (minimum/optimal): 512 bytes / 512 bytes
 8 Disk identifier: 0xcd6e8236
 9
10     Device Boot      Start         End      Blocks   Id  System
11 /dev/xvda1   *           1        1044     8385898+  83  Linux
12
13 Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
14 255 heads, 63 sectors/track, 6527 cylinders
15 Units = cylinders of 16065 * 512 = 8225280 bytes
16 Sector size (logical/physical): 512 bytes / 512 bytes
17 I/O size (minimum/optimal): 512 bytes / 512 bytes
18 Disk identifier: 0x00000000
19
20 Disk /dev/xvdb doesn‘t contain a valid partition table
21
22 Disk /dev/xvdc: 2147 MB, 2147483648 bytes
23 255 heads, 63 sectors/track, 261 cylinders
24 Units = cylinders of 16065 * 512 = 8225280 bytes
25 Sector size (logical/physical): 512 bytes / 512 bytes
26 I/O size (minimum/optimal): 512 bytes / 512 bytes
27 Disk identifier: 0x00000000
28
29 Disk /dev/xvdc doesn‘t contain a valid partition table

这结果很明显让人烦躁,一坨屎一样,下面我们过滤一下

命令:

fdisk -l  |grep Disk

结果:

[email protected]_160_34_centos:~> fdisk -l  |grep Disk
Disk /dev/xvdb doesn‘t contain a valid partition table
Disk /dev/xvdc doesn‘t contain a valid partition table
Disk /dev/xvda: 8589 MB, 8589934592 bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: 2147 MB, 2147483648 bytes
Disk identifier: 0x00000000

这个看起来让人舒心多了,

结果中:

提示这个

Disk /dev/xvdb doesn‘t contain a valid partition table
Disk /dev/xvdc doesn‘t contain a valid partition table

这两行应该就是说还没有挂载上去的硬盘了.

新添加的硬盘的编号为

/dev/xvdb
/dev/xvdc

3.硬盘分区

  • 进入fdisk模式
 fdisk /dev/xvdb  
 1 [email protected]_160_34_centos:~> fdisk /dev/xvdb
 2 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 3 Building a new DOS disklabel with disk identifier 0x7ca79642.
 4 Changes will remain in memory only, until you decide to write them.
 5 After that, of course, the previous content won‘t be recoverable.
 6
 7 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 8
 9 WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
10          switch off the mode (command ‘c‘) and change display units to
11          sectors (command ‘u‘).
12
13 Command (m for help): 
  •  输入n进行分区 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)p

这里有两个选项: 
?   p: 主分区 linux上主分区最多能有4个 
?   e: 扩展分区 linux上扩展分区只能有1个,扩展分区创建后不能直接使用,还要在扩展分区上创建逻辑分区。

这里我选择的p。

  • 选择分区个数
Partition number (1-4): 1

可以选择4个分区,这里我只分成1个分区

  • 设置柱面,这里选择默认值就可以,直接按回车过去
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):
Using default value 6527
  • 输入w,写入分区表,进行分区 
Command (m for help):w
Command (m for help): w
The partition table has been altered!

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

整个过程如下:

[email protected]_160_34_centos:~> fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7ca79642.
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): n
Command action
   e   extended
   p   primary partition (1-4)

Last login: Fri Jun 13 18:19:47 2014 from 112.90.239.105
[email protected]_160_34_centos:~>
Display all 1286 possibilities? (y or n)
[email protected]_160_34_centos:~>
[email protected]_160_34_centos:~> fdisk /dev/xvd
xvda   xvda1  xvdb   xvdc
[email protected]_160_34_centos:~> fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc925c1ae.
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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):
Using default value 6527

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

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

4.格式化分区 

将新分区格式化为ext3文件系统

  • 如果创建的是主分区
#mkfs -t ext3  /dev/xvdb
[email protected]_160_34_centos:~> mkfs -t ext3  /dev/xvdb
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
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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,
        4096000, 7962624, 11239424

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.

5.  挂载硬盘

  • 创建挂载点

在根目录下创建storage目录

#mkdir /storage 
  • 将/dev/xvdb挂载到/storage下 
#mount /dev/xvdb /storage
  • 设置开机启动自动挂载 

新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。 
    设置开机自动挂载需要修改/etc/fstab文件

 #vi /etc/fstab 

在文件的最后增加一行

 /dev/xvdb /storage ext3 defaults 1 2 

过程如下:

 1 [email protected]_160_34_centos:~> mkdir /storage
 2 [email protected]_160_34_centos:~> mount /dev/xvdb /storage
 3 [email protected]_160_34_centos:~> vi /etc/fstab
 4
 5
 6
 7 /dev/xvda1            /                    ext3       noatime,acl,user_xattr 1 1
 8 /dev/xvdc            swap                 swap       defaults 0 0
 9 proc                 /proc                proc       defaults              0 0
10 sysfs                /sys                 sysfs      noauto                0 0
11 debugfs              /sys/kernel/debug    debugfs    noauto                0 0
12 devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
13 /dev/xvdb            /storage             ext3       defaults              1 2
14 ~
15 ~
16 ~
17 ~
18 ~
19 "/etc/fstab" 7L, 536C written
20 [email protected]_160_34_centos:~> clear

结果:

[email protected]_160_34_centos:/storage> ll /
total 104
dr-xr-xr-x   2 root root  4096 May 15 15:33 bin
dr-xr-xr-x   4 root root  4096 May 31  2013 boot
drwxr-xr-x   2 root root  4096 Dec 16 11:42 data
drwxr-xr-x  15 root root  3360 Jun 13 19:21 dev
drwxr-xr-x  73 root root  4096 Jun 13 19:37 etc
drwxr-xr-x   3 root root  4096 Jun  2 20:32 home
dr-xr-xr-x  12 root root  4096 Jun 20  2013 lib
dr-xr-xr-x   9 root root 12288 Jun 20  2013 lib64
drwx------   2 root root 16384 May 31  2013 lost+found
drwxr-xr-x   2 root root  4096 Sep 23  2011 media
drwxr-xr-x   2 root root  4096 Sep 23  2011 mnt
drwxr-xr-x   2 root root  4096 Sep 23  2011 opt
dr-xr-xr-x 106 root root     0 Jun 14  2014 proc
dr-xr-x---   2 root root  4096 Jun 13 19:35 root
dr-xr-xr-x   2 root root 12288 Jun 19  2013 sbin
drwxr-xr-x   2 root root  4096 May 31  2013 selinux
drwxr-xr-x   2 root root  4096 Sep 23  2011 srv
drwxr-xr-x   3 root root  4096 Jun 13 19:37 storage
drwxr-xr-x  13 root root     0 Jun 14  2014 sys
drwxrwxrwt   3 root root  4096 Jun 13 18:26 tmp
drwxr-xr-x  13 root root  4096 May 31  2013 usr
drwxr-xr-x  19 root root  4096 Jul 16  2013 var
[email protected]_160_34_centos:/storage> fdisk -l  |grep Disk
Disk /dev/xvdb doesn‘t contain a valid partition table
Disk /dev/xvdc doesn‘t contain a valid partition table
Disk /dev/xvda: 8589 MB, 8589934592 bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: 2147 MB, 2147483648 bytes
Disk identifier: 0x00000000
[email protected]_160_34_centos:/storage> df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.5G  6.1G  20% /
/dev/xvdb              50G  180M   47G   1% /storage

教程到此结束!

CentOS挂载新硬盘

时间: 2024-08-26 08:37:19

CentOS挂载新硬盘的相关文章

linux 挂载新硬盘

fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段 我们可以对硬盘进行分区操作,前提是您把fdisk -l 弄明白了:通过fdisk -l ,我们能找出机器中所有硬盘个数及设备名称:比如上面的例子,我们会看到两个设备一个是/dev/hda ,另一个是/dev/sda : fdisk 操作硬盘的命令格式如下: [[email protected] beinan]# fdisk 设备 比如我们通过 fdisk -l 得知 /dev/hda 或者 /dev/sda设备:我们如果想再添加或者

买了阿里云之后:挂载新硬盘

挂载新硬盘# df -h2.查看新硬盘    #fdisk –l 1)进入fdisk模式    #/sbin/fdisk/dev/sdb   2)输入n进行分区这里有两个选项: Ø  p: 主分区linux上主分区最多能有4个 Ø  e: 扩展分区linux上扩展分区只能有1个,扩展分区创建后不能直接使用,还要在扩展分区上创建逻辑分区. 这里我选择的p.    4)选择分区个数       Partition number (1-4):可以选择4个分区,这里我只分成1个分区    5)设置柱面,

vm虚拟机下centos6.2挂载新硬盘操作记录

查看现有的分区 [[email protected] ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/opt

Linux挂载新硬盘和创建Swap分区的方法

Liunx添加新硬盘其实和Windows的操作一样,但一个是图形化操作,另一个是命令行操作,不过步骤是一样,下面就动手演示和讲解 Linux挂载新硬盘 1.查看硬盘信息 命令:fdisk -l [[email protected] ~]# fdisk -l Disk /dev/vda: 21.5 GB, 21474836480 bytes #第一块硬盘的信息和分区信息 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of

CentOS 7 下 fdisk 对挂载新硬盘的操作

CentOS 7 下 fdisk 加载新硬盘 注意: fdisk工具不支持GPT,对GPT格式的分区,需使用另一个GNU发布的强大分区工具parted -+++++++++++++++++++++++++++++++ 基本命令:fdisk # 磁盘分区mkfs #对每个分区进行格式化+++++++++++++++++++++++++++++++ fdisk 交互式命令的常用选项 例子:该系统有两个磁盘sda 和sdb, sda已经划分好并分区和格式化在使用了, sdb是一个没有做任何操作的磁盘.

linux挂载新硬盘,开机自动挂载

Linux的硬盘识别: 2.6 kernel以后,linux会将识别到的硬件设备,在/dev/下建立相应的设备文件.如: sda        表示第1块SCSI硬盘.# V, z   b, }2 F7 u' | hda        表示第1块IDE硬盘(即连接在第1个IDE接口的Master口上) scd0        表示第1个USB光驱. 当添加了新硬盘后,在/dev目录下会有相应的设备文件产生.cciss的硬盘是个例外,它的 设备文件在/dev/cciss/目录下.一般使用"fdis

解决挂载新硬盘原有目录下文件消失的方法

新硬盘挂载目录后文件消失解决办法 版权声明:本文为博主原创文章,未经博主允许不得转载. 项目初期用户文件较少,全部存储在/home目录下,/home目录没有单独划开分区,随着项目网站做大,用户文件越来越多,/home目录不够空间,想挂载一个新硬盘来负责储存 但发现新挂载/home到新硬盘时,/home原来数据变空了,这个原因是由于Linux的VFS(虚拟文件系统)机制导致的,正常登录以后,所看到的各个目录,文件都是内核在加载时候构造在内存中的VFS目录树,而不是直接看到硬盘上的实际目录树.当你挂

[草稿]挂载新硬盘

查看新硬盘&创建分区 [email protected]:/dev$ sudo fdisk -l [sudo] password for xxx: Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 cylinders, total 167772160 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/phys

Linux下挂载新硬盘方法

?? Linux的硬盘识别在/dev/下建立相应的设备文件.如 sda 表示第一块SCSI硬盘 hda 表示第一块IDE硬盘(即连接在第一个IDE接口的Master口上) scd0 表示第一个USB光驱通过fdisk -l 查看当前的设备和分区信息.注意,新硬盘没有分区信息,只是显示硬盘大小信息 分区并进行格式 使用fdisk命令对sdb进行分区 [[email protected] ~]# fdisk /dev/sdb 输入:n 表示新建分区 Command(m for help):n Com