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

时间:2024-05-01 16:04:09

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

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

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

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

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

添加新分区

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
Free PE
Allocated PE
PV UUID 8AV96r-QBvP-Hy6Q-uP1l-YI4b-UYom-GgIUNV 创建pv
[root@wb201 /]# pvcreate /dev/sdb
WARNING: xfs signature detected on /dev/sdb at offset . 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
Free PE
Allocated PE
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
Total PE
Free PE
Allocated PE
PV UUID OjyuLL-5f4X-BoVB-hZBS-AJpZ-IeMV-JO6UHF 查看vg(卷组)
[root@wb201 /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 7.51 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 7.47 GiB
Free PE / Size / 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, -- :: +
LV Status available
# open
LV Size 820.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- 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, -- :: +
LV Status available
# open
LV Size 6.67 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : 看看现在卷组的情况
[root@wb201 /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 28.28 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 7.47 GiB
Free PE / Size / 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, -- :: +
LV Status available
# open
LV Size 820.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- 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, -- :: +
LV Status available
# open
LV Size 6.67 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : 增加物理卷到根目录,可以看到根目录是在/dev/centos/root
[root@wb201 /]# lvextend -L +.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 ( extents) to 27.48 GiB ( extents).
Logical volume root successfully resized. 现在还没有增加,因为还没有更新
[root@wb201 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root .7G .5G .3G % /
devtmpfs .9G .9G % /dev
tmpfs .9G .9G % /dev/shm
tmpfs .9G 8.4M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
/dev/sda1 497M 205M 292M % /boot
tmpfs 380M 380M % /run/user/ 如果不xfs用resize2fs更新,但是xfs需要用xfs_growfs
[root@wb201 /]# resize2fs /dev/centos/root
resize2fs 1.42. (-Dec-)
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 .7G .5G .3G % /
devtmpfs .9G .9G % /dev
tmpfs .9G .9G % /dev/shm
tmpfs .9G 8.4M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
/dev/sda1 497M 205M 292M % /boot
tmpfs 380M 380M % /run/user/
[root@wb201 /]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
data blocks changed from to 现在看就ok啦,哈哈
[root@wb201 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 28G .5G 23G % /
devtmpfs .9G .9G % /dev
tmpfs .9G .9G % /dev/shm
tmpfs .9G 8.4M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
/dev/sda1 497M 205M 292M % /boot
tmpfs 380M 380M % /run/user/

ok了,完美~