# swapoff
# cfdisk /dev/sda1
图形化的界面 删除swap即可
如果你的系统是ext3格式的分区,那么可以将删除掉的swap占用的空间扩充到邻近的分区上,注意 这一步需要在livecd环境中进行
以livecd启动, 个人建议knoppix 比较好,注意 以下的是我在虚拟机种测试的输出, 请按照你的实际情况来 *** 作, 千万不可完全的照搬,否则一定会损坏数据
P.S 这个建议现在虚拟机里面练习下,否则 以下 *** 作对于新手来讲还是有一定难度的, 倒不如重新安装一遍来的快和安全,另外 不管内存多大, 适当预留一些swap谨防万一是个好的预防措施...
我个人是认为 没必要care这2g 除非你空间真的十分紧张
卸载sda1:
umount /dev/sda1
然后执行:
fsck -n /dev/sda1
输出:
fsck 1.38 (30-Jun-2005)
e2fsck 1.38 (30-Jun-2005)
/dev/sda1: clean, 159036/765536 files, 1080014/1536000 blocks
然后是:
tune2fs -O ^has_journal /dev/sda1
输出:
tune2fs 1.38 (30-Jun-2005)
接下来运行:
fdisk /dev/sda
输出:
(Yes, it's /dev/sda, not /dev/sda1.)
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Type m to get a list of all commands:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only
我们来打印分区表:
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 789 6337611 83 Linux
/dev/sda2 1248 1305 465885 5 Extended
/dev/sda5 1248 1305 465853+ 82 Linux swap / Solaris
现在,删除第一个分区:
Command (m for help): d
Partition number (1-5): 1
然后创建一个新的sda1分区,大体事项和缩小分区步骤一:
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4): 1
现在就该确定最开始和末尾的柱面号,首先输出起始柱面号:
First cylinder (1-1305, default 1):
然后fdisk会告述我们可能的最大柱面号,在这里是1247,然后我们直接输入就行了:
Last cylinder or +size or +sizeM or +sizeK (1-1247, default 1247): 1247
然后看一下新的分区表:
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 1247 10016496 83 Linux
/dev/sda2 1248 1305 465885 5 Extended
/dev/sda5 1248 1305 465853+ 82 Linux swap / Solaris
别忘了,之前的分区是启动分区,所以还需要做:
Command (m for help): a
Partition number (1-5): 1
最后写入:
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.
Syncing disks.
然后重新启动。还是启动到live-CD环境中(或者rescue模式),用su命令再次切换成root用户,然后运行:
fsck -n /dev/sda1
输出应该是这样的:
fsck 1.38 (30-Jun-2005)
e2fsck 1.38 (30-Jun-2005)
/dev/sda1: clean, 159036/765536 files, 1047239/1536000 blocks
接下来,在新的/dev/sda1上创建日志文件,转换回ext3文件系统:
tune2fs -j /dev/sda1
tune2fs 1.38 (30-Jun-2005)
Creating journal inode: done
This filesystem will be automatically checked every 30 mounts or
0 days, whichever comes first. Use tune2fs -c or -i to override.
好了,这下完成了。再次重启,启动到你原来的系统中,看看:
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 9859036 4224032 5234348 45% /
varrun 95480 132 95348 1% /var/run
varlock 95480 0 95480 0% /var/lock
udev 10240 52 10188 1% /dev
devshm 95480 0 95480 0% /dev/shm
lrm 95480 17580 77900 19% /lib/modules/2.6.17-10-generic/volatile
df -B 4k
Filesystem 4K-blocks Used Available Use% Mounted on
/dev/sda1 2464759 1056008 1308587 45% /
varrun 23870 33 23837 1% /var/run
varlock 23870 0 23870 0% /var/lock
udev 2560 13 2547 1% /dev
devshm 23870 0 23870 0% /dev/shm
lrm 23870 4395 19475 19% /lib/modules/2.6.17-10-generic/volatile
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.5G 4.1G 5.0G 45% /
varrun 94M 132K 94M 1% /var/run
varlock 94M 0 94M 0% /var/lock
udev 10M 52K 10M 1% /dev
devshm 94M 0 94M 0% /dev/shm
lrm 94M 18M 77M 19% /lib/modules/2.6.17-10-generic/volatile
fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1247 10016496 83 Linux
/dev/sda2 1248 1305 465885 5 Extended
/dev/sda5 1248 1305 465853+ 82 Linux swap / Solaris
fdisk -s /dev/sda1
10016496
1、首先输入下方的代码:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
FILE *file
int opt
char *optstring = "a:b:c:d"
char fname[50]
while ((opt = getopt(argc, argv, optstring)) != -1)
2、然后再输入下方的代码:
{
switch(opt)
{
case 'a':
strcpy(fname,optarg)
if(mkdir(fname,0777)==-1)
printf("fail to build directionary\n")
// if((file=fopen(fname,"w+"))==NULL)
// printf("open file error\n")
break
}
}
return 0
}
3、最后这样就完成了,效果如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)