環境:
CentOS 6.9
平常在VMware上建立Linux系統虛擬機器的時候,往往當時不會給太多的磁碟空間,在後期的使用過程中經常會遇到磁碟空間不足的情況,所以需要對Linux系統擴充套件磁碟空間。
擴充套件磁碟步驟:1.磁碟擴充套件
此時雖然在VMware虛擬機器管理介面的擴容操作已經完成,但是這還只是擴容的第一步,後面還需要到作業系統內部進行操作。
2.檢視分割槽資訊
[root@test-centos6 ~]# fdisk -lDisk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000a16bc Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2611 20458496 8e Linux LVMDisk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes255 heads, 63 sectors/track, 2285 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[root@test-centos6 ~]# lsblk //列出塊裝置資訊NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 447M 0 romsda 8:0 0 60G 0 disk├─sda1 8:1 0 500M 0 part /boot└─sda2 8:2 0 19.5G 0 part ├─vg_testcentos6-lv_root (dm-0) 253:0 0 17.5G 0 lvm / └─vg_testcentos6-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]
可以看到目前磁碟/dev/sda已經有兩個分割槽,分別為sda1、sda2。
3.新建分割槽sda3
[root@test-centos6 ~]# fdisk /dev/sdaWARNING: 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): m //列出可以執行的命令Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition //選擇分割槽,刪除現有分割槽 o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)Command (m for help): n //建立新的磁碟分割槽Command action e extended //邏輯分割槽 p primary partition (1-4) //主分割槽 p //建立主分割槽Partition number (1-4): 3 //輸入分割槽號First cylinder (2611-7832, default 2611): //分割槽起始位置(可直接回車也可以根據情況輸入)Using default value 2611Last cylinder, +cylinders or +size{K,M,G} (2611-7832, default 7832): //回車Using default value 7832Command (m for help): p //列出磁碟目前的分割槽情況Disk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000a16bc Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2611 20458496 8e Linux LVM/dev/sda3 2611 7832 41939020 83 LinuxCommand (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: 裝置或資源忙.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks. //正在同步磁碟[root@test-centos6 ~]# fdisk -l //檢視分割槽建立情況Disk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000a16bc Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2611 20458496 8e Linux LVM/dev/sda3 2611 7832 41939020 83 LinuxDisk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes255 heads, 63 sectors/track, 2285 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
4.重啟系統並格式化分割槽sda3檔案系統
[root@test-centos6 ~]# reboot[root@test-centos6 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 447M 0 romsda 8:0 0 60G 0 disk├─sda1 8:1 0 500M 0 part /boot├─sda2 8:2 0 19.5G 0 part│ ├─vg_testcentos6-lv_root (dm-0) 253:0 0 17.5G 0 lvm /│ └─vg_testcentos6-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]└─sda3 8:3 0 40G 0 part[root@test-centos6 ~]# mkfs.ext4 /dev/sda3 //將/dev/sda3分割槽檔案系統格式化為ext4mke2fs 1.41.12 (17-May-2010)檔案系統標籤=作業系統:Linux塊大小=4096 (log=2)分塊大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks2621440 inodes, 10484755 blocks524237 blocks (5.00%) reserved for the super user第一個資料塊=0Maximum filesystem blocks=4294967296320 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624正在寫入inode表: 完成Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成This filesystem will be automatically checked every 35 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
5.建立物理卷(pv)
此步驟可省略:當將分割槽直接新增到卷組(vg)時,LVM會自動將分割槽轉換為物理卷(pv)。
[root@test-centos6 ~]# lvmlvm> pvcreate /dev/sda3 //建立物理卷pv Physical volume "/dev/sda3" successfully createdlvm> pvdisplay //顯示物理卷pv資訊 --- Physical volume --- PV Name /dev/sda2 VG Name vg_testcentos6 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 jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC "/dev/sda3" is a new physical volume of "40.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 40.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlplvm> pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name vg_testcentos6 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 jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC "/dev/sda3" is a new physical volume of "40.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 40.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlp
6.檢視並建立卷組(vg)
lvm> vgdisplay //檢視需要擴充套件的卷組vg名稱 --- Volume group --- VG Name vg_testcentos6 //卷組vg名稱 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 59.49 GiB PE Size 4.00 MiB Total PE 17790 Alloc PE / Size 15232 / 19.50 GiB Free PE / Size 2558 / 9.99 GiB VG UUID yVVWYi-mV3I-f1WI-2QeH-HkVT-oBXP-2KkQ8vlvm> vgextend vg_testcentos6 /dev/sda3 //擴展卷組(這裡的“vg_testcentos6”名稱為上面的卷組名稱) Volume group "vg_testcentos6" successfully extended
7.擴充套件邏輯卷(lv)
[root@test-centos6 ~]# df -h //檢視擴充套件路徑,這裡也可以用fdisk -l檢視Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg_testcentos6-lv_root -----》 //**擴充套件路徑** 18G 18G 0 100% /tmpfs 1.9G 0 1.9G 0% /dev/shm/dev/sda1 485M 58M 403M 13% /boot[root@test-centos6 ~]# lvm //進入LVM管理器lvm> lvextend -L +39.99G /dev/mapper/vg_testcentos6-lv_root //擴充套件邏輯卷lv大小(透過fdisk -l/df -h檢視要擴充套件過去的磁碟) Rounding size to boundary between physical extents: 39.99 GiB. Size of logical volume vg_testcentos6/lv_root changed from 17.51 GiB (4482 extents) to 57.50 GiB (14720 extents) Logical volume lv_root successfully resized.lvm> lvscan ACTIVE '/dev/vg_testcentos6/lv_root' [57.50 GiB] inherit ACTIVE '/dev/vg_testcentos6/lv_swap' [2.00 GiB] inheritlvm> pvscan PV /dev/sda2 VG vg_testcentos6 lvm2 [19.51 GiB / 0 free] PV /dev/sda3 VG vg_testcentos6 lvm2 [39.99 GiB / 0 free] Total: 2 [59.50 GiB] / in use: 2 [59.50 GiB] / in no VG: 0 [0 ]lvm> exit Exiting.
8.檢視分割槽情況
[root@test-centos6 ~]# fdisk -lDisk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000a16bc Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2611 20458496 8e Linux LVM/dev/sda3 2611 7832 41939020 83 LinuxDisk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes255 heads, 63 sectors/track, 2285 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
注意:上面雖然顯示物理卷/dev/sdb3有40G空閒,但是這裡不能全部使用,可能只有39.99G可以使用。
7.啟用即重新讀取磁碟資訊
檢視/dev/mapper/vg_testcentos6-lv_root的Type為ext4,所以使用resize2fs;如果檔案型別是 xfs ,則使用xfs_growfs命令格式化。
[root@test-centos6 ~]# blkid //檢視檔案系統/dev/sda1: UUID="32a489a3-65c2-43a4-9aff-12c03eabc4dd" TYPE="ext4"/dev/sda2: UUID="jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC" TYPE="LVM2_member"/dev/sda3: UUID="PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlp" TYPE="LVM2_member"/dev/mapper/vg_testcentos6-lv_root: UUID="e8adf717-e78c-4845-a750-2a22a60689ed" TYPE="ext4" //可以看到檔案系統格式化為ext4/dev/mapper/vg_testcentos6-lv_swap: UUID="ac33f130-95cc-4046-8bdd-db2d7c450f6d" TYPE="swap"[root@test-centos6 ~]# resize2fs /dev/mapper/vg_testcentos6-lv_root //ext4檔案系統使用resize2fsresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/mapper/vg_testcentos6-lv_root is mounted on /; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 4Performing an on-line resize of /dev/mapper/vg_testcentos6-lv_root to 15073280 (4k) blocks.The filesystem on /dev/mapper/vg_testcentos6-lv_root is now 15073280 blocks long.[root@test-centos6 ~]# df -h //檢視啟用狀態Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg_testcentos6-lv_root 57G 4.4G 50G 9% /tmpfs 1.9G 244K 1.9G 1% /dev/shm/dev/sda1 485M 58M 403M 13% /boot
可以看到現在我們的磁碟已經從最開始的19G擴充套件到了57G。
最新評論