1. 程式人生 > >linux 擴展文件系統

linux 擴展文件系統

rmi ada sed inter yar pdv rest can partition

1. 創建新分區

[root@localhost ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a8293

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 20971519 10279936 8e Linux LVM Disk /dev/mapper/cl-root: 8376 MB, 8376025088 bytes, 16359424 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512
bytes / 512 bytes Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@localhost ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2
). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): 3 First sector (20971520-62914559, default 20971520): Using default value 20971520 Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559): +2G Partition 3 of type Linux and of size 2 GiB is set Command (m for help): p Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a8293 Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 20971519 10279936 8e Linux LVM /dev/sda3 20971520 25165823 2097152 83 Linux Command (m for help): t   # 修改文件系統類型 Partition number (1-3, default 3): 3 Hex code (type L to list all codes): 8e Changed type of partition Linux to Linux LVM Command (m for help): p Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a8293 Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 20971519 10279936 8e Linux LVM /dev/sda3 20971520 25165823 2097152 8e Linux LVM Command (m for help): w The partition table has been altered!

2. 創建 pv

[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@localhost ~]# pvdisplay   
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               9.80 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2509
  Free PE               0
  Allocated PE          2509
  PV UUID               vBCY0m-syaR-HKNJ-FNlW-G7Ql-2eru-4ccPC6
   
  "/dev/sda3" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               kRvof2-gzMz-raeu-njD7-vujG-N45B-yJemBd

3. 將 pv 添加到 vg

[root@localhost ~]# vgextend cl /dev/sda3 
  Volume group "cl" successfully extended
[root@localhost ~]# vgs
  VG #PV #LV #SN Attr   VSize  VFree
  cl   2   2   0 wz--n- 11.80g 2.00g
[root@localhost ~]# pvs
  PV         VG Fmt  Attr PSize PFree
  /dev/sda2  cl lvm2 a--  9.80g    0 
  /dev/sda3  cl lvm2 a--  2.00g 2.00g

4. 擴展 lv

[root@localhost ~]# lvextend /dev/cl/root /dev/sda3
  Size of logical volume cl/root changed from 7.80 GiB (1997 extents) to 9.80 GiB (2508 extents).
  Logical volume cl/root successfully resized.

5. 擴展文件系統的邏輯邊界

[root@localhost ~]# xfs_growfs /dev/cl/root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=511232 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2044928, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2044928 to 2568192
[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root  9.8G 1021M  8.8G  11% /
devtmpfs             1.9G     0  1.9G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  8.6M  1.9G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1            197M  117M   81M  60% /boot
tmpfs                378M     0  378M   0% /run/user/0
[root@localhost ~]# 



Command (m for help): ^C[root@localhost ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000a8293
Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 20971519 10279936 8e Linux LVM
Disk /dev/mapper/cl-root: 8376 MB, 8376025088 bytes, 16359424 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
[root@localhost ~]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.Be careful before using the write command.

Command (m for help): nPartition type: p primary (2 primary, 0 extended, 2 free) e extendedSelect (default p): pPartition number (3,4, default 3): 3Value out of range.Partition number (3,4, default 3): 3First sector (20971520-62914559, default 20971520): Using default value 20971520Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559): +2GPartition 3 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000a8293
Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 20971519 10279936 8e Linux LVM/dev/sda3 20971520 25165823 2097152 83 Linux
Command (m for help): tPartition number (1-3, default 3): 3Hex code (type L to list all codes): 8eChanged type of partition ‘Linux‘ to ‘Linux LVM‘
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000a8293
Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 20971519 10279936 8e Linux LVM/dev/sda3 20971520 25165823 2097152 8e Linux LVM
Command (m for help): w^HmThe partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.[root@localhost ~]# m-bash: m: command not found[root@localhost ~]# partprobeWarning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.[root@localhost ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000a8293
Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 20971519 10279936 8e Linux LVM/dev/sda3 20971520 25165823 2097152 8e Linux LVM
Disk /dev/mapper/cl-root: 8376 MB, 8376025088 bytes, 16359424 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name cl PV Size 9.80 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 2509 Free PE 0 Allocated PE 2509 PV UUID vBCY0m-syaR-HKNJ-FNlW-G7Ql-2eru-4ccPC6 [root@localhost ~]# amnpvcreate-bash: amnpvcreate: command not found[root@localhost ~]# [root@localhost ~]# man pvcreate[root@localhost ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created.[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name cl PV Size 9.80 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 2509 Free PE 0 Allocated PE 2509 PV UUID vBCY0m-syaR-HKNJ-FNlW-G7Ql-2eru-4ccPC6 "/dev/sda3" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID kRvof2-gzMz-raeu-njD7-vujG-N45B-yJemBd [root@localhost ~]# pvdisplay /dev/sda3 "/dev/sda3" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID kRvof2-gzMz-raeu-njD7-vujG-N45B-yJemBd [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- 9.80g 0 /dev/sda3 lvm2 --- 2.00g 2.00g[root@localhost ~]# man pvs[root@localhost ~]# ^C[root@localhost ~]# vgvgcfgbackup vgcfgrestore vgchange vgck vgconvert vgcreate vgdisplay vgexport vgextend vgimport vgimportclone vgmerge vgmknodes vgreduce vgremove vgrename vgs vgscan vgsplit [root@localhost ~]# vgvgcfgbackup vgcfgrestore vgchange vgck vgconvert vgcreate vgdisplay vgexport vgextend vgimport vgimportclone vgmerge vgmknodes vgreduce vgremove vgrename vgs vgscan vgsplit [root@localhost ~]# man vgextend [root@localhost ~]# vgextend ^C[root@localhost ~]# [root@localhost ~]# [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID fXT6fu-BoAz-0KaZ-rTH5-mHa6-l2uj-K8RCyh LV Write Access read/write LV Creation host, time localhost.localdomain, 2019-03-17 11:27:45 +0800 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/cl/root LV Name root VG Name cl LV UUID srKRrd-Izbt-g00h-XiiR-vahV-CVCP-lRzOit LV Write Access read/write LV Creation host, time localhost.localdomain, 2019-03-17 11:27:46 +0800 LV Status available # open 1 LV Size 7.80 GiB Current LE 1997 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@localhost ~]# vgextend cl /dev/sda3 Volume group "cl" successfully extended[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree cl 2 2 0 wz--n- 11.80g 2.00g[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- 9.80g 0 /dev/sda3 cl lvm2 a-- 2.00g 2.00g[root@localhost ~]# pvdisplay /dev/sda3 --- Physical volume --- PV Name /dev/sda3 VG Name cl PV Size 2.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 511 Free PE 511 Allocated PE 0 PV UUID kRvof2-gzMz-raeu-njD7-vujG-N45B-yJemBd [root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl-root 7.8G 1021M 6.8G 13% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 8.6M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 197M 117M 81M 60% /boottmpfs 378M 0 378M 0% /run/user/0[root@localhost ~]# man lvextend [root@localhost ~]# lvextend -L +2G /dev/mapper/cl-root Insufficient free space: 512 extents needed, but only 511 available[root@localhost ~]# lvextend -L +2G /dev/mapper/cl-root^C[root@localhost ~]# man lvextend [root@localhost ~]# lvextend /dev/vg01/lvol01 /dev/sdk3 Volume group "vg01" not found Cannot process volume group vg01[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree cl 2 2 0 wz--n- 11.80g 2.00g[root@localhost ~]# vgdisplay --- Volume group --- VG Name cl System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 11.80 GiB PE Size 4.00 MiB Total PE 3020 Alloc PE / Size 2509 / 9.80 GiB Free PE / Size 511 / 2.00 GiB VG UUID xGCNuQ-UlO9-2Pdv-wnXq-11Ft-4SlA-5YU3kw [root@localhost ~]# lvextend /dev/cl/root New size of 0 not permitted.[root@localhost ~]# lvextend /dev/cl/root /dev/sda3 Size of logical volume cl/root changed from 7.80 GiB (1997 extents) to 9.80 GiB (2508 extents). Logical volume cl/root successfully resized.[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl-root 7.8G 1021M 6.8G 13% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 8.6M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 197M 117M 81M 60% /boottmpfs 378M 0 378M 0% /run/user/0[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl-root 7.8G 1021M 6.8G 13% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 8.6M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 197M 117M 81M 60% /boottmpfs 378M 0 378M 0% /run/user/0[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl-root 7.8G 1021M 6.8G 13% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 8.6M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 197M 117M 81M 60% /boottmpfs 378M 0 378M 0% /run/user/0[root@localhost ~]# bgs-bash: bgs: command not found[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree cl 2 2 0 wz--n- 11.80g 0 [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- 9.80g swap cl -wi-ao---- 2.00g [root@localhost ~]# vgdisplay --- Volume group --- VG Name cl System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 11.80 GiB PE Size 4.00 MiB Total PE 3020 Alloc PE / Size 3020 / 11.80 GiB Free PE / Size 0 / 0 VG UUID xGCNuQ-UlO9-2Pdv-wnXq-11Ft-4SlA-5YU3kw [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- 9.80g swap cl -wi-ao---- 2.00g [root@localhost ~]# resizeresize2fs resizecons resizepart [root@localhost ~]# man resize2fs[root@localhost ~]# man xfs_growfs[root@localhost ~]# xfs_growfs /dev/cl/rootmeta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=511232 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=2044928, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 2044928 to 2568192[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl-root 9.8G 1021M 8.8G 11% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 8.6M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 197M 117M 81M 60% /boottmpfs 378M 0 378M 0% /run/user/0[root@localhost ~]#

linux 擴展文件系統