zoukankan      html  css  js  c++  java
  • 在Linux中扩展磁盘容量(1)

    对于linux系统管理员来说,随着业务的发展,磁盘容量不足是需要面对的一个难题。这里通过两种方式来说明如果添加新的磁盘到linux 系统当中去。一是连接新的disk,对disk分区和格式化,然后合并以存在的filesystem和新增加的disk的filesystem。二是通过 linux logical volumn manager 来管理磁盘。

    添加新的disk到linux当中来

    [完成的任务]将新增加的disk做出一个parition,然后将linux上已有磁盘上数据全部或部分迁移到新的磁盘上来

    假设现在linux system中的filesystem的使用情况大致是:

    [root@bigboy tmp]# df -k
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/hda3               505636    118224    361307  25% /
    /dev/hda1               101089     14281     81589  15% /boot
    none                     63028         0     63028   0% /dev/shm
    /dev/hda5               248895      6613    229432   3% /tmp
    /dev/hda7              3304768   2720332    416560  87% /usr
    /dev/hda2              3304768   3300536      4232  99% /var
    

    可以看到/var挂载点挂载的/dev/hda2 partition已经使用了99%。需要增加新的磁盘容量。

    通过查看/proc/partitions proc 文件,可以查看当前linux系统中所有已知的partitions

    [root@bigboy tmp]# cat /proc/partitions
    major minor  #blocks  name
     
       3     0    7334145 hda
       3     1     104391 hda1
       3     2    1052257 hda2
       3     3    2040255 hda3
       3     4          1 hda4
       3     5    3582463 hda5
       3     6     554211 hda6
      22     0   78150744 hdb
    [root@bigboy tmp]#

    可以看到minor 值为0表示是整块磁盘, 磁盘上的分区的major同一样,minor是根据parition的增加而增加,这里hda1 hda2 … hda6的minor分别为1,2,…,6

    Linux系统中hard disk命名规则, scsi磁盘以sd开头,ide磁盘以hd开头,scsi的第一个磁盘为sda, 依次其它的为sdb,sdc,sdd, IDE同样如此,hda, hdb.

    sda上第一个parition为sda1,剩余的以此类推。

    接下来,为新增加的disk hdb建立分区。

    [root@bigboy tmp]# fdisk /dev/hdb
     
    The number of cylinders for this disk is set to 9729.
    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)
     
    Command (m for help): 
    ============================================================
    Command (m for help): p
     
    Disk /dev/hdb: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
       Device Boot      Start         End      Blocks   Id   System
     
    Command (m for help):
    可以看到目前hdb 上没有建立parition。
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    Partition number (1-4): 1
    First cylinder (1-9729, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729):
    Command (m for help): p
     
    Disk /dev/hdb: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
       Device Boot      Start         End      Blocks   Id   System
    /dev/hdb1               1        9726    78148161   83  Linux
     
    Command (m for help):

    如果你在新建partition的时候出错,则你可以使用d命令来删除该parition,然后重新来过。 另外,linux最多允许四个primary partition, 如果你需要建立更多的分区,使用建立extended partition. 建立完extended partition之后,可以在extended partition上建立新的logical partition。

    Command (m for help): p
     
    Disk /dev/hda: 7510 MB, 7510164480 bytes
    255 heads, 63 sectors/track, 913 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
       Device Boot      Start         End      Blocks   Id   System
    /dev/hda1   *           1          13      104391   83  Linux
    /dev/hda2              14         144     1052257+  83  Linux
    /dev/hda3             145         398     2040255   82  Linux swap
    /dev/hda4             399         913     4136737+   5  Extended
    /dev/hda5             399         844     3582463+  83  Linux #logical parition on extended parition
    /dev/hda6             845         913      554211   83  Linux # ditto

    当你完成对hdb分区后, 查看下分区表分区是否正确 : 通过cat /proc/partitions 或 fdisk -l

    接下来就需要对新增的disk hdb进行格式化,为其建立新的目录结构。

    mkfs –t ext3 /dev/hdb1

    然后为/dev/hdb1 建立挂载点,这里是/mnt/hdb1

    修改/etc/fstab 将/dev/hdb1 挂载到/mnt/hdb1

    #
    # File: /etc/fstab
    #
    /dev/hdb1  /mnt/hdb1  ext3  defaults 1 2

    最后别忘记挂载,挂载完成后就可以使用新增的disk了。

    小结:新增disk基本需要:连接好disk,对disk分区, 格式化,最后建立挂载点,挂载

    关于LVM,在Linux中扩展磁盘容量(2)—LVM 中总结。

  • 相关阅读:
    Python 散点图
    python matplotlib 图例设置 legend() 参数详解
    python matplotlib 设置背景色、轴脊、网格线
    python 可视化有随机噪声得到的一个“异或”数据集的二维分布
    Python 中的逻辑值
    python 计算等差数列和的两种循环方式
    Python 及其第三方库的版本查看
    R语言 中的 paste/paste0 函数
    R语言 文件及路径操作
    Python 热力图
  • 原文地址:https://www.cnblogs.com/yuboyue/p/2109860.html
Copyright © 2011-2022 走看看