改变Linux分区大小
一般来说,Linux系统根分区(一般是Ext2、Ext3、ReiserFS格式)是无法改变容量的,这一点与Windows下的FAT32、NTFS 颇有不同。我曾经试了一下,不但改变容量不行,移动分区位置更是不行,启动时无法进入系统,或者在GDM处出错。但有一种方法可以却实现上述目的,我在 Ubuntu 7.04下试验成功:
1、用Ghost工具将Linux根分区备份为镜像。ghost是windows下常用的软件,其备份效率和压缩比都比较高,一般来说 ghost8.0以上的版本对linux分区支持较好,推荐使用ghost11。用ghost备份linux分区速度比备份windows分区要慢一半,用最高压缩比一般在400M/S左右,还可以接受,等待10几分钟也就完成了。用linux的人最喜欢的还是直接用tar命令备份重要数据,但个人觉得还是用ghost彻底备份比较好,免得硬盘损坏无法恢复全部数据。
2、用paragon patition mamager 调整linux根分区容量,无论是从前面还是从后面增减都可以,一般来说保留10G刚好。当然你也可以用PQmagic来执行调整,我没试过,不过应该没有什么问题。其实因为要移动数据,采用调整的方式速度很慢,而且事实上调整之后也不能进入系统,所以不如干脆删除,重建更快,但要注意别误操作,删除 windows分区就叫天天不应了。
3、用Ghost将以前备份的镜像还原到调整后的新分区,重新启动,结果顺利引导进入Ubuntu,但你会发现一个新的问题,就是Ubuntu自动挂载的windows分区有可能不见了。其实不变linux分区,调整windows分区也会导致挂载失效。
4、由于Ubuntu是工具硬盘分区的UUID进行挂载的,因而,硬盘分区的位置发生变化,挂载就自然失效了,别着急,可以重新挂载。打开终端,输入 “sudo ls -l /dev/disk/by-uuid”,可以显示当前硬盘各个分区的UUID,再在终端里输入“sudo gedit /etc/fstab”打开fstab,将不能挂载的分区UUID替换成刚得到的UUID,保存并关闭fstab,重启系统就可以了。
这个方法比较安全、实用,使你辛辛苦苦配置起来的系统不至于要重新安装,而且备份的ghost镜像随时可用来恢复系统,一点无用功都没有做。
查看系统中的 LABEL/ UUID
使用 blkid 命令:
用法(LABEL):
# blkid -s LABEL
/dev/hda3: LABEL="/"
/dev/hda1: LABEL="/boot1"
/dev/hda2: LABEL="SWAP-hda2"
/dev/hdc1: LABEL="/boot9"
/dev/hdc2: LABEL="/vm"
/dev/hdc3: LABEL="/home9"
/dev/hdc5: LABEL="/9"
/dev/hdc6: LABEL="/var/ftp/pub9"
/dev/hdc8: LABEL="/boot"
/dev/hdc9: LABEL="/1"
用法(UUID):
# blkid -s UUID
/dev/hda3: UUID="440612e0-9cea-4751-8e59-07ebffc589c2"
/dev/hda1: UUID="027ecc62-d346-411d-ae6c-c3eaa87fb195"
/dev/hdc1: UUID="fdbe6b52-755f-4e14-b970-b3be01543acc"
/dev/hdc2: UUID="e61f4197-5f00-4f4f-917c-290922a85339"
/dev/hdc3: UUID="06679282-4973-476a-98ae-4986f504816f"
/dev/hdc5: UUID="51f7e9a4-5154-4e29-a7a6-208417290b85"
/dev/hdc6: UUID="4bf4855e-96b9-43c4-89d7-b3d0087560e1"
/dev/hdc8: UUID="5a15d9d7-5a17-4d71-a2b6-eb978e6905cd"
/dev/hdc9: UUID="dc348785-9acb-4484-b52a-da000ffba601"
改变 LABEL 名称
Ext2 或 Ext3
打「e2label 装置档案 [label]」,例如把 /dev/sda1 命名为 /boot:
e2label /dev/sda1 /boot
或者使用「tune2fs -L label 装置档案」,例如把 /dev/sda1 命名为 /boot:
tune2fs -L /boot /dev/sda1
在 mount 命令中使用 LABEL/UUID
mount LABEL=/boot1 /boot
mount UUID="51f7e9a4-5154-4e29-a7a6-208417290b85" /mnt/
在 /etc/fstab 中使用 LABEL/UUID
档案/etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot1 /boot ext3 defaults 1 2
UUID="e61f4197-5f00-4f4f-917c-290922a85339" /usr ext3 defaults 1 12
debain中的fstab和grub的变化,使用了UUID
代码:
$ cat /etc/fstab
# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
# /dev/sda1 -- converted during upgrade to edgy
UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c / reiserfs defaults 0 1
# /dev/sda3 -- converted during upgrade to edgy
UUID=6b4fad21-6ce4-40d1-9042-f7894420d2ba /boot ext3 defaults 0 2
# /dev/sda4 -- converted during upgrade to edgy
UUID=c9946833-d79a-49d2-a565-2eb5f81b1340 /home reiserfs defaults 0 2
# /dev/sdb1 -- converted during upgrade to edgy
UUID=6884DF8584DF5462 /media/sdb1 ntfs defaults,nls=utf8,umask=007,gid=46 0 1
# /dev/sdb2 -- converted during upgrade to edgy
UUID=6f796414-ca8c-467a-8bdf-8690eee8a147 /media/sdb2 xfs defaults 0 2
# /dev/sdb3 -- converted during upgrade to edgy
UUID=4466-DBF1 /media/sdb3 vfat defaults,utf8,umask=007,gid=46 0 1
# /dev/sda2 -- converted during upgrade to edgy
UUID=52fac974-9ebd-4355-8bca-82a8e6763ba3 none swap sw 0 0
/dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0
代码:
$ cat /boot/grub/menu.lst
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.
## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0
## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10
## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu
## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret
#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#
#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST
### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below
## DO NOT UNCOMMENT THEM, Just edit them to your needs
## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro
## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,2)
## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true
## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false
## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash
## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false
## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(single-user) single
# altoptions=(recovery mode) single
## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all
## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true
## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false
## ## End Default Options ##
title Ubuntu, kernel 2.6.17-10-386
root (hd0,2)
kernel /vmlinuz-2.6.17-10-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro quiet splash
initrd /initrd.img-2.6.17-10-386
savedefault
boot
title Ubuntu, kernel 2.6.17-10-386 (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.17-10-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro single
initrd /initrd.img-2.6.17-10-386
boot
title Ubuntu, kernel 2.6.17-10-generic
root (hd0,2)
kernel /vmlinuz-2.6.17-10-generic root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro quiet splash
initrd /initrd.img-2.6.17-10-generic
savedefault
boot
title Ubuntu, kernel 2.6.17-10-generic (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.17-10-generic root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro single
initrd /initrd.img-2.6.17-10-generic
boot
title Ubuntu, kernel 2.6.15-27-386
root (hd0,2)
kernel /vmlinuz-2.6.15-27-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro quiet splash
initrd /initrd.img-2.6.15-27-386
savedefault
boot
title Ubuntu, kernel 2.6.15-27-386 (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.15-27-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro single
initrd /initrd.img-2.6.15-27-386
boot
title Ubuntu, kernel 2.6.15-26-386
root (hd0,2)
kernel /vmlinuz-2.6.15-26-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro quiet splash
initrd /initrd.img-2.6.15-26-386
savedefault
boot
title Ubuntu, kernel 2.6.15-26-386 (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.15-26-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro single
initrd /initrd.img-2.6.15-26-386
boot
title Ubuntu, kernel 2.6.16-28-386
root (hd0,2)
kernel /vmlinuz-2.6.16-28-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro quiet splash
initrd /initrd.img-2.6.16-28-386
savedefault
boot
title Ubuntu, kernel 2.6.16-28-386 (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.16-28-386 root=UUID=d72fd170-80fb-43da-b079-e51cd1a06a7c ro single
initrd /initrd.img-2.6.16-28-386
boot
title Ubuntu, memtest86+
root (hd0,2)
kernel /memtest86+.bin
boot
### END DEBIAN AUTOMAGIC KERNELS LIST
# This is a divider, added to separate the menu items below from the Debian
# ones.
title Other operating systems:
root
# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sdb1
title Microsoft Windows XP Professional
root (hd1,0)
savedefault
makeactive
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1