fdisk and parted partition

There are two types of linux partitions I contact: one is using fdisk partition, and the other is parted partition. The former is for MBR mode partition, and the latter is for GPT mode partition

fdisk partition:

Fdisk - L ----- > view disk information
Fdisk / dev / SDC -- > select the disk to operate (eg:/dev/sdc)

a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
D delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
N add a new partition
o create a new empty DOS partition table    
p print the partition table                  
Q quit without saving changes
s create a new empty Sun disklabel
T change a partition's system ID
u change display/entry units
v verify the partition table
W write table to disk and exit
x extra functionality (experts only)               

 1 Create a partition example:
 2 Command (m for help): n
 3 Partition type:
 4    p   primary (0 primary, 0 extended, 4 free)
 5    e   extended
 6 Select (default p): p
 7 Partition number (1-4, default 1): 1
 8 First sector (2048-4194303, default 2048):
 9 Using default value 2048
10 Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
11 Using default value 4194303
12 Partition 1 of type Linux and of size 2 GiB is set
13 
14 Command (m for help): t
15 Selected partition 1
16 Hex code (type L to list all codes): 8e
17 Changed type of partition 'Linux' to 'Linux LVM'

Creating and expanding logical volumes

[root@localhost ~]# pvcreate /dev/sdc1                ---->Establish pv
  Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# vgextend rhel /dev/sdc1           ---->extend vg Volume group
 Volume group "rhel" successfully extended
[root@localhost ~]# vgreduce rhel /dev/sdc1           --->If you don't want to join the existing vg Inside, I want to build one myself vg Volume group, expand the pv Remove it,
Removed "/dev/sdc1" from volume group "rhel"
[root@localhost ~]# vgcreate vg2 /dev/sdc1            --->Create new vg,And set up vg be known as vg2
Volume group "vg2" successfully created
[root@localhost ~]# lvextend /dev/rhel/root /dev/sdc1
Physical Volume "/dev/sdc1" not found in Volume Group "rhel".  --->No addition vg Group, directly expanding to logical volume will report error,To expand, first vgextend To the corresponding vg group
[root@localhost ~]# pvremove /dev/sdc1                   ---->remove pv
Labels on physical volume "/dev/sdc1" successfully wiped
as lvextend If wrong entry is added, it will be solved as follows
[root@localhost ~]# lvextend /dev/rhel/root /dev/sdc1                         ---->Will expand/dev/sdc1 Extend to/dev/rhe1/root After that, I feel the extension error. How to exit,
  Size of logical volume rhel/root changed from 90.46 GiB (23158 extents) to 92.46 GiB (23669 extents).   --->Remember that. extents Size, from 23158 to 23669
  Logical volume root successfully resized
[root@localhost ~]# lvreduce -l 23158  /dev/rhel/root                        ---->This is going to be extended/dev/sdc1 Back out,-l Parameter assignment extents Size, specify reduced/dev/rhel/root Size
  WARNING: Reducing active and open logical volume to 90.46 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]: y
  Size of logical volume rhel/root changed from 92.46 GiB (23669 extents) to 90.46 GiB (23158 extents).
  Logical volume root successfully resized                                   ---->Success, can be re expanded later

[root @ localhost ~] ා lvcreate - L + 100% free rhel / dev / SDC1 - n lv2 ---- ----- > recreate an lv volume, - n parameter specifies that the created volume name rhel is a volume group, and
Logical volume "lv2" created.

Partial partition:

[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) select /dev/sdc                                                   ---->Select the partition you want to operate on, be sure to pay attention to the disk you are executing
Using /dev/sdc
(parted) p                                                                 ---->View current partition information
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2146MB  2145MB               p     lvm
(parted) mklabel GPT                                                     ---->Disk format as GPT Mode, no formatting required before
Warning: The existing disk label on /dev/sdc will be destroyed and all data on   
this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart name 0% 100%                                             ---->name Name the partition for customization  0% 100% It's disk./dev/sdc As the size of the partition
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2146MB  2145MB               name

(parted) set 1 lvm on                                                   ---->According to zone No.1,Set partition 1 as a logical volume
(parted) rm 1                                                           ---->Delete partition with partition number 1
(parted) q                                                              ---->Save on exit

Format and mount the disk

 Capacity reduction,One way
[root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 93G 15G 78G 16% / devtmpfs devtmpfs 904M 0 904M 0% /dev tmpfs tmpfs 914M 80K 914M 1% /dev/shm tmpfs tmpfs 914M 8.9M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 xfs 497M 124M 373M 25% /boot /dev/mapper/rhel-home xfs 7.0G 65M 7.0G 1% /home [root@localhost ~]# mkfs.ext4 /dev/mapper/rhel-home ---->To reduce the size of the partition, first change the format to ext4 Format, xfs Format does not support pass resize2fs reduce mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 458752 inodes, 1835008 blocks 91750 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1879048192 56 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost ~]# resize2fs /dev/mapper/rhel-home 2G ---->Reassign/rhel-home The size of the volume needs to be increased by unit. If no unit is added, the default value is block block resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/mapper/rhel-home to 524288 (4k) blocks. The filesystem on /dev/mapper/rhel-home is now 524288 blocks long. [root@localhost ~]# lvreduce -L 2G /dev/rhel/home WARNING: Reducing active logical volume to 2.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce home? [y/n]: y Size of logical volume rhel/home changed from 7.00 GiB (1792 extents) to 2.00 GiB (512 extents). Logical volume home successfully resized [root@localhost ~]# mount /dev/mapper/rhel-home /home/ [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 93G 15G 78G 16% / devtmpfs 904M 0 904M 0% /dev tmpfs 914M 80K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 124M 373M 25% /boot /dev/mapper/rhel-home 1.9G 21M 1.8G 2% /home
Reduced capacity:Mode two(Note: this system volume root And volume home All for xfs File system, different from above, but not associated with file system)
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   91G   15G   77G  16% /
devtmpfs               904M     0  904M   0% /dev
tmpfs                  914M  276K  914M   1% /dev/shm
tmpfs                  914M  9.1M  905M   1% /run
tmpfs                  914M     0  914M   0% /sys/fs/cgroup
/dev/sda1              497M  124M  373M  25% /boot
/dev/mapper/rhel-home  7.0G   65M  7.0G   1% /home
/dev/sr0               3.7G  3.7G     0 100% /media
[root@localhost ~]# lvreduce -L 88G /dev/rhel/root               ---->Be careful about root directory operation
  WARNING: Reducing active and open logical volume to 88.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]: y
  Size of logical volume rhel/root changed from 90.46 GiB (23158 extents) to 88.00 GiB (22528 extents).
  Logical volume root successfully resized
[root@localhost ~]# lvextend /dev/rhel/home /dev/sda2 /dev/sdb1 /dev/sd
/dev/sda2  /dev/sdb1
[root@localhost ~]# lvextend /dev/rhel/home /dev/sda2 /dev/sdb1   ---->Expand free space to home Roll down
  No free extents on physical volume "/dev/sda2".
  Size of logical volume rhel/home changed from 7.00 GiB (1792 extents) to 9.46 GiB (2422 extents).
  Logical volume home successfully resized
[root@localhost ~]# xfs_growfs /dev/mapper/rhel-home                ---->xfs File system expansion, ext4 Use resize2fs Capacity expansion
meta-data=/dev/mapper/rhel-home  isize=256    agcount=4, agsize=458752 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=1835008, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 1835008 to 2480128
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   91G   15G   77G  16% /
devtmpfs               904M     0  904M   0% /dev
tmpfs                  914M  276K  914M   1% /dev/shm
tmpfs                  914M  9.1M  905M   1% /run
tmpfs                  914M     0  914M   0% /sys/fs/cgroup
/dev/sda1              497M  124M  373M  25% /boot
/dev/mapper/rhel-home  9.5G   66M  9.4G   1% /home        ---->It's expanded by 2.5G
/dev/sr0               3.7G  3.7G     0 100% /media
Add new volume
[root@localhost ~]# lvcreate -l +100%Free rhel /dev/sda2 -n lv2 --->Create new lv volume Logical volume "lv2" created. [root@localhost ~]# mkfs.xfs /dev/mapper/rhel-lv2 ---->New lv2 Volume format as xfs format meta-data=/dev/mapper/rhel-lv2 isize=256 agcount=4, agsize=327680 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=1310720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mkdir /lv2 ---->Create directory [root@localhost ~]# mount /dev/mapper/rhel-lv2 /lv2/ ---->mount [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 93G 15G 78G 16% / devtmpfs 904M 0 904M 0% /dev tmpfs 914M 80K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 124M 373M 25% /boot /dev/mapper/rhel-home 2.0G 33M 2.0G 2% /home /dev/mapper/rhel-lv2 5.0G 33M 5.0G 1% /lv2
Expansion capacity [root@localhost
~]#xfs_growfs /dev/mapper/rhel-root ---->extend xfs Partition size, which is extended to root Under the root
[root@localhost ~]#resize2fs /dev/mapper/rhel-home 7G ---->extend ext4 Partition size.

Tags: Linux RHEL Vmware ascii

Posted on Tue, 03 Dec 2019 21:12:01 -0500 by chord