CentOS添加新硬盘到新的分区(xfs/ext4) 或者添加新分区

 CentOs添加新硬盘到新的分区(xfs/ext4)  添加新分区

转载请注明:http://www.cnblogs.com/juandx/p/5618162.html

这篇文章介绍怎么添加一块新的硬盘,然后将其添加到一个新的分区或者一个已有的分区,比如增加根分区的大小

比如在virtualbox中添加的硬盘也可以用这样的

 添加新分区

fdisk -l
可以看到新的硬盘 /dev/sdb

fdisk /dev/sdb
输入m查看提示
输入n添加分区
输入1新建一个分区
然后默认回车2次创建成功(有人说第二次按w保存,但是我直接回车好像也没问题额)

格式化分区 mkfs -t xfs  /dev/sdb

新建一个自己想要挂载的目录 mkdir /opt/data/data1

然后 mount -t xfs /dev/sdb /opt/data/data1

df -lhT可以看到信息,ok了

 


添加新硬盘到新的分区(xfs/ext4)

fdisk -l
可以看到新的硬盘 /dev/sdb
fdisk /dev/sdb
输入m查看提示
输入n添加分区
输入p选择primary
输入1新建一个分区
然后默认回车2次创建成功(有人说第二次按w保存,但是我直接回车好像也没问题额)

格式化分区 mkfs -t xfs  /dev/sdb

查看pv(物理卷)
[root@wb201 /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               7.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              1922
  Free PE               10
  Allocated PE          1912
  PV UUID               8AV96r-QBvP-Hy6Q-uP1l-YI4b-UYom-GgIUNV
   
创建pv
[root@wb201 /]# pvcreate /dev/sdb 
WARNING: xfs signature detected on /dev/sdb at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sdb.
  Physical volume "/dev/sdb" successfully created
[root@wb201 /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               7.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              1922
  Free PE               10
  Allocated PE          1912
  PV UUID               8AV96r-QBvP-Hy6Q-uP1l-YI4b-UYom-GgIUNV
   
  "/dev/sdb" is a new physical volume of "20.78 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.78 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               OjyuLL-5f4X-BoVB-hZBS-AJpZ-IeMV-JO6UHF
   
查看vg(卷组)
[root@wb201 /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.51 GiB
  PE Size               4.00 MiB
  Total PE              1922
  Alloc PE / Size       1912 / 7.47 GiB
  Free  PE / Size       10 / 40.00 MiB
  VG UUID               iLRzhR-myQz-XQwG-XBnd-yH2V-2vhu-VWTtgm
   
增加卷组
 [root@wb201 /]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended

查看lv(卷组)
[root@wb201 /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                dBjVT5-KvtT-t4zS-hWkh-cDvn-rXch-hc7SaA
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-02-22 22:43:17 +0800
  LV Status              available
  # open                 2
  LV Size                820.00 MiB
  Current LE             205
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                6IJGJT-QEyI-bsQ2-O180-hRcI-T5U8-QBUcMA
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-02-22 22:43:17 +0800
  LV Status              available
  # open                 1
  LV Size                6.67 GiB
  Current LE             1707
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
看看现在卷组的情况
[root@wb201 /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               28.28 GiB
  PE Size               4.00 MiB
  Total PE              7240
  Alloc PE / Size       1912 / 7.47 GiB
  Free  PE / Size       5328 / 20.81 GiB
  VG UUID               iLRzhR-myQz-XQwG-XBnd-yH2V-2vhu-VWTtgm
   
看看现在逻辑卷的情况
[root@wb201 /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                dBjVT5-KvtT-t4zS-hWkh-cDvn-rXch-hc7SaA
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-02-22 22:43:17 +0800
  LV Status              available
  # open                 2
  LV Size                820.00 MiB
  Current LE             205
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                6IJGJT-QEyI-bsQ2-O180-hRcI-T5U8-QBUcMA
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-02-22 22:43:17 +0800
  LV Status              available
  # open                 1
  LV Size                6.67 GiB
  Current LE             1707
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   

增加物理卷到根目录,可以看到根目录是在/dev/centos/root
 [root@wb201 /]# lvextend -L +20.81G /dev/centos/root
  Rounding size to boundary between physical extents: 20.81 GiB
  Size of logical volume centos/root changed from 6.67 GiB (1707 extents) to 27.48 GiB (7035 extents).
  Logical volume root successfully resized.

现在还没有增加,因为还没有更新
[root@wb201 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.7G  5.5G  1.3G  82% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  205M  292M  42% /boot
tmpfs                    380M     0  380M   0% /run/user/0


如果不xfs用resize2fs更新,但是xfs需要用xfs_growfs
[root@wb201 /]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.
[root@wb201 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.7G  5.5G  1.3G  82% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  205M  292M  42% /boot
tmpfs                    380M     0  380M   0% /run/user/0
[root@wb201 /]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=436992 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=1747968, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1747968 to 7203840

现在看就ok啦,哈哈
[root@wb201 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   28G  5.5G   23G  20% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  205M  292M  42% /boot
tmpfs                    380M     0  380M   0% /run/user/0

 

ok了,完美~

posted @ 2016-06-26 16:57  juandx  阅读(8734)  评论(1编辑  收藏  举报