虚拟机硬盘不足

[root@bass virhost]# qemu-img create -f raw 5g.raw 5G
Formatting '5g.raw', fmt=raw size=5368709120 
[root@bass virhost]# cp 5g.raw 
[root@bass virhost]# cp 5g.raw 5g.raw.bak

 23lmr为虚机名 注意/home/virhost/5g.raw新增的磁盘必是绝对路径!!!

[root@bass virhost]# virsh attach-disk 23lmr /home/virhost/5g.raw vdb --cache none#vdb可以是(vdc,vda,vdb,vde等)
Disk attached successfully
[root@lmr lnmp]# fdisk -l

Disk /dev/vda: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a136a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       10403     4729856   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 4303 MB, 4303355904 bytes
255 heads, 63 sectors/track, 523 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: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 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/vdb: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

 

 

[root@lmr lnmp]# fdisk /dev/vdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x30dadc82.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10402, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10402, default 10402): 
Using default value 10402

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

[root@lmr lnmp]# mkfs.ext3 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@lmr lnmp]# fdisk -l

Disk /dev/vda: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a136a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       10403     4729856   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 4303 MB, 4303355904 bytes
255 heads, 63 sectors/track, 523 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: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 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/vdb: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc1594d7d

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       10402     5242576+  83  Linux

 编辑配置文件:

[root@bass ~]# virsh edit 23lmr
Domain 23lmr XML configuration not changed.
--------------------------------------
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/home/virhost/23lnmp_memache_redis.raw'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
#在磁盘代码的后面加上下面的代码
    <disk tpye='file' device='disk'>
    <driver name='qemu' type='raw' cache='none'/>
    <source file='/home/virhost/5g.raw'/>
    <target dev='vdb' bus='virtio'/>
    </disk>

 如果不加入上框内的代码重启后会,无法挂载磁盘,并无法启动成功!!!

 创建挂载点:

[root@lmr lnmp]# mkdir /nd

 

[root@lmr lnmp]# mount /dev/vdb1 /nd
[root@lmr lnmp]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      3.9G  3.2G  502M  87% /
tmpfs                 245M     0  245M   0% /dev/shm
/dev/vda1             477M   33M  419M   8% /boot
/dev/vdb1             5.0G  139M  4.6G   3% /nd

 系统启动,自动挂载数据盘

查看磁盘UUID信息:

[root@lmr lnmp]# blkid
/dev/vda1: UUID="34e5bf8b-5152-4d91-9ebf-8f98217395d3" TYPE="ext4" 
/dev/vda2: UUID="MpbaAJ-JfHb-GXvj-BEEu-wFD2-XSUX-5AbirT" TYPE="LVM2_member" 
/dev/mapper/VolGroup-lv_root: UUID="1a94c909-6e3a-4cf8-bd62-e3d5e298aa93" TYPE="ext4" 
/dev/mapper/VolGroup-lv_swap: UUID="01c6ea43-dc10-44d9-87df-ba308b94ebac" TYPE="swap" 
/dev/vdb1: UUID="06dd7613-4629-4964-a56a-b75f583b6030" TYPE="ext3" 

 编辑系统分区表

vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Jul 11 09:48:39 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=34e5bf8b-5152-4d91-9ebf-8f98217395d3 /boot                   ext4    defaults        1 2
UUID=06dd7613-4629-4964-a56a-b75f583b6030 /nd                     ext3    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

 

重启动 -----》制动挂载成功
[root@lmr ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      3.9G  3.2G  502M  87% /
tmpfs                 245M     0  245M   0% /dev/shm
/dev/vda1             477M   33M  419M   8% /boot
/dev/vdb1             5.0G  139M  4.6G   3% /nd

!!!!!!!!!!!注意重reboot没问题,但关机后(包括正常关机),再开启就会报错(如果不在虚机的配置文件中添加相关代码,的情况下会报错,并无法启动),如下图:

这种情况下输入密码( 是指root的密码),会进入,但在这种模式下,所有的文件都是只读的(root),解决方法:

mount -o remount,rw /

 执行这条命令后,权限恢复正常

注释/etc/fstab 中的挂载项,如下图

在实体机上执行如下命令:

重新去掉/etc/fstab 中注释掉的挂载项前面的#号

 

posted @ 2016-07-11 11:40  bass  阅读(319)  评论(0编辑  收藏  举报