[笔记]Ubuntu /home目录的空间扩展缩小

摘要:
1.检查卷组是否有足够的可用空间$sudovgdisplay2。使用lvdisplay命令查看逻辑分区$sudolvdisplay3。增加逻辑分区空间$sudolextend-L+59G/dev/VG/homev#-L。该参数由大小表示。命令$df-T可以查看分区文件系统类型!

 一、扩展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
    This command will install lvm2 onto your Live CD session only but will help with the rest of this tutorial.

 

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
    This gives the LVM an understand of what physical volumes it has to offer for volume groups and logical volumes during your setup. Create a group using our newly create physical volume:
    sudo vgcreate sysvg /dev/sda2
                    ^       ^
                   name     PV
    This part creates a new volume group which is tided to a physical volume. A physical disk can not be can not be used on multiple violume groups (unless you partition that disk before hand like we did above). The name of this volume group is 'sysvg' but you can name it whatever you wish. Create the swap logical volume using the newly create sysvg group:
    sudo lvcreate -L 1G -n lvswap sysvg
                    ^        ^      ^
                 size(GB)   name    VG
    I need a swap for the system so 1GB will do in this case (you can change the size to whatever you want). The name can be whatever you want it to be but I like to keep a naming scheme when creating VG's and LV's. Then assign it to a VG group that you made from before and you will have your first LV done. Create the root logical volume using the newly create sysvg group:
    sudo lvcreate -L 20G -n lvroot sysvg
                    ^        ^      ^
                 size(GB)   name    VG
    Again, like the swap but this will be used for my root file system. The size and name is up to you and make sure you point it to your VG that was created above. Create the home logical volume using the newly create sysvg group:
    sudo lvcreate -l 100%FREE -n lvhome sysvg
                     ^           ^      ^
                 extents(%)     name    VG
    Without getting into a lot of details, this will create a logical volume called 'home' using 100% of whats left on my VG. The percentage and name is up to you and make sure you point it to your VG that was created above. You do not need to use the rest of your disk space on home or any of the above created.

参考文档:

免责声明:文章转载自《[笔记]Ubuntu /home目录的空间扩展缩小》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ES6中Arguments和Parameters用法解析WIN7无法访问共享打印机及文件的解决办法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

一文教您如何通过 Docker 快速搭建各种测试环境(Mysql, Redis, Elasticsearch, MongoDB

友情提示:搭建之前,你需要先安装 Docker 哟,本文基于您已经安装好 Docker 的基础上! 目录 一、镜像加速 二、快速安装&搭建 Mysql 环境 三、快速安装&搭建 Redis 环境 四、快速安装&搭建 MongDB 环境 五、快速安装&搭建 Elasticsearch 环境 六、总结 一、镜像加速 Dock...

ES6 模块化笔记

ES6 模块的设计思想,是尽量的静态化,使得编译时就能确定模块的依赖关系,以及输入和输出的变量。 ES6 模块不是对象,而是通过export命令显式指定输出的代码,再通过import命令输入。 // ES6模块 import { stat, exists, readFile } from 'fs'; 需要特别注意的是,export命令规定的是对外的接口...

Android双系统实现

1. 前言: 刷机,似乎是安卓手机用户的一项专利,可是,会刷机的用户一般都是喜新厌旧的角色。 一个系统用久了。就想换到还有一个系统。或者认为没有原来的好,或者又认为要换回去。这样又要重刷。 可是刷来刷去都麻烦啊,而且每次刷机也不是没有风险的,一不小心就可能造成关键数据的丢失。 没有解决的方法吗? 有。双系统! 甚至三系统,四系统! ! 本文就是解决问题的,...

redis慢查询的简单认识和事务、订阅的认识

  有学习的小伙伴可以一起讨论有问题可以问我,微信 15321502296慢查询 阀值:规定的一个值 阈值:规定的一个范围 就是系统在执行命令前后计算每条命令的执行时间,当超过预设的阀值时,就见这条命令记录下来 slowlog-log-slower-than  微秒 1秒=1000毫秒=1000000微秒 0 记录所有命令 <0不进行记录 slowl...

EasyDSS中如何利用FFmpeg对MP4文件进行字幕叠加?

上一篇我们讲了在EasyDSS内可以通过FFmpeg对音视频进行裁剪,那么裁剪后我们又想进行字幕叠加时应该怎么做?其实这个需求也可以通过FFmpeg来满足,我们只需要调用对应的命令就可以了。 在具体教大家怎么叠加字幕之前,先给大家普及一下字幕文件的格式,字幕文件有很多种,常见的有 .srt,.ass 文件等。不同格式的字幕文件也可以相互转换,命令如下:...

IMAP命令与分析

https://www.cnblogs.com/crystalray/p/3304688.html Internet Mail Access Protocol(缩写为IMAP,以前称作交互邮件访问协议(interactive mail access protocol))IMAP是斯坦福大学在1986年开发的研发的一种邮件获取协议。它的主要作用是邮件客户端(...