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