Showing posts with label parted. Show all posts
Showing posts with label parted. Show all posts

Tuesday, June 7, 2011

Creating and mounting filesystem ext2 ext3 ext4

[root@rhel02 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  check NUMBER                             do a simple check on the file system
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partition NUMBER
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
  move NUMBER START END                    move partition NUMBER
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resize NUMBER START END                  resize partition NUMBER and its file system
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext2
Start? 0
End? 100
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) pri
Model: VBOX HARDDISK (scsi)
Disk /dev/sdb: 524MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End    Size   Type     File system  Flags
 1      512B   100MB  100MB  primary  ext2

(parted) quit
Information: You may need to update /etc/fstab.

[root@rhel02 ~]# partprobe /dev/sdb


Create the same way for /dev/sdc (ext3) and /dev/sdd (ext4)

To show the filesystem created
[root@rhel02 ~]# parted /dev/sdb print
Model: VBOX HARDDISK (scsi)
Disk /dev/sdb: 524MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End    Size   Type     File system  Flags
 1      512B   100MB  100MB  primary  ext2

[root@rhel02 ~]# parted /dev/sdc print
Model: VBOX HARDDISK (scsi)
Disk /dev/sdc: 524MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End    Size   Type     File system  Flags
 1      512B   100MB  100MB  primary  ext3

[root@rhel02 ~]# parted /dev/sdd print
Model: VBOX HARDDISK (scsi)
Disk /dev/sdd: 524MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End    Size   Type     File system  Flags
 1      512B   100MB  100MB  primary  ext4


Alternative commands
mkfs.ext2 /dev/sdb1
mkfs.ext3 /dev/sdc1
mkfs.ext4 /dev/sdd1

Mounting
mount /dev/sdb1 /mnt
mount /dev/sdc1 /mnt2
mount /dev/sdd1 /mnt3

Creating partition using one liner

[root@rhel02 ~]# parted /dev/sdc mkpart primary ext4 0 500

RAID

Parted


To list disk
parted -l |grep sd    #sd-scsi disks

Use in command line
parted <device> <command>
parted /dev/sdb print


Creating a raid5

mdadm -Cv /dev/md0 --level=5 -n3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm --detail /dev/md0

Use the command below to create a copy of the partition of an existing disk then format then use mdadm --add to the array.
sfdisk -d /dev/<origin-disk> |sfdisk /dev/<destination-disk>
Example:
sfdisk -d /dev/sda | sfdisk /dev/sdb

Fail a disk
mdadm /dev/md0 -f /dev/sdb1

Remove a disk
mdadm /dev/md0 -r /dev/sdb1

Add a disk
mdadm /dev/md0 -a /dev/sdb1

Start md
mdadm --assemble --scan

Saving mdadm config
echo 'DEVICE /dev/sd*'  > /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf

Removing array
mdadm -S /dev/md0  >> stop md
mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdc1
mdadm --zero-superblock /dev/sdd1