既然这机器上要跑KVM。那么20G 显然小了一点。扩展一下咯。
1 vm 里设置--硬盘--扩展--扩展至50G
2 这里就很傻了,fdisk一下,不清楚命令可以m打印看看。
在分配前p一下看看总是不会错的,然后n 新建。把所有空间都分配给一个扩展分区。
再p看一下。ok.扩展分区有啦。
fdisk /dev/sda Command (m for help): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 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: 0x0004f14b Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2350 18566144 83 Linux /dev/sda3 2350 2611 2097152 82 Linux swap / Solaris Command (m for help): n Command action e extended p primary partition (1-4) e Selected partition 4 First cylinder (2611-6527, default 2611): Using default value 2611 Last cylinder, +cylinders or +size{K,M,G} (2611-6527, default 6527): Using default value 6527 Command (m for help): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 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: 0x0004f14b Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2350 18566144 83 Linux /dev/sda3 2350 2611 2097152 82 Linux swap / Solaris /dev/sda4 2611 6527 31456607+ 5 Extended
3 新建逻辑分区,继续刚才的再n 一下,他还是从 2611 开始,也就是在扩展分区里面运作,我+20G
先。再p 一下,OK ,其他的我还没想好用来干啥。先这样吧,w 保存退出,如果刚才分错了是q退出。
Command (m for help): n First cylinder (2611-6527, default 2611): Using default value 2611 Last cylinder, +cylinders or +size{K,M,G} (2611-6527, default 6527): +20G Command (m for help): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 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: 0x0004f14b Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2350 18566144 83 Linux /dev/sda3 2350 2611 2097152 82 Linux swap / Solaris /dev/sda4 2611 6527 31456607+ 5 Extended /dev/sda5 2611 5222 20974163+ 83 Linux Command (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: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
4. 他最后又个warning,意思就是这个告诉你保存建立分区,还没真生效,你重启一下或者执行命令才行。
ls /dev/sda* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3
恩,果然没有设备文件,那还是执行一下命令吧。
partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 ls /dev/sda* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
执行会提示几个error,那不是问题,执行完了,再ls 一下,设备文件出现。那就是真成功了。
5. 在我们使用这个空间之前,我们需要先将他格式化,mkfs命令就是这个作用,mkfs下有许多的命令,是格式化成各种格式,我们用ext4
mkfs.ext4 /dev/sda5 #省略过程一万字 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
那最后这样就算成功了。
6. 既然是磁盘空间我们肯定要长期挂载使用,需要写入fstab 文件中。我们先cat一下文件。
UUID=06280bc4-de78-4f46-b39e-d3fac6f48b50 / ext4 defaults 1 1 UUID=2ac81b7a-6c84-43ee-92e3-59ee3faaabdb /boot ext4 defaults 1 2 UUID=140959ff-7320-47f1-8620-a958e631141e 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
呐。有点乱,基本格式就是这么6列,设备/挂载点/挂载格式/参数/备份/检测
第一列我们可以写 /dev/sda5 也可以写UUID,后者更加唯一性。bldid 可以获得uuid
那么我们也依样画葫芦好了,新建一个/myspace 目录挂载给他
blkid /dev/sda5 /dev/sda5: UUID="4e887f42-b19a-4d74-b694-9a8f36a9ed61" TYPE="ext4" mkdir /myspace vim /etc/fstab UUID=4e887f42-b19a-4d74-b694-9a8f36a9ed61 /myspace ext4 defaults 0 0
vim编辑这个文件,我们添加了这么一行。这时候,执行mount -a 可以不重启重新挂载fstab 中的内容。 再df -h 看看
mount -a df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 3.0G 14G 18% / tmpfs 1.9G 224K 1.9G 1% /dev/shm /dev/sda1 291M 39M 238M 14% /boot /dev/sda5 20G 172M 19G 1% /myspace
OK 这样。就算成功了咯~