当前位置:文档之家› VM虚拟机中Linux扩展根分区空间

VM虚拟机中Linux扩展根分区空间

VM虚拟机中Linux扩展根分区空间修改记录目录1检查LVM (1)2VMWare扩展设置 (1)3开启虚拟机 (2)4查看分区状况 (3)5查看lvm状态 (3)6生成分区/dev/sda3 (4)7重读磁盘分区 (5)8格式化/dev/sda3 (5)9lvm 扩容 (5)1 检查LVM看到文章说必须基于LVM,那是不是呢?命令检验一下。

据说centos默认安装也是LVM的[root@SQL2 ~]# lvdisplay2 VMWare扩展设置关闭centos,打开VMWare软件,展开需要扩展的linux服务器按如图所示步骤,点出扩展磁盘容量对话框此处,改成80,启动虚拟机3 开启虚拟机#查看当前硬盘使用情况,如下所示,50G而已[root@SQL2 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 46G 12G 35G 25% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 84K 1.9G 1% /dev/shm tmpfs 1.9G 8.9M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 159M 339M 32% /boot tmpfs 379M 12K 379M 1% /run/user/42 tmpfs 379M 0 379M 0% /run/user/04 查看分区状况#sda已经扩展到80G了[root@SQL2 ~]# fdisk /dev/sdaWelcome 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.Command (m for help): pDisk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0006069dDevice Boot Start End Blocks Id System/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 104857599 51915776 8e Linux LVMCommand (m for help):5 查看lvm状态[root@SQL2 ~]# pvsPV VG Fmt Attr PSize PFree/dev/sda2 centos lvm2 a-- 49.51g 44.00m[root@SQL2 ~]# vgsVG #PV #LV #SN Attr VSize VFreecentos 1 2 0 wz--n- 49.51g 44.00m[root@SQL2 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot centos -wi-ao---- 45.59gswap centos -wi-ao---- 3.88g6 生成分区/dev/sda3[root@SQL2 ~]# fdisk /dev/sdaWelcome 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.Command (m for help): pDisk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0006069dDevice Boot Start End Blocks Id System/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 104857599 51915776 8e Linux LVMCommand (m for help): nPartition type:p primary (2 primary, 0 extended, 2 free)e extendedSelect (default p): pPartition number (3,4, default 3): 3First sector (104857600-167772159, default 104857600): #回车Using default value 104857600Last sector, +sectors or +size{K,M,G} (104857600-167772159, default 167772159): #回车Using default value 167772159Partition 3 of type Linux and of size 30 GiB is setCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 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.7 重读磁盘分区[root@SQL2 ~]# partprobe8 格式化/dev/sda3[root@SQL2 ~]# mkfs.ext4 /dev/sda3mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1966080 inodes, 7864320 blocks393216 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2155872256240 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,4096000Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done9 lvm 扩容[root@SQL2 ~]# pvcreate /dev/sda3WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sda3.Physical volume "/dev/sda3" successfully created[root@SQL2 ~]# pvsPV VG Fmt Attr PSize PFree/dev/sda2 centos lvm2 a-- 49.51g 44.00m #标红为组名,下步会用到/dev/sda3 lvm2 --- 30.00g 30.00g[root@SQL2 ~]# vgextend centos /dev/sda3 #(注意组名)Volume group "centos" successfully extended#此处+29.9表示大约扩展30G空间,若是此处设置为80G 也是可行,表示扩展后总容量[root@SQL2 ~]# lvextend -L +29.9G /dev/mapper/centos-root /dev/sda3Rounding size to boundary between physical extents: 29.90 GiBSize of logical volume centos/root changed from 45.59 GiB (11671 extents) to 75.49 GiB (19326 extents).Logical volume root successfully resized.#若此处报错,可以不管,执行下个resize2fs命令,若正确,可忽略resize2fs命令[root@SQL2 ~]# resize2fs /dev/mapper/centos-rootresize2fs 1.42.9 (28-Dec-2013)resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root Couldn't find valid filesystem superblock.[root@SQL2 ~]# resize2fs /dev/mapper/centos-rootresize2fs 1.42.9 (28-Dec-2013)resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root Couldn't find valid filesystem superblock.[root@SQL2 ~]# xfs_growfs /dev/mapper/centos-rootmeta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2987776 blks= sectsz=512 attr=2, projid32bit=1= crc=0 finobt=0data = bsize=4096 blocks=11951104, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal bsize=4096 blocks=5835, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 11951104 to 19789824[root@SQL2 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 76G 12G 65G 15% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 84K 1.9G 1% /dev/shmtmpfs 1.9G 9.0M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 497M 159M 339M 32% /boot tmpfs 379M 16K 379M 1% /run/user/42 tmpfs 379M 0 379M 0% /run/user/0 [root@SQL2 ~]#。

相关主题