2017_12_18-mdadm_resize

Resize partition in mdadm RAID1 array

2017_12_18

Recently I found my root partition was almost full,

joe@hzwtech:/hzw> df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         63G  8.0K   63G   1% /dev
tmpfs            63G  837M   63G   2% /dev/shm
tmpfs            63G  3.1M   63G   1% /run
tmpfs            63G     0   63G   0% /sys/fs/cgroup
/dev/md126p2     63G   62G  585M 100% /
/dev/sdc1       2.7T  1.7T  887G  67% /mnt/sdc
/dev/md126p4    670G  517G  152G  78% /home
/dev/md126p5     13G  152K   13G   1% /boot/efi
/dev/md126p3     63G  9.2G   53G  15% /hzw
tmpfs            13G   44K   13G   1% /run/user/1001

and I found /opt occupied 28GB in /.

So I plan to resize the /hzw partition and create a new
partition to mount /opt on it.

The procedures are as follows:

Although I finshed these procedures without any data lost, but
just do remember to backup your data!

Procedure

  1. umount

    joe@hzwtech:/> sudo umount /hzw

    and

    joe@hzwtech:/> df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs         63G  8.0K   63G   1% /dev
    tmpfs            63G  837M   63G   2% /dev/shm
    tmpfs            63G  3.1M   63G   1% /run
    tmpfs            63G     0   63G   0% /sys/fs/cgroup
    /dev/md126p2     63G   62G  585M 100% /
    /dev/sdc1       2.7T  1.7T  887G  67% /mnt/sdc
    /dev/md126p4    670G  517G  152G  78% /home
    /dev/md126p5     13G  152K   13G   1% /boot/efi
    tmpfs            13G   44K   13G   1% /run/user/1001
  2. e2fsck & resize2fs

    first run e2fsck and then resize2fs

    joe@hzwtech:/> sudo e2fsck -f /dev/md126p3
    e2fsck 1.43.7 (16-Oct-2017)
    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/md126p3: 65994/4202496 files (0.1% non-contiguous), 2690892/16777984 blocks
    joe@hzwtech:/> sudo resize2fs /dev/md126p3 23G
    resize2fs 1.43.7 (16-Oct-2017)
    Resizing the filesystem on /dev/md126p3 to 6029312 (4k) blocks.
    The filesystem on /dev/md126p3 is now 6029312 (4k) blocks long.
  3. fdisk

    sudo fdisk -l

    shows

    Disk /dev/md126: 884.9 GiB, 950150365184 bytes, 1855762432 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    
    Device            Start        End    Sectors  Size Type
    /dev/md126p1       2048  134223871  134221824   64G Linux filesystem
    /dev/md126p2  134223872  268445695  134221824   64G Linux filesystem
    /dev/md126p3  268445696  402669567  134223872   64G Linux filesystem
    /dev/md126p4  402669568 1828732927 1426063360  680G Linux filesystem
    /dev/md126p5 1828732928 1855762398   27029471 12.9G EFI System
  4. gdisk

    sudo gdisk /dev/md126

    and p shows

    GPT fdisk (gdisk) version 1.0.1
    
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: present
    
    Found valid GPT with protective MBR; using GPT.
    
    Command (? for help): p
    Disk /dev/md126: 1855762432 sectors, 884.9 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 1855762398
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 2014 sectors (1007.0 KiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048       134223871   64.0 GiB    8300  primary
       2       134223872       268445695   64.0 GiB    8300  primary
       3       268445696       402669567   64.0 GiB    8300  primary
       4       402669568      1828732927   680.0 GiB   8300
       5      1828732928      1855762398   12.9 GiB    EF00

    first delete the partition

    Command (? for help): d
    Partition number (1-5): 3
    
    Command (? for help): p
    Disk /dev/md126: 1855762432 sectors, 884.9 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 1855762398
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 134225886 sectors (64.0 GiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048       134223871   64.0 GiB    8300  primary
       2       134223872       268445695   64.0 GiB    8300  primary
       4       402669568      1828732927   680.0 GiB   8300
       5      1828732928      1855762398   12.9 GiB    EF00

    then create a new partition with volume 23GB

    Command (? for help): n
    Partition number (3-128, default 3):
    First sector (34-402669567, default = 268445696) or {+-}size{KMGTP}:
    Last sector (268445696-402669567, default = 402669567) or {+-}size{KMGTP}: +23G
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300):
    Changed type of partition to 'Linux filesystem'
    
    Command (? for help): p
    Disk /dev/md126: 1855762432 sectors, 884.9 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 1855762398
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 85991390 sectors (41.0 GiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048       134223871   64.0 GiB    8300  primary
       2       134223872       268445695   64.0 GiB    8300  primary
       3       268445696       316680191   23.0 GiB    8300  Linux filesystem
       4       402669568      1828732927   680.0 GiB   8300
       5      1828732928      1855762398   12.9 GiB    EF00

    next the new partition with volume 41GB

    Command (? for help): n
    Partition number (6-128, default 6):
    First sector (34-402669567, default = 316680192) or {+-}size{KMGTP}:
    Last sector (316680192-402669567, default = 402669567) or {+-}size{KMGTP}:
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300):
    Changed type of partition to 'Linux filesystem'
    
    Command (? for help): p
    Disk /dev/md126: 1855762432 sectors, 884.9 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 1855762398
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 2014 sectors (1007.0 KiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048       134223871   64.0 GiB    8300  primary
       2       134223872       268445695   64.0 GiB    8300  primary
       3       268445696       316680191   23.0 GiB    8300  Linux filesystem
       4       402669568      1828732927   680.0 GiB   8300
       5      1828732928      1855762398   12.9 GiB    EF00
       6       316680192       402669567   41.0 GiB    8300  Linux filesystem

    finally write to partition table

    Command (? for help): w
    
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    
    Do you want to proceed? (Y/N): Y
    OK; writing new GUID partition table (GPT) to /dev/md126.
    Warning: The kernel is still using the old partition table.
    The new table will be used at the next reboot or after you
    run partprobe(8) or kpartx(8)
    The operation has completed successfully.
  5. reboot

    reboot the system to let kernel recognize the new partition table.

  6. resize2fs

    rerun for safety.

    sudo umount /dev/md126p3
    sudo e2fsck -f /dev/md126p3
    e2fsck 1.43.7 (16-Oct-2017)
    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/md126p3: 65994/1507328 files (0.1% non-contiguous), 2519745/6029312 blocks
    
    sudo resize2fs /dev/md126p3
    resize2fs 1.43.7 (16-Oct-2017)
    The filesystem is already 6029312 (4k) blocks long.  Nothing to do!
    joe@hzwtech:/> sudo mount /dev/md126p3 /hzw
    joe@hzwtech:/> cd hzw
    joe@hzwtech:/hzw> ls
    bin  lost+found  Matlab_Compiler_Runtime  MatlabR2011A  nanodcal  openSUSE-13.2-DVD-x86_64.iso  software
  7. create new filesystem

    sudo fdisk -l
    
    Disk /dev/md126: 884.9 GiB, 950150365184 bytes, 1855762432 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: 1D3291C0-F646-49B9-B07B-638F1F67A9EB
    
    Device            Start        End    Sectors  Size Type
    /dev/md126p1       2048  134223871  134221824   64G Linux filesystem
    /dev/md126p2  134223872  268445695  134221824   64G Linux filesystem
    /dev/md126p3  268445696  316680191   48234496   23G Linux filesystem
    /dev/md126p4  402669568 1828732927 1426063360  680G Linux filesystem
    /dev/md126p5 1828732928 1855762398   27029471 12.9G EFI System
    /dev/md126p6  316680192  402669567   85989376   41G Linux filesystem
    
    Partition table entries are not in disk order.

    mkfs

    joe@hzwtech:/hzw> sudo mkfs -t ext4 /dev/md126p6
    mke2fs 1.43.7 (16-Oct-2017)
    Creating filesystem with 10748672 4k blocks and 2689904 inodes
    Filesystem UUID: 33a6e7e9-e49b-40c1-9ae9-04fffa63e07a
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000, 7962624
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (65536 blocks): done
    Writing superblocks and filesystem accounting information: done
  8. mount & cp

    cd /mnt
    sudo mkdir p1
    
    joe@hzwtech:/mnt> sudo mount /dev/md126p6 p1
    joe@hzwtech:/mnt> cd p1
    joe@hzwtech:/mnt/p1> ls
    lost+found

    copy files in /opt to the new partition

    sudo rsync -a --info=progress2 /opt .
  9. fstab

    joe@hzwtech:/mnt> cat /etc/fstab
    UUID=6ed7f97f-cbb5-478e-8031-c47f8d3ba764 swap                 swap       defaults              0 0
    UUID=ebe87b34-eb89-4264-ab8f-4f137a9d1b36 /                    ext4       acl,user_xattr        1 1
    UUID=2CE2-06FC                            /boot/efi            vfat       defaults              1 2
    UUID=6ab7a4ee-ecba-47ca-b22f-6e1dd74a0586 /home                ext4       acl,user_xattr        1 2
    UUID=9fe5cf6c-34d1-407f-b11a-abdd64eeeab7 /hzw                 ext4       acl,user_xattr        1 2
    UUID=3cd980c2-a8a6-4e6c-bbc7-58b627b5395e /mnt/sdc             ext4       auto                  0 2
    
    #localhost/owncloud/remote.php/webdav /home/joe/owncloud davfs user,rw,auto 0 0
    

    find UUID

    joe@hzwtech:/mnt> sudo blkid /dev/md126p*
    /dev/md126p1: UUID="6ed7f97f-cbb5-478e-8031-c47f8d3ba764" TYPE="swap" PARTLABEL="primary"   PARTUUID="7bbaf50d-ac00-4a0a-afa7-95a46b0d3a19"
    /dev/md126p2: UUID="ebe87b34-eb89-4264-ab8f-4f137a9d1b36" TYPE="ext4" PARTLABEL="primary"   PARTUUID="c6759101-c1f1-451d-a848-1a0a0e7bb5da"
    /dev/md126p3: UUID="9fe5cf6c-34d1-407f-b11a-abdd64eeeab7" TYPE="ext4" PARTLABEL="Linux filesystem"  PARTUUID="7318c6c3-3881-4fcb-9f35-8fb5490a4add"
    /dev/md126p4: UUID="6ab7a4ee-ecba-47ca-b22f-6e1dd74a0586" TYPE="ext4" PARTUUID="6517563c-8945-4732-9613-3adae5c2d7ef"
    /dev/md126p5: UUID="2CE2-06FC" TYPE="vfat" PARTUUID="2176c8ad-4939-4df2-8855-f9b62fa80180"
    /dev/md126p6: UUID="33a6e7e9-e49b-40c1-9ae9-04fffa63e07a" TYPE="ext4" PARTLABEL="Linux filesystem"  PARTUUID="669a7a4a-e3be-4d53-963a-a87b04198d85"

    add a line

    UUID=33a6e7e9-e49b-40c1-9ae9-04fffa63e07a /opt                 ext4       acl,user_xattr        1 2
  10. delete /opt

    enter rescue system and delete /opt to free the disk.

done!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值