2019-11-21 09:24:12 0 评论 Linux Boy.Lee

Centos 6 通过命令行 挂载新硬盘

在Centos 6下,通过命令行,挂载新购买的硬盘空间的完整操作流程

 

{ 硬盘使用概况 }

>> df -h

[root@MyServer YiiLib.com@666]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_have-lv_root
                      8.5G  6.7G  1.4G  84% /
tmpfs                 935M     0  935M   0% /dev/shm
/dev/xvda1            485M   71M  389M  16% /boot
/dev/mapper/Xvdbgroup-xvdb1
                      4.9G  1.8G  2.9G  39% /home

 

{ 使用详情 }

>> fdisk -l

... ...

Disk /dev/xvdb: 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/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006cde7

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         652     5237158+  83  Linux

... ...

这里有用的信息是: 

21.5GB + 2610 cylinders
使用了 1 - 652 (653-2610 未使用, 这里就是cylinders)

 

{ 分配新硬盘 }

>> fdisk /dev/xvdb

>p
Command (m for help): p

Disk /dev/xvdb: 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/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006cde7

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         652     5237158+  83  Linux


>n
Command (m for help): n
>p
Command action
   e   extended
   p   primary partition (1-4)
>2
Partition number (1-4): 2
>653
First cylinder (653-2610, default 653):
Using default value 653
>2610
Last cylinder, +cylinders or +size{K,M,G} (653-2610, default 2610):
Using default value 2610


>p
Command (m for help): p

Disk /dev/xvdb: 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/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006cde7

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         652     5237158+  83  Linux
/dev/xvdb2             653        2610    15727635   83  Linux


>w
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

上面的命令就是把653-2610挂载到/dev/xvdb2,特别注意分区类型(extended和primary partition)这里主分区只能有4个,超过了就只能做成扩展分区

 

{ 生效新分区 }

重启或者使用fdisk进行生效,建议重启

 

{ 格式化新分区 }

>> mkfs -t ext4 /dev/xvdb2

[root@MyServer YiiLib.com@666]# mkfs -t ext4 /dev/xvdb2
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
983040 inodes, 3931908 blocks
196595 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 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

建议保持ext4格式

 

{ 挂载新分区 }

>> mkdir /eebox
>> mount -t ext4 /dev/xvdb2 /eebox

>> df -h
[root@MyServer YiiLib.com@666]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_have-lv_root
                      8.5G  6.7G  1.4G  84% /
tmpfs                 935M     0  935M   0% /dev/shm
/dev/xvda1            485M   71M  389M  16% /boot
/dev/mapper/Xvdbgroup-xvdb1
                      4.9G  1.8G  2.9G  39% /home
/dev/xvdb2             15G  166M   14G   2% /eebox

 

{ 还没有结束 }

如果现在你重启机器,会发现挂载失效了, 只需要编辑 /etc/fstab 添加如下一行即可

>> cat /etc/fstab
>> add the follow line
/dev/xvdb2              /eebox                  ext4    defaults        0 0

>> save

 

{ Home Free }

>> /home free

umount /eedb
mount /dev/mapper/Xvdbgroup-xvdb1 /eedb
mkfs -t ext4 /dev/mapper/Xvdbgroup-xvdb1
mkfs.ext4 /dev/mapper/Xvdbgroup-xvdb1

/dev/mapper/Xvdbgroup-xvdb1              /eedb                  ext4    defaults        0 0