Linux下面增加磁盘空间
2024-08-28 00:18:52
供稿:网友
我的linux虚拟机分的2G空间不够用了,在网上查找相关资料,工具倒是挺多的,现学现用,一知半解,摸索着搞了好久,最后终于加载上了。
1.先看看情况
[root@localhost tmp]# fdisk -l
Disk /dev/sda: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 261 2096451 83 Linux
/dev/sda2 262 391 1044225 82 Linux swap
看到我原先给linux分了两个区,一个是linux(2G),一个是linux swap(竟然有1G)这个swap的空间那么大呢,可是好像用不上,那就只能从它开刀了。得修改分区表。
2.分区工具parted
[root@localhost tmp]# parted
然后就进入parted的命令环境了(parted) print
--打印当前分区信息
Disk geometry for /dev/sda: 0.000-3072.000 megabytes
Disk label type: msdos
Minor Start End Type Filesystem Flags
1 0.031 2047.346 primary ext3 boot
2 2047.346 3067.097 primary linux-swap
根据帮助的指示,觉得resize命令可能就是我要找的,先把分区2变小
(parted) resize 2 3000 3067.097
执行完了,再看看结果如何
(parted) print
Disk geometry for /dev/sda: 0.000-3072.000 megabytes
Disk label type: msdos
Minor Start End Type Filesystem Flags
1 0.031 2047.346 primary ext3 boot
2 2996.499 3067.097 primary linux-swap
果然改变了,那么把分区1变大吧
(parted) resize 1 0.031 2996.499
Warning: Filesystem was not cleanly unmounted! You should e2fsck.
Ignore/Cancel? c
好像这么弄不行,那就算了,另想个办法,把空出的空间单独作为一个分区吧。
(parted) mkpartfs primary ext2 2047.346 2996.499
(parted) print
Disk geometry for /dev/sda: 0.000-3072.000 megabytes
Disk label type: msdos
Minor Start End Type Filesystem Flags
1 0.031 2047.346 primary ext3 boot
3 2047.346 2996.499 primary ext2
2 2996.499 3067.097 primary linux-swap
这个方法奏效了
退出再看看
[root@localhost tmp]# fdisk -l
Disk /dev/sda: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 261 2096451 83 Linux
/dev/sda2 383 391 72292+ 82 Linux swap
/dev/sda3 262 382 971932+ 83 Linux
3、对分区进行格式化,以及加载;
先提示一下;用 mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs 等命令来格式化分区,比如我想格式化 sda3为ext3文件系统,则输入;
[root@localhost tmp]# mkfs.ext3 /dev/sda3