一、扩展home目录
前提是/home目录是单独的分区,硬盘有剩余的空间。
1、查看卷组是否有有足够空闲空间
$sudo vgdisplay
2、用lvdisplay命令查看逻辑分区
$sudo lvdisplay
3、增加逻辑分区空间
$sudo lvextend -L +59G /dev/VG/homelv # -L 参数用大小表示, “+”为追加,如果没有这个加号,则为扩展到指定的大小
# -l (小写L),则用PE的数目表示,如果要把剩下全部PE都扩展到逻辑分区时,最好使用这个参数
# lvextend /dev/VolGroup00/LogVol00 -l +100%FREE 以百分比
4、增加文件系统空间,我的文件系统用xfs格式.ext4文件系统用resize2fs命令,其它的文件系统上谷歌搜一下!命令$df -T 可以查看分区文件系统类型,在RHEL4系统的ext3文件系统使用这个命令:ext2online /dev/VolGroup00/LogVol00
$sudo xfs_growfs /dev/VG/homelv
5、查看更新后的文件系统
$sudo df -h
二、扩展卷组
1、将要添加到卷组中的磁盘格式化为物理卷
$sudo pvcreate /dev/sdb
2、扩展卷组的空间
$sudo vgextend VG /dev/sdb
3、查看扩充后大小
$sudo vgdisplay
三、缩小swap分区
1、查看swap分区大小:$free -m 以M为单位,如果是以G为单位则用-g参数
2、停止swap分区,再用free -m查看时,则为大小则为0;
$sudo swapoff -a
3、缩小swap分区大小,这里为缩小4G
$sudo lvreduce /dev/VolGroup00/swap -L -4G
4、重做swap分区
$sudo mkswap /dev/VolGroup00/swap
5、启动swap,启动后再用free -m命令缩小后的大小
$sudo swapon /dev/VolGroup00/swap
四、缩小/home目录
1、查看哪些程序在使用/home目录
取消挂载/home时出现umount: /home: device is busy,原因是因为有程序在使用/home目录,我们可以使用fuser查看那些程序的进程, 然后杀掉就可以了。
$ fuser -m /home /home: 1340c kill -9 pid
注意:pid就是1340,不用后面的c
2、卸载/home
$ sudo umount /home
3、强制检查/dev/vg/home文件系统的正确性(可以不操作)
$sudo e2fsck -f /dev/mapper/nasvg-naslv_home e2fsck 1.39 (29-May-2006) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/nasvg-naslv_home: 17/262144 files (17.6% non-contiguous), 44125/1048576 blocks
4、先缩小/dev/mapper/nasvg-naslv_home文件系统的大小,这里为缩小到5G
$ sudo resize2fs /dev/mapper/nasvg-naslv_home 5G
5、再缩小/dev/mapper/nasvg-naslv_home的LVM大小
$ sudo lvresize -L 5G /dev/mapper/nasvg-naslv_home
6、再挂载上去
$ sudo mount -a
7、再查看就是缩小后的大小了
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/nasvg-naslv_root 9.6G 2.1G 7.5G 22% / udev 489M 8.0K 489M 1% /dev tmpfs 200M 328K 199M 1% /run none 5.0M 0 5.0M 0% /run/lock none 498M 0 498M 0% /run/shm /dev/sda1 228M 48M 181M 21% /boot /dev/mapper/nasvg-naslv_home 5.0G 214M 4.8G 5% /home
五、安装Ubuntu桌面系统时,进行LVM分区
参考:
Start up Ubuntu Live
-
Once you have your Ubuntu Live CD or USB ready, start up that computer/laptop, go into your BIOS (usually its F2 but this link can help if it doesn't work: http://www.cyberwalker.com/article/28) and make sure your 'Boot Sequence' is set to CDROM or USB (if its supported). Save your BIOS setting and watch Ubuntu startup in front of your eyes. Later, you should see two options of "Try Ubuntu" and "Install Ubuntu" (11.04). Select "Try Ubuntu" and let it load into the Ubuntu 11.04.
Install lvm2
- Now that Ubuntu is booted up, now we will need a terminal by selecting the following:
Applications >> Accessories >> Terminal Once the terminal in front of you, run the following command:
sudo apt-get -y install lvm2
Setup hard drive partions
- Keep the terminal open as we will be creating partitions using the command fdisk. In the example below, I will be setting up my desktop using the /dev/sda patition (to find yours, do the command 'sudo fdisk -l' and make sure you know much your storage is on the machine so you can figure out what physical device you want to use):
ubuntu@ubuntu:~$ sudo fdisk /dev/sda Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x568311d6. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-5221, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +1G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (133-5221, default 133): Using default value 133 Last cylinder, +cylinders or +size{K,M,G} (133-5221, default 5221): Using default value 5221 Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x568311d6 Device Boot Start End Blocks Id System /dev/sda1 1 132 1060258+ 83 Linux /dev/sda2 133 5221 40877392+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
The reason for this setup is explained below:
/dev/sda1 -- This partition has been created for /boot of the installation. It always a good thing to make your /boot the first partion of any Linux system
/dev/sda2 -- This is the LVM physical parition that will be used to create the rest of the system before installation.
NOTE: In the following setup, I will be using a LVM swap partition instead of making it through fdisk. Having swap as a LVM partition might cause overhead. You can make a new partition before you make your LVM partition as a swap partition. Make sure you know how much you need since you will not be able to increase the swap size easily. The table id for swap is 82 (Linux swap / Solaris).
pvcreate, vgcreate, lvcreate, mkfs
- This part will help setup your logical volumes for your desktop. In this example, there will be three different logical volumes using one volume group and one physical volume: Create the physical volume:
sudo pvcreate /dev/sda2 ^ PV
sudo vgcreate sysvg /dev/sda2 ^ ^ name PV
sudo lvcreate -L 1G -n lvswap sysvg ^ ^ ^ size(GB) name VG
sudo lvcreate -L 20G -n lvroot sysvg ^ ^ ^ size(GB) name VG
sudo lvcreate -l 100%FREE -n lvhome sysvg ^ ^ ^ extents(%) name VG
参考文档: