Showing posts with label disks. Show all posts
Showing posts with label disks. Show all posts

Monday, March 28, 2016

Linux - Parted the CLI Disk Management Tool

Parted is a famous command line tool that allows you to easily manage hard disk partitions. It can help you add, delete, shrink and extend disk partitions along with the file systems located on them. Parted has gone a long way from when it first came out. Some of it’s functions have been removed, others have been added.

In this tutorial you will learn the basics of parted and we will show you some practical examples. If you don’t have any previous experience with parted, please be aware that parted writes the changes immediately to your disk, so be careful if you try to modify your disk partitions.

If you plan on testing parted, the better option would be to simply use a virtual machine or old computer/laptop without any valuable information on it. To make modifications on a disk partition it must not be in use. If you need to work on primary partition, you may boot into rescue mode.

Note: You will need to have root access to the machine you will be working on in order to use parted.

 

How to Install Parted on Linux

On many Linux distributions, parted comes pre-installed. If it is not included in your distro, you can install it with:

$ sudo apt-get install parted        [On Debian/Ubuntu systems]
# yum install parted                    [On RHEL/CentOS and Fedora]
# dnf install parted                      [On Fedora 22+ versions]

Once you have make sure that parted is installed, you can proceed further to check out some real world examples of parted command in the rest of this article.

 

1. Check Parted Version

Run the following command, you see message similar to the one shown on the image below. Don’t worry if your parted version is different. Unless specified otherwise, parted will use your primary drive, which in most cases will be/dev/sda.

$ parted

clip_image001

Check Parted Command Version

If you want to exit parted, simply type:

$ quit

 

2. List Linux Disk Partitions

Now that parted is started, let’s list the partitions of the selected hard disk. As mentioned earlier, parted chooses your first drive by default. To see the disk partitions run print.

(parted) print

clip_image002

Check Linux Partitions

When running print, it will also display the hard disk information and model. Here is example from a real hard disk (not virtual as shown on the image above) :

(parted) print

Model: ATA TOSHIBA MQ01ACF0 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start   End    Size   Type      File system  Flags

1      1049kB  256MB  255MB  primary   ext2         boot
2      257MB   320GB  320GB  extended
5      257MB   320GB  320GB  logical                    lvm

sector size and partition table.

 

3. List or Switch to Different Disk

If you have more than one hard disk, you can easily switch between disks, by using the “select” command. In the example below, I will switch from /dev/sda to/dev/sdb which is a secondary drive on my system.

To easily switch between disks you can use:

(parted) select /dev/sdX

clip_image003

Select Different Disk

Change "X" with the letter of the disk to which you wish to switch.

 

4. Create Primary or Logical Partition in Linux

Parted can be used to create primary and logical disk partitions. In this example, I will show you how to create primary partition, but the steps are the same for logical partitions.

To create new partition, parted uses “mkpart“. You can give it additional parameters like "primary" or "logical" depending on the partition type that you wish to create.

Before you start creating partitions, it’s important to make sure that you are using (you have selected) the right disk.

Start by using print:

(parted) print

clip_image004

Show Current Linux Disk

As shown on the above image, we are using a virtual drive of 34 GB. First we will give the new disk a label and then create a partition and set a file system on it.

Now the first step is to give the new disk a label name with:

(parted) mklabel msdos

Now create the new partition with  mkpart. The listed units are in megabytes (MB). We will create a 10 GB partition starting from 1 to 10000:

(parted) mkpart

Partition type?  primary/extended? primary
File system type?  [ext2]?
Start? 1
End? 10000
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start   End     Size    Type     File system  Flags
1      1049kB  10.0GB  9999MB  primary   ext2         lba

clip_image005

Create Primary or Logical Linux Partitions

Next,  exit parted with "quit" command. We will format our new partition in ext4 file system using mkfs. To make this happen run the following command:

# mkfs.ext4 /dev/sdb1

Note: It’s important to select the right disk and partition when executing the above command!

Now let’s verify our results, by printing the partition table on our secondary disk. Under file system column, you should see ext4 or the file system type that you have decided to use for your partition:

clip_image006

Verify Disk Partition Filesystem

 

5. Resize Linux Disk Partition

Parted includes multiple useful functions and one of them is "resizepart". As you have probably figured this out by now, "resizepart" helps you resize a partition.

In the example below, you will see how to resize an existing partition. For the purpose of this example, we will be using the earlier created partition.

First you will need to know the number of the partition that you will be resizing. This can be easily found by using "print":

(parted) print

clip_image007

Find Linux Partition Number

In our example, the partition number is "1". Now run the resizepart command:

(parted) resizepart

You will be asked for the number of the partition that you will resize. Enter it’s number. After that, you will be asked to set the new ending point for this partition. Remember that by default the units are in MB. In our example, we have set the new partition size to 15 GB:

(parted) resizepart
Partition number? 1
End?  [10.0GB]? 15000
Now verify the results with "print":
(parted) print

clip_image008

Verify Linux Resize Partition

 

6. Delete Linux Partition

The next thing you will learn is how to delete a partition from your hard drive. To do this, you will need to use the "rm" command within parted. To delete a disk partition you will need to know it’s number.

As mentioned earlier, you can easily obtain this number by using "print". In our example, we will delete the partition with number 1 from our secondary drive/dev/sdb1:

(parted) rm 1

Verify the results by printing the partitions table:

clip_image009

Delete a Linux Partition

 

7. Rescue Linux Disk Partition

Parted supports a “rescue" utility that helps you recover a lost partition between a starting and ending point. If a partition is found within that range, it will attempt to restore it.

Here is an example:

(parted) rescue
Start? 1
End? 15000
(parted) print
Model: Unknown (unknown)
Disk /dev/sdb1: 15.0GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 15.0GB 15.0GB ext4

 

8 Change Linux Partition Flag

Using parted, you can change the state of a flag for disk partitions. The supported flags are:

  • boot
  • root
  • swap
  • hidden
  • raid
  • lvm
  • lba
  • legacy_boot
  • irst
  • esp
  • palo

The states can be either "on" or "off". To change a flag simply run "set"command within parted:

(parted) set 2 lba on

The above command sets lba flag to on for second partition. Verify the results with print:

clip_image010

Change Partition Flag

 

Conclusion

Parted is a useful and powerful utility that can help you manage your disk partitions in Linux systems. As always, when working with disk partitions you need to be extra careful. It is strongly recommend to go through parted man pages to learn how you can customize it’s output and find more information about its capabilities.

If you have any questions or comments, please do not hesitate to use the comment section below.

 

Taken From: http://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/

Wednesday, May 2, 2012

Mount a VMware a Virtual Disk in Windows

How to Mount a VMware Virtual Disk in Windows

Here is handy tool that is part of VMware Workstation, but isnt as well know as some features but can be a real timesaver!

Let’s say your working on a Virtual Machine however it is turned off but you quickly need to pull an important file from it to use or check something you would normally have to go through the process of booting the whole VM to get to the file which may not be desirable if it takes a while to boot the VM, or you dont have the spare RAM (maybe you already have another VM or two running).

Thankfully, VMware can save you some hassle as it includes a tool to map VMware virtual hard disks directly to to the host computer without needing to boot a Virtual Machine at all. To use this tool simply go to File > Map or Disconnect Virtual Disks and click on the Map option, then point it to the .vmdk virtual disk file and select the drive letter to map it to. When you click Ok the drive will load which can take a few seconds and then you will have the disk available to use.

clip_image002

clip_image004

clip_image006

clip_image008

ScreenShot036

There are however a couple of important limitations to note:

· You can only mount partitions that are formatted FAT or NTFS (on Windows anyway), any non-FAT or NTFS partitions that exist in a Virtual Disk won’t be mounted.

· You can’t mount a Virtual Disk that is compressed, encrypted or set to have read-only permissions.

· To run the Virtual Machine that uses a mounted Virtual Disk, you must first disconnect the disk via the Map or Disconnect Virtual Disks menu.

Finally, here is a final warning that I have taken from the VMware Manual that is worth reading if you make use of snapshots (either linked or un-linked ones):

Caution VMware recommends that you leave the check box “Open file in read-only mode” selected in the Map a Virtual Disk dialog box. This setting prevents you from accidentally writing data to a virtual disk that might be the parent of a snapshot or linked clone. Writing to such a disk might make the snapshot or clone unusable.

Based on: http://www.monkeydust.net/2010/02/24/how-to-mount-a-vmware-virtual-disk-in-windows/

Monday, June 1, 2009

Listing Partitions and Disks with FDISK

## List All Partions and Disks #####

In order to list all partions and disks using fdisk, while root just type:

# fdisk -l

And you will get disks and partitions informations all together:

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 3916 31455206 fb Unknown

Disk /dev/sdb: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
255 heads, 63 sectors/track, 8920 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 650 5116702+ 83 Linux
/dev/cciss/c0d0p3 651 8584 63729855 fb Unknown
/dev/cciss/c0d0p4 8585 8920 2698920 f Win95 Ext'd (LBA)
/dev/cciss/c0d0p5 8585 8653 554211 82 Linux swap
/dev/cciss/c0d0p6 8654 8907 2040223+ 83 Linux
/dev/cciss/c0d0p7 8908 8920 104391 fc Unknown


This is quite confusing if you have multiple disks with multiple partitions, so next I'm, going to show you how to, only show the disks and then, pick a disk and then list it`s partitions



## List All Disks #####

Now I'm going to show you how to list only the disks, for that while in root just type:

# fdisk -l | grep Disk

The result shold be something like this:

Disk /dev/sdk doesn't contain a valid partition table
Disk /dev/sda: 32.2 GB, 32212254720 bytes
Disk /dev/sdb: 53.6 GB, 53687091200 bytes
Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes

Here you only see the harddrives and no partitions, now you can pick which hardrive you want to see the partitions. Im picking
/dev/cciss/c0d0, and next i will show you only it's partitions.


## List a Disk's Partitions #####

Now listing all the partitions in one disk, for that while in root just type:

# fdisk -l /dev/cciss/c0d0

The result should be something like this:

Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
255 heads, 63 sectors/track, 8920 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 650 5116702+ 83 Linux
/dev/cciss/c0d0p3 651 8584 63729855 fb Unknown
/dev/cciss/c0d0p4 8585 8920 2698920 f Win95 Ext'd (LBA)
/dev/cciss/c0d0p5 8585 8653 554211 82 Linux swap
/dev/cciss/c0d0p6 8654 8907 2040223+ 83 Linux
/dev/cciss/c0d0p7 8908 8920 104391 fc Unknown



That's all, happy listing...