centos7扩展根分区
生活随笔
收集整理的這篇文章主要介紹了
centos7扩展根分区
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
購買的云主機,安裝centos7后,發現系統根分區只有8.5G,而云主機硬盤大小是110G。
現在想把剩余的硬盤大小找出來,然后擴容至根分區。
本文主題是:centos擴展根分區。由于阿里云,騰訊云在購買主機時,硬盤大小即為根分區
大小,沒有遇到到需要擴容的情況。
1、查看硬盤大小信息
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 8.5G 1.5G 7.0G 18% /
devtmpfs 231M 0 231M 0% /dev
tmpfs 241M 0 241M 0% /dev/shm
tmpfs 241M 4.3M 237M 2% /run
tmpfs 241M 0 241M 0% /sys/fs/cgroup
/dev/sda1 494M 124M 371M 25% /boot
tmpfs 49M 0 49M 0% /run/user/0# 發現只有8.5G,總大小沒有110G 發現根目錄只有8.5G,總大小沒有110G,然后使用fdisk -l命令查看,發現剩余的空間在sdb第二個磁盤上:[root@localhost ~]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x000f1903Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 20971519 9972736 8e Linux LVMDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/centos-root: 116.5 GB, 116505182208 bytes, 227549184 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
發現sdb磁盤有3個分區,分別是:sdb1、sdb2、sdb3,上面截圖是我完成后的,所以看到sdb只有一個分區。
2、刪除分區、磁盤分區
# fdisk /dev/sdb? ? ? ?#將磁盤分區 #先刪除分區,再將磁盤分為一個區
m ----->?打印help信息
d?----->?刪除分區
p ----->? 打印sdb磁盤的分區信息
n?----->? 創建新分區,進到分區項后,按p直接分區,默認分為一個區,自行選擇分區數量。
w?----->? 保存分區信息,不然分區無法正確完成。
?
[root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them. Be careful before using the write command.Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xef6f1f81.The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted.Command (m for help): m Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help): n Partition type:p primary (0 primary, 0 extended, 4 free)e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-209715199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): Using default value 209715199 Partition 1 of type Linux and of size 100 GiB is setCommand (m for help): pDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0xef23a9cbDevice Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 LinuxCommand (m for help): w The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks.?
3、格式化磁盤
# mkfs.ext4 /dev/sdb #格式化為ext4格式 [root@localhost ~]# mkfs.ext4 /dev/sdb mke2fs 1.42.9 (28-Dec-2013) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Discarding device blocks: done Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214400 blocks 1310720 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2174746624 800 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, 4096000, 7962624, 11239424, 20480000, 23887872Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done4、創建物理卷
# pvcreate /dev/sdb [root@localhost ~]# pvcreate /dev/sdb WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: yWiping ext4 signature on /dev/sdb.Physical volume "/dev/sdb" successfully created5、查看卷組名稱
# vgdisplay -v# 查看到我的VG Name為“centos” [root@localhost ~]# vgdisplay -vUsing volume group(s) on command line.--- Volume group ---VG Name centosSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 9.51 GiBPE Size 4.00 MiBTotal PE 2434Alloc PE / Size 2424 / 9.47 GiBFree PE / Size 10 / 40.00 MiBVG UUID OyB5dN-0LOk-6vb1-Qmtu-1EQp-1GtB-Szuco0--- Logical volume ---LV Path /dev/centos/swapLV Name swapVG Name centosLV UUID 9SLqUm-dXfi-bNle-wdX1-cnZQ-HCun-nGWdXkLV Write Access read/writeLV Creation host, time localhost.localdomain, 2016-06-28 02:34:19 +0800LV Status available# open 2LV Size 1.00 GiBCurrent LE 256Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:1--- Logical volume ---LV Path /dev/centos/rootLV Name rootVG Name centosLV UUID J3ANyS-BTG5-YJ8M-2Zsq-sBUo-YVWg-jyFmvALV Write Access read/writeLV Creation host, time localhost.localdomain, 2016-06-28 02:34:19 +0800LV Status available# open 1LV Size 8.47 GiBCurrent LE 2168Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:0--- Physical volumes ---PV Name /dev/sda2 PV UUID P6xf6f-NPgl-s3Dm-123h-B5e3-NJBh-GbNM1nPV Status allocatableTotal PE / Free PE 2434 / 10
6、將物理卷擴展到卷組
# vgextend centos /dev/sdb
[root@localhost ~]# vgextend centos /dev/sdbVolume group "centos" successfully extended7、將卷組中的空閑空間擴展到根分區邏輯卷
#lvextend -l +100%FREE /dev/centos/root
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root Size of logical volume centos/root changed from 8.47 GiB (2168 extents) to 108.50 GiB (27777 extents).Logical volume root successfully resized.8、刷新根分區
# xfs_growfs /dev/centos/root
[root@localhost ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=555008 blks= sectsz=4096 attr=2, projid32bit=1= crc=0 finobt=0 data = bsize=4096 blocks=2220032, 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=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 2220032 to 284436489、查看擴展是否成功
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 109G 1.5G 108G 2% / devtmpfs 231M 0 231M 0% /dev tmpfs 241M 0 241M 0% /dev/shm tmpfs 241M 4.3M 237M 2% /run tmpfs 241M 0 241M 0% /sys/fs/cgroup /dev/sda1 494M 124M 371M 25% /boot tmpfs 49M 0 49M 0% /run/user/0看到根分區已為109G大小,擴展根分區成功!
?
?轉載于:https://www.cnblogs.com/catinsky/p/9318380.html
總結
以上是生活随笔為你收集整理的centos7扩展根分区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蛋姑爷做法怎样才才好吃?
- 下一篇: 波利王超级蔓越莓一般要吃多久?