Linux partition table

From Ever changing code
Revision as of 20:20, 29 December 2014 by Pio2pio (talk | contribs) (Created page with "The headline it should be '''Working with Partition Table in Linux''' but Google search phrases take precedences as these are more human language much often than we think. Vot...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The headline it should be Working with Partition Table in Linux but Google search phrases take precedences as these are more human language much often than we think. Vote if you disagree!

List partitions

sudo blkid -o list         # read more http://linux.101hacks.com/unix/blkid/
device      fs_type label    mount point     UUID
----------------------------------------------------------------------------------
/dev/sda1   ext4             /               4a5d5028-062d-4a4b-9d1a-c4df9708ef86
/dev/sda5   swap             <swap>          bc8348c5-c188-4627-9df4-32bba94c9c8b
lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0  55.9G  0 disk 
├─sda1   8:1    0  54.4G  0 part /
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0   1.5G  0 part [SWAP]
sudo fdisk -l
Disk /dev/sda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders, total 117210240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f12f1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   114083839    57040896   83  Linux
/dev/sda2       114085886   117209087     1561601    5  Extended
/dev/sda5       114085888   117209087     1561600   82  Linux swap / Solaris
sudo sfdisk -ls
/dev/sda:  58605120

Disk /dev/sda: 7296 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+   7101-   7102-  57040896   83  Linux
/dev/sda2       7101+   7295-    195-   1561601    5  Extended
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
/dev/sda5       7101+   7295-    195-   1561600   82  Linux swap / Solaris
  • -l : List the partitions of a device.
  • -s : List the size of a partition.
  • -u or -uS or -uB or -uC or -uM : Accept or report in units of sectors (blocks, cylinders, megabytes, respecpively). The default is cylinders, at least when the geometry is known


Create a single optimal partition

This can be useful for provisioning EBS disks on AWS instances.

Provision an entire disk

parted -a optimal /dev/xvdb (parted) mklabel msdos #must be one of these supported disk labels: bsd, loop (raw disk access), gpt, mac, msdos, pc98, sun. “disk label” same thing as partition table, partition map Warning: The existing disk label on /dev/xvdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes (parted) mkpart primary ext2 0% 100% (parted) set 1 lvm on

Create a filesystem (format disk)
sudo mkfs.ext4 /dev/xvdb1
Mount
sudo mount /dev/xvdb1 -f ext4 /mnt/xvdb1