How do I add a partition to a disk under linux redhat using parted?



  • This article adds adds a partition and then uses it to create a volume group and logical volume.

    First see what you have already, c0d0 is the whole disk, which had three partitions p1, p2, and p3.

    # cd /dev/cciss
    # ls
    c0d0  c0d0p1  c0d0p2  c0d0p3
    

    Use parted to add the new partition, p4 is the extended partition, after adding the intial partitions, the remaining space is the extended partition, from this you can add other partitions.

    # parted
    GNU Parted 1.6.19
    Copyright (C) 1998 - 2004 Free Software Foundation, Inc.
    This program is free software, covered by the GNU General Public License.
    
    This program is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.  See the GNU General Public License for more details.
    
    Using /dev/cciss/c0d0
    (parted) p
    Disk geometry for /dev/cciss/c0d0: 0.000-69973.593 megabytes
    Disk label type: msdos
    Minor    Start       End     Type      Filesystem  Flags
    1          0.031    101.975  primary   ext3        boot
    2        101.975   5224.262  primary   ext3
    3       5224.263  21610.876  primary   linux-swap
    4      21610.876  69970.605  extended
    
    (parted) m
    
      check MINOR                   do a simple check on the filesystem
      cp [FROM-DEVICE] FROM-MINOR TO-MINOR      copy filesystem to another partition
      help [COMMAND]                prints general help, or help on COMMAND
      mklabel LABEL-TYPE            create a new disklabel (partition table)
      mkfs MINOR FS-TYPE            make a filesystem FS-TYPE on partititon MINOR
      mkpart PART-TYPE [FS-TYPE] START END      make a partition
      mkpartfs PART-TYPE FS-TYPE START END      make a partition with a filesystem
      move MINOR START END          move partition MINOR
      name MINOR NAME               name partition MINOR NAME
      print [MINOR]                 display the partition table, or a partition
      quit                          exit program
      rescue START END              rescue a lost partition near START and END
      resize MINOR START END        resize filesystem on partition MINOR
      rm MINOR                      delete partition MINOR
      select DEVICE                 choose the device to edit
      set MINOR FLAG STATE          change a flag on partition MINOR
    
    (parted) mkpart logical ext3 21610.907 69970.605
    
    (parted) p
    Disk geometry for /dev/cciss/c0d0: 0.000-69973.593 megabytes
    Disk label type: msdos
    Minor    Start       End     Type      Filesystem  Flags
    1          0.031    101.975  primary   ext3        boot
    2        101.975   5224.262  primary   ext3
    3       5224.263  21610.876  primary   linux-swap
    4      21610.876  69970.605  extended
    5      21610.907  69970.605  logical   ext3
    
    (parted) quit
    Information: Don't forget to update /etc/fstab, if necessary.
    

    Check the new partition has been added.

    # ls
    c0d0  c0d0p1  c0d0p2  c0d0p3  c0d0p5
    

    Make the partition a LVM recognised partition.

    # pvcreate /dev/cciss/c0d0p5
      Physical volume "/dev/cciss/c0d0p5" successfully created
    

    Add the physical partition to a volume group, this creates vg01 with partition c0d0p5 in the volume group.

    # vgcreate vg01 /dev/cciss/c0d0p5
      Volume group "vg01" successfully created
    

    Check the volume group you have created.

    #  vgdisplay vg01
      --- Volume group ---
      VG Name               vg01
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               47.22 GB
      PE Size               4.00 MB
      Total PE              12089
      Alloc PE / Size       0 / 0
      Free  PE / Size       12089 / 47.22 GB
      VG UUID               1IxO0M-RVXu-FaJa-WByR-xdJG-ubtY-iV9mpR
    

    Create the logical volume under the volume group.

    # lvcreate -n lvol1 --size 47.22G vg01
      Rounding up size to full physical extent 47.22 GB
      Logical volume "lvol1" created
    

    Create the filesystem on the logical volume.

    # mkfs -t ext3 /dev/vg01/lvol1
    mke2fs 1.35 (28-Feb-2004)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    6193152 inodes, 12379136 blocks
    618956 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=4294967296
    378 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000, 7962624, 11239424
    
    Writing inode tables: done
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 38 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

    Add the file system to the /etc/fstab

    # vi /etc/fstab
    

    Add:
    /dev/vg01/lvol1 /kickstart ext3 defaults 1 2

    Mount the filesystem.

    # mkdir /kickstart
    # mount /kickstart
    # df -k
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2      5162828   4176164    724404  86% /
    none                   8207000         0   8207000   0% /dev/shm
    10.150.50.9:/var/crash
                          16523776   5138432  11220128  32% /mnt
    /dev/mapper/vg01-lvol1
                          48739168   3863764  42399580   9% /kickstart
    

    Note: Automatically uses the multipath device. Beginning with /dev/mapper


Log in to reply
 

© Lightnetics 2024