GPT, LVM concepts and basic shell scripts

GPT, LVM concepts and basic shell scripts

  • GPT is describing what should be how to use
    the full name 1.GPT a Globally Unique Identifier Partition Table, which means GUID partition table, GUID partition table (GPT) as Extensible Firmware Interface (EFI) part of the plan introduced. Main previous commonly used PC Boot Record (MBR) partitioning scheme with respect, GPT provides a more flexible disk partitioning scheme. It refers to physical storage space on a partition or logical disk connected to each other, but provide a function as physically separate disks. For the system firmware and the installed operating system, the partition is visible. Before the operating system starts, access to the partitions controlled by the system firmware, after the operating system is started by the operating system.
    2 has the following advantages:
    (1) support the hard disk 2TB more;
    number of partitions (2) of each disk is almost no limit (Windows system only allows a maximum of 128 partitions dividing);
    (3) virtually no limit to the size of the partition. Another "almost." Because it uses 64-bit integer number of sectors, i.e., = 18,446,744,073,709,551,616;
    (4) carrying the partition table backup. Head and tail portions of the disk are stored a same partition table, wherein the one is destroyed by another recovery;
    (5) a cyclic redundancy check value calculated for critical data structures, improving the detection of data corruption probability;
    (6) while providing an MBR partition type byte code but using a 16-byte GPT globally unique identifier (GUID) to identify the value of the partition type, partition type which makes more difficult conflict;
    (7) each partition can have a name (different from the label).
    3. To use the GPT partition table must be UEFI BIOS environment, UEFI and GPT complementary, and both are indispensable, and now the basic server board uses UEFI + BIOS coexistence mode, and integrated UEFI BIOS startup items, if our system disk size exceeds 2T we need to use UEFI mode system installation and system startup, when the non-system disk partition larger than 2T, we need to select GPT partition format.
  • 10G create a partition, and format for the file system ext4:
    (. 1) Block size is 2048, a 20% reserve space, the volume label MYDATA,: claim
    disabled (2) to mount / mydata directory, to mount program to run automatically, and does not update the access time stamp of the file.
    (3) can be switched automatically mounted.
    (1) fdisk to create partitions 10G
    [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
    All primary partitions are in use
    Adding logical partition 6
    First sector (141940736-419430399, default 141940736): 
    Using default value 141940736
    Last sector, +sectors or +size{K,M,G} (141940736-419430399, default 419430399): +10G
    Partition 6 of type Linux and of size 10 GiB is set
    Command (m for help): w
    The 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 at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.

    (2) mkfs create the file system:

    [root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6/
    mke2fs 1.42.9 (28-Dec-2013)
    Could not stat /dev/sda6/ --- Not a directory
    [root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=MYDATA
    OS type: Linux
    Block size=2048 (log=1)
    Fragment size=2048 (log=1)
    Stride=0 blocks, Stripe width=0 blocks
    655360 inodes, 5242880 blocks
    1048576 blocks (20.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=273678336
    320 block groups
    16384 blocks per group, 16384 fragments per group
    2048 inodes per group
    Superblock backups stored on blocks: 
    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 
    2048000, 3981312
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   

    (3) mounted to / mydata directory, to ban the program to run automatically when the mount, and does not update the access time stamp of the file. And set the boot automatically mount

    [root@localhost ~]# mkdir -p /mydata
    [root@localhost ~]# vim /etc/fstab
    /dev/sda6                        /mydata                 ext4    defaults,noatime,noexec 0 0
    [root@localhost ~]# mount -a
    [root@localhost ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        47G  5.2G   42G  12% /
    devtmpfs        523M     0  523M   0% /dev
    tmpfs           538M     0  538M   0% /dev/shm
    tmpfs           538M  7.8M  530M   2% /run
    tmpfs           538M     0  538M   0% /sys/fs/cgroup
    /dev/sda1       497M  151M  346M  31% /boot
    /dev/sda3        19G   39M   19G   1% /data
    tmpfs           108M  4.0K  108M   1% /run/user/42
    tmpfs           108M   32K  108M   1% /run/user/1000
    /dev/sr0        8.1G  8.1G     0 100% /run/media/wl/CentOS 7 x86_64
    tmpfs           108M     0  108M   0% /run/user/0
    /dev/sda6       9.8G   13M  7.8G   1% /mydata
  • Creating a swap partition size for the 1G and enable:
    [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
    All primary partitions are in use
    Adding logical partition 7
    First sector (162914304-419430399, default 162914304): 
    Using default value 162914304
    Last sector, +sectors or +size{K,M,G} (162914304-419430399, default 419430399): +1G
    Partition 7 of type Linux and of size 1 GiB is set
    Command (m for help): t
    Partition number (1-7, default 7): 7
    Hex code (type L to list all codes): 82
    Changed type of partition 'Linux' to 'Linux swap / Solaris'
    Command (m for help): w
    The 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 at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    [root@localhost ~]# mkswap /dev/sda7 
    Setting up swapspace version 1, size = 1048572 KiB
    no label, UUID=ba42d9ae-41a0-4829-bd14-a32834cf6ec9
    [root@localhost ~]# swapon /dev/sda7
    [root@localhost ~]# vim /etc/fstab 
    /dev/sda7                                 swap                    swap    defaults      0  0 
  • Scripting computing / etc / passwd file, the first 10 users and 20 user id and number of
    #!/bin/bash
    #判断系统是否存在20个用户
    id_sum=$( cat /etc/passwd | wc -l )
    [ ${id_sum} -lt 20 ] && echo "用户个数小于20" && exit 2
    id1=$(head -10 /etc/passwd | tail -1 | cut  -d: -f3)
    id2=$(head -20 /etc/passwd | tail -1 | cut -d: -f3)
    idsum=$[${id1}+${id2}]
    echo "Ths sum is $idsum"
    [root@localhost scripts]# bash -x  idsum2.sh 
    ++ cat /etc/passwd
    ++ wc -l
    + id_sum=58
    + '[' 58 -lt 20 ']'
    ++ head -10 /etc/passwd
    ++ tail -1
    ++ cut -d: -f3
    + id1=11
    ++ head -20 /etc/passwd
    ++ tail -1
    ++ cut -d: -f3
    + id2=997
    + idsum=1008
    + echo 'Ths sum is 1008'
    Ths sum is 1008
  • Save the current hostname to hostName variable, if the host name is empty or is
    localhost.localdomain will be set to www.magedu.com
    #!/bin/bash
    hostName=$(hostname)
    [ -z "${hostName}" -o "${hostName}" == "localhost.localdomain" -o "${hostName}" == "locahost" ] && hostnamectl set-hostname www.magedu.com || echo "主机名:${hostName},不要修改"
    [root@localhost scripts]# bash -x hostname.sh 
    ++ hostname
    + hostName=localhost.localdomain
    + '[' -z localhost.localdomain -o localhost.localdomain == localhost.localdomain -o   localhost.localdomain == locahost ']'
    + hostnamectl set-hostname www.magedu.com
  • Scripting, command line parameters into a user name, judge id number is even or odd
    #!/bin/bash
    #脚本判断参数用户ID奇偶类型
    [ $# -lt 1 ] && echo "At least a username " && exit 1
    ! id $1 && echo "No such user" && exit 2
    userid=$(id -u $1)
    useri=$[${userid}%2]
    if [ ${useri} -eq 0 ];then
    echo "$1 ID 是偶数"
    else
    echo "$1 ID 是奇数"
    fi
    root@localhost scripts]# bash -xv   id.sh  user3
    #!/bin/bash
    #脚本判断参数用户ID奇偶类型
    [ $# -lt 1 ] && echo "At least a username " && exit 1
    + '[' 1 -lt 1 ']'
    ! id $1 && echo "No such user" && exit 2
    + id user3
    uid=1003(user3) gid=1003(user3) groups=1003(user3)
    userid=$(id -u $1)
    ++ id -u user3
    + userid=1003
    useri=$[${userid}%2]
    + useri=1
    if [ ${useri} -eq 0 ];then
     echo "$1 ID 是偶数"
    else
     echo "$1 ID 是奇数"
    fi
    + '[' 1 -eq 0 ']'
    + echo 'user3 ID 是奇数'
    user3 ID 是奇数
  • lvm basic application and extension reduction achieved
    (1) LVM Principles
    LVM is (Logical Volume Manager) Logical Volume Manager shorthand, it is a mechanism to manage disk partitions under Linux. LVM is establishing a logical layer above the hard disk partition and shielding the underlying disk layout, to facilitate dynamic adjustment of disk capacity to increase the flexibility of management of the disk partition. It may be one or more underlying devices organized into blocks of a logical volume device group, the administrator can freely create the logical volume group (logical volumes) in the volume group, and further creates a file system on a logical volume set, administrators can easily adjust the size of the LVM volume group storage, disk storage and may be named by groups manner, management and distribution
    GPT, LVM concepts and basic shell scripts

(2) LVM basic terms:

 (a)物理存储介质(PhysicalStorageMedia):
            指系统上最底层的物理存储设备:磁盘,例如:/dev/sda、/dev/sdb等
(b)物理卷(Physical Volume, PV):
       指磁盘、磁盘分区或RAID设备,使用LVM前需要先将之制作成便于识别的物理卷PV
(c)卷组(Volume Group, VG):
         卷组由一个或多个物理卷PV组成,在卷组之上可创建一个或多个逻辑卷LV。卷组VG类似于非LVM系统的 物理磁盘
(d)逻辑卷(Logical Volume, LV):
        建立在卷组VG之上,相当于逻辑分区,可在逻辑卷LV上进行一系列操作(例如:格式化、挂载等)。 逻辑卷LV类似于非LVM系统的磁盘分区
(d)物理扩展块(Physical Extent, PE):
        当物理卷PV加入某一卷组VG后即被划分为基本单元PE,PE是LVM寻址的最小单元。PE的大小是可配置的,默认为4M。
(e)逻辑扩展块(Logical Extent, LE):
        卷组VG将PE划分给逻辑卷LV,在逻辑卷LV中的PE称为LE。在同一卷组VG中,PE和LE大小相同,且相互对应。LE也是LVM的最小寻址单位。

(3) LVM basic operations:
(A) PV management tools:

pvs:简要pv信息显示
pvdisplay:显示pv的详细信息
pvcreate /dev/DEVICE: 创建pv

(B) vg management tools:

vgs
vgdisplay
vgcreate  [-s #[kKmMgGtTpPeE]] VolumeGroupName  PhysicalDevicePath [PhysicalDevicePath...]
vgextend  VolumeGroupName  PhysicalDevicePath [PhysicalDevicePath...]
vgreduce  VolumeGroupName  PhysicalDevicePath [PhysicalDevicePath...]
先做pvmove
vgremove

(C) lv management tools:

lvs
lvdisplay
lvcreate -L #[mMgGtT] -n NAME VolumeGroup
vremove /dev/VG_NAME/LV_NAME

(D) extended logical volume:

    # lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME
    # resize2fs /dev/VG_NAME/LV_NAME(e)缩减逻辑卷:
    # umount /dev/VG_NAME/LV_NAME# e2fsck -f /dev/VG_NAME/LV_NAME
    # resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]
    # lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME
    # mount

Guess you like

Origin blog.51cto.com/14418331/2434553