centos挂载盘到根下_Centos 扩容根分区大小,挂载磁盘到跟目录

操作环境:

[root@zwf ~]# uname -a

Linux zwf 2.6.32-504.16.2.el6.x86_64 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@zwf ~]# cat /etc/issue

CentOS release 6.6 (Final)

Kernel \r on an \m

[root@zwf ~]#

1

2

3

4

5

6

7

[root@zwf~]# uname -a

Linuxzwf2.6.32-504.16.2.el6.x86_64#1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@zwf~]# cat /etc/issue

CentOSrelease6.6(Final)

Kernel\ronan\m

[root@zwf~]#

扩容前,服务器磁盘分区情况:

[root@zwf ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

18G 3.4G 13G 21% /

tmpfs 3.9G 0 3.9G 0% /dev/shm

/dev/xvda1 477M 52M 400M 12% /boot

1

2

3

4

5

6

[root@zwf~]# df -h

FilesystemSizeUsedAvailUse%Mountedon

/dev/mapper/VolGroup-lv_root

18G3.4G13G21%/

tmpfs3.9G03.9G0%/dev/shm

/dev/xvda1477M52M400M12%/boot

可以看到跟目录只有18个G的大小,现在增加一块磁盘100G:

[root@zwf ~]# fdisk -l

Disk /dev/xvdb: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x3f057d6e

Device Boot Start End Blocks Id System

/dev/xvdb1 1 13054 104856223+ 83 Linux

Disk /dev/xvda: 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: 0x0002051c

Device Boot Start End Blocks Id System

/dev/xvda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/xvda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes

255 heads, 63 sectors/track, 2285 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: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 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: 0x00000000

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

[root@zwf~]# fdisk -l

Disk/dev/xvdb:107.4GB,107374182400bytes

255heads,63sectors/track,13054cylinders

Units=cylindersof16065*512=8225280bytes

Sectorsize(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Diskidentifier:0x3f057d6e

DeviceBootStartEndBlocksIdSystem

/dev/xvdb1113054104856223+83Linux

Disk/dev/xvda:21.5GB,21474836480bytes

255heads,63sectors/track,2610cylinders

Units=cylindersof16065*512=8225280bytes

Sectorsize(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Diskidentifier:0x0002051c

DeviceBootStartEndBlocksIdSystem

/dev/xvda1   *16451200083Linux

Partition1doesnotendoncylinderboundary.

/dev/xvda2642611204584968eLinuxLVM

Disk/dev/mapper/VolGroup-lv_root:18.8GB,18798870528bytes

255heads,63sectors/track,2285cylinders

Units=cylindersof16065*512=8225280bytes

Sectorsize(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Diskidentifier:0x00000000

Disk/dev/mapper/VolGroup-lv_swap:2147MB,2147483648bytes

255heads,63sectors/track,261cylinders

Units=cylindersof16065*512=8225280bytes

Sectorsize(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Diskidentifier:0x00000000

/dev/xvdb1  就是新增的磁盘,已经分区并格式化,还没有挂载,给此磁盘添加物理卷:

[root@zwf ~]# pvcreate /dev/xvdb1

Physical volume "/dev/xvdb1" successfully created

1

2

[root@zwf~]# pvcreate /dev/xvdb1

Physicalvolume"/dev/xvdb1"successfullycreated

查看当前服务器物理卷(PV)的情况:

[root@zwf ~]# pvdisplay

--- Physical volume ---

PV Name /dev/xvda2

VG Name VolGroup

PV Size 19.51 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 4994

Free PE 0

Allocated PE 4994

PV UUID QKYKlh-t5DO-1gFR-QZrl-I3iB-NbP2-IkvyHa

"/dev/xvdb1" is a new physical volume of "100.00 GiB"

--- NEW Physical volume ---

PV Name /dev/xvdb1

VG Name

PV Size 100.00 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID lodesI-sjY8-K3Bo-ZzCz-ghQq-24rg-ITlzXm

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

[root@zwf~]# pvdisplay

---Physicalvolume---

PVName/dev/xvda2

VGNameVolGroup

PVSize19.51GiB/notusable3.00MiB

Allocatableyes(butfull)

PESize4.00MiB

TotalPE4994

FreePE0

AllocatedPE4994

PVUUIDQKYKlh-t5DO-1gFR-QZrl-I3iB-NbP2-IkvyHa

"/dev/xvdb1"isanewphysicalvolumeof"100.00 GiB"

---NEWPhysicalvolume---

PVName/dev/xvdb1

VGName

PVSize100.00GiB

AllocatableNO

PESize0

TotalPE0

FreePE0

AllocatedPE0

PVUUIDlodesI-sjY8-K3Bo-ZzCz-ghQq-24rg-ITlzXm

可以看到新添加的物理卷/dev/xvdb1,大小为100G,查看当前卷组情况:

[root@zwf ~]# vgdisplay

--- Volume group ---

VG Name VolGroup

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 19.51 GiB

PE Size 4.00 MiB

Total PE 4994

Alloc PE / Size 4994 / 19.51 GiB

Free PE / Size 0 / 0

VG UUID V6yHrx-YXrI-q6gb-fg51-ECNZ-cnE3-Oj0lNf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

[root@zwf~]# vgdisplay

---Volumegroup---

VGNameVolGroup

SystemID

Formatlvm2

MetadataAreas1

MetadataSequenceNo3

VGAccessread/write

VGStatusresizable

MAXLV0

CurLV2

OpenLV2

MaxPV0

CurPV1

ActPV1

VGSize19.51GiB

PESize4.00MiB

TotalPE4994

AllocPE/Size4994/19.51GiB

FreePE/Size0/0

VGUUIDV6yHrx-YXrI-q6gb-fg51-ECNZ-cnE3-Oj0lNf

将分区/dev/xvdb1转换为扩展分区:

[root@zwf ~]# vgextend VolGroup /dev/xvdb1

Volume group "VolGroup" successfully extended

1

2

[root@zwf~]# vgextend VolGroup /dev/xvdb1

Volumegroup"VolGroup"successfullyextended

查看逻辑卷:

[root@zwf ~]# lvdisplay

--- Logical volume ---

LV Path /dev/VolGroup/lv_root

LV Name lv_root

VG Name VolGroup

LV UUID YCl5Qf-H6rc-xIw1-0DCL-csgP-6jRV-J8wPzR

LV Write Access read/write

LV Creation host, time localhost.localdomain, 2015-06-05 14:15:42 +0800

LV Status available

# open 1

LV Size 17.51 GiB

Current LE 4482

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

--- Logical volume ---

LV Path /dev/VolGroup/lv_swap

LV Name lv_swap

VG Name VolGroup

LV UUID YZbRLA-gCBf-hPtV-mryG-szfu-j8i4-ulbcHj

LV Write Access read/write

LV Creation host, time localhost.localdomain, 2015-06-05 14:15:47 +0800

LV Status available

# open 1

LV Size 2.00 GiB

Current LE 512

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

[root@zwf~]# lvdisplay

---Logicalvolume---

LVPath/dev/VolGroup/lv_root

LVNamelv_root

VGNameVolGroup

LVUUIDYCl5Qf-H6rc-xIw1-0DCL-csgP-6jRV-J8wPzR

LVWriteAccessread/write

LVCreationhost,timelocalhost.localdomain,2015-06-0514:15:42+0800

LVStatusavailable

# open                 1

LVSize17.51GiB

CurrentLE4482

Segments1

Allocationinherit

Readaheadsectorsauto

-currentlysetto256

Blockdevice253:0

---Logicalvolume---

LVPath/dev/VolGroup/lv_swap

LVNamelv_swap

VGNameVolGroup

LVUUIDYZbRLA-gCBf-hPtV-mryG-szfu-j8i4-ulbcHj

LVWriteAccessread/write

LVCreationhost,timelocalhost.localdomain,2015-06-0514:15:47+0800

LVStatusavailable

# open                 1

LVSize2.00GiB

CurrentLE512

Segments1

Allocationinherit

Readaheadsectorsauto

-currentlysetto256

Blockdevice253:1

这里可以看到根分区的路径为:/dev/VolGroup/lv_root,查看扩展后的卷组情况

[root@zwf ~]# vgdisplay

--- Volume group ---

VG Name VolGroup

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 119.50 GiB

PE Size 4.00 MiB

Total PE 30593

Alloc PE / Size 4994 / 19.51 GiB

Free PE / Size 25599 / 100.00 GiB

VG UUID V6yHrx-YXrI-q6gb-fg51-ECNZ-cnE3-Oj0lNf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

[root@zwf~]# vgdisplay

---Volumegroup---

VGNameVolGroup

SystemID

Formatlvm2

MetadataAreas2

MetadataSequenceNo4

VGAccessread/write

VGStatusresizable

MAXLV0

CurLV2

OpenLV2

MaxPV0

CurPV2

ActPV2

VGSize119.50GiB

PESize4.00MiB

TotalPE30593

AllocPE/Size4994/19.51GiB

FreePE/Size25599/100.00GiB

VGUUIDV6yHrx-YXrI-q6gb-fg51-ECNZ-cnE3-Oj0lNf

此时还没刷新根分区大小,看到的分区还没有添加

[root@zwf ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

18G 3.4G 13G 21% /

tmpfs 3.9G 0 3.9G 0% /dev/shm

/dev/xvda1 477M 52M 400M 12% /boot

1

2

3

4

5

6

[root@zwf~]# df -h

FilesystemSizeUsedAvailUse%Mountedon

/dev/mapper/VolGroup-lv_root

18G3.4G13G21%/

tmpfs3.9G03.9G0%/dev/shm

/dev/xvda1477M52M400M12%/boot

刷新根分区大小:

[root@zwf ~]# lvextend -L +99.99G /dev/VolGroup/lv_root

Rounding size to boundary between physical extents: 99.99 GiB

Size of logical volume VolGroup/lv_root changed from 17.51 GiB (4482 extents) to 117.50 GiB (30080 extents).

Logical volume lv_root successfully resized

[root@zwf ~]# e2fsck -f /dev/VolGroup/lv_root

e2fsck 1.41.12 (17-May-2010)

/dev/VolGroup/lv_root is mounted.

e2fsck: Cannot continue, aborting.

1

2

3

4

5

6

7

8

[root@zwf~]# lvextend -L +99.99G /dev/VolGroup/lv_root

Roundingsizetoboundarybetweenphysicalextents:99.99GiB

SizeoflogicalvolumeVolGroup/lv_rootchangedfrom17.51GiB(4482extents)to117.50GiB(30080extents).

Logicalvolumelv_rootsuccessfullyresized

[root@zwf~]# e2fsck -f /dev/VolGroup/lv_root

e2fsck1.41.12(17-May-2010)

/dev/VolGroup/lv_rootismounted.

e2fsck:Cannotcontinue,aborting.

命令resize2fs即刷新根分区“/dev/VolGroup/lv_root”的容量,再次查看次磁盘分区情况

[root@zwf ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

116G 3.4G 107G 4% /

tmpfs 3.9G 0 3.9G 0% /dev/shm

/dev/xvda1 477M 52M 400M 12% /boot

1

2

3

4

5

6

[root@zwf~]# df -h

FilesystemSizeUsedAvailUse%Mountedon

/dev/mapper/VolGroup-lv_root

116G3.4G107G4%/

tmpfs3.9G03.9G0%/dev/shm

/dev/xvda1477M52M400M12%/boot

添加分区成功。

转载请注明: 版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!

最后编辑:2015-12-09作者:Jerry

一个积极向上的小青年,热衷于分享--Focus on DB,BI,ETL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS中添加硬盘并扩容分区的步骤如下: 1. 首先,确保你已经连接好了新的硬盘到计算机,并且已经被识别到了系统中。你可以通过使用`sudo fdisk -l`命令来查看所有已连接的硬盘和分区。 2. 接下来,使用`sudo fdisk /dev/sdX`命令(X代表新硬盘的设备名)来对新硬盘进行分区。按下n创建新分区,然后选择主分区或扩展分区,然后设置分区的起始和结束柱面等信息。 3. 分区创建完成后,我们需要将新分区格式化为文件系统。使用`sudo mkfs.ext4 /dev/sdX1`命令(X代表新分区的序号)将分区格式化为ext4文件系统。 4. 接下来,我们需要将新分区挂载到系统中。首先创建一个目录作为挂载点,比如`sudo mkdir /mnt/newdisk`。然后使用`sudo mount /dev/sdX1 /mnt/newdisk`命令将新分区挂载到该目录上。 5. 现在我们可以将分区的数据复制到新硬盘上。使用`sudo rsync -avxHAX / /mnt/newdisk`命令来复制分区的数据。这可能需要一些时间,所以请耐心等待。 6. 复制完成后,我们需要更新/boot/grub/menu.lst文件以指向新硬盘的分区。打开该文件,找到原来的分区的设备名,并将其替换为新硬盘的设备名。 7. 最后,我们需要更新grub并重新启动。使用`sudo grub-install /dev/sdX`命令,将grub安装到新硬盘上。然后,使用`sudo reboot`命令重新启动计算机。 在重启后,系统将会使用新硬盘的扩容分区运行。你可以使用`df -h`命令来检查分区大小是否已经扩容成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值