EzDevInfo.com

fdisk interview questions

Top fdisk frequently asked interview questions

why does the partition start on sector 2048 instead of 63

I had two drives partitioned the same and running 2 raid partitions on each.

One died and I replaced it under warranty for the same model.

While trying to partition it, the first partition can only start on sector 2048, instead of 63 that was before. Driver have different geometry as previous and remaining ones. (Fewer heads/more cylinders)

old drive:

$ sudo fdisk -c -u -l /dev/sdb 

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 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: 0x000aa189

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          63   174080339    87040138+  83  Linux
/dev/sdb2       174080340   182482334     4200997+  82  Linux swap / Solaris
/dev/sdb3       182482335  3907024064  1862270865   fd  Linux raid autodetect

remanufactured drive received from warranty:

$ sudo fdisk -c -u -l /dev/sda

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 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: 0x000d0b5d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  ...

why is that?


Source: (StackOverflow)

Creating and formating a partition using a bash script

Is there any way to create and format a partition using a bash script?

I think it can be done with fdisk but I don't know how to feed commands from the bash script into the fdisk shell then exit the fdisk shell.

I'm wanting to create a partition then format it to ntfs from within bash.


Source: (StackOverflow)

Advertisements

What does sfdisk do, and how does it compare to fdisk or parted?

I was looking over documentation for ZFS for Linux and I came accross a command that the instructions tell me to run to prepare a disk for use.

The command was;

sfdisk -q /dev/zvol/tank/fish << EOF
0,
EOF

The line breaks are included the command took up 3 lines

What does sfdisk do? Is it the same and creating a new partition table or is it something different?

Here is the documentation I was looking at, Link


Source: (StackOverflow)

What is the equivalent of the Linux command "sudo fdisk -l" in MacOS?

In Linux, the command sudo fdisk -l produces an output the lists all the disks and partitions in the computer. The following is an example of fdisk -l output:

Example of fdisk -l output

If I try to use sudo fdisk -l in MacOS X 10.7.5, the output is like this:

fdisk: illegal option -- l
usage: fdisk [-ieu] [-f mbrboot] [-c cyl -h head -s sect] [-S size] [-r] [-a style] disk
    -i: initialize disk with new MBR
    -u: update MBR code, preserve partition table
    -e: edit MBRs on disk interactively
    -f: specify non-standard MBR template
    -chs: specify disk geometry
    -S: specify disk size
    -r: read partition specs from stdin (implies -i)
    -a: auto-partition with the given style
    -d: dump partition table
    -y: don't ask any questions
    -t: test if disk is partitioned
`disk' is of the form /dev/rdisk0.
auto-partition styles:
  boothfs     8Mb boot plus HFS+ root partition (default)
  hfs         Entire disk as one HFS+ partition
  dos         Entire disk as one DOS partition
  raid        Entire disk as one 0xAC partition

Is there another command in MacOS to replicate the behavior of fdisk -l in Linux?


Source: (StackOverflow)

What does the output of fdisk mean?

I've got a flash drive and I want to understand the properties of it as is outputted from fdisk. I inserted it and check the dmesg and I could see that it was mounted as /dev/sdb1 so I ran fdisk to see what is reported for /dev/sdb

mike@mike-Qosmio-X770:~$ sudo fdisk -l
[sudo] password for mike: 

Disk /dev/sdb: 127 MB, 127926272 bytes
16 heads, 32 sectors/track, 488 cylinders, total 249856 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: 0x6b3ee723

   Device Boot      Start         End      Blocks   Id  System
 /dev/sdb1   *          32      249854      124911+   b  W95 FAT32

As far as I can tell, the drive is a 128MB FAT32 formatted flash drive, it only has 1 partition on it. It starts at "32" (presumably 0-31 is used for some FTL).

It's reporting a "sector" is 512 bytes in size and there are 249,856 sectors (122MB total).

Now I'm confused about the Cylinder, head, and sectors/track count. I know cylinders/heads have to do with Magnetic disk storage types. Is there any meaning for these when it comes to a flash device? Or is this just "left over" information from fdisk which really has no meaning to a non-magnetic storage medium? If the later, why give values at all?

Second question, what is the "size" of a block? :

Blocks
 124911+

And what is the meaning of the + after the block count?


Source: (StackOverflow)

Recover harddrive data

I have a dell laptop that recently "died" (It would get the blue screen of death upon starting) and the hard drive would make a weird cyclic clicking noises.

I wanted to see if I could use some tools on my linux machine to recover the data, so I plugged it into there.

If I run "fdisk" I get:

Disk /dev/sdb: 20.0 GB, 20003880960 bytes
64 heads, 32 sectors/track, 19077 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x64651a0a

Disk /dev/sdb doesn't contain a valid partition table

Fine, the partition table is messed up. However if I run "testdisk" in attempt to fix the table, it freezes at this point, making the same cyclical clicking noises:

Disk /dev/sdb - 20 GB / 18 GiB - CHS 19078 64 32
Analyse cylinder   158/19077: 00%

I don't really care about the hard drive working again, and just the data, so I ran "gpart" to figure out where the partitions used to be. I got this:

dev(/dev/sdb) mss(512) chs(19077/64/32)(LBA) #s(39069696) size(19077mb)

* Warning: strange partition table magic 0x2A55.
Primary partition(1)
   type: 222(0xDE)(UNKNOWN)
   size: 15mb #s(31429) s(63-31491)
   chs:  (0/1/1)-(3/126/63)d (0/1/32)-(15/24/4)r
   hex:  00 01 01 00 DE 7E 3F 03 3F 00 00 00 C5 7A 00 00

Primary partition(2)
   type: 007(0x07)(OS/2 HPFS, NTFS, QNX or Advanced UNIX) (BOOT)
   size: 19021mb #s(38956987) s(31492-38988478)
   chs:  (4/0/1)-(895/126/63)d (15/24/5)-(19037/21/31)r
   hex:  80 00 01 04 07 7E FF 7F 04 7B 00 00 BB 6F 52 02

So I tried to mount just to the old NTFS partition, but got an error:

sudo mount -o loop,ro,offset=16123904 -t ntfs /dev/sdb /mnt/usb
NTFS signature is missing.

Ugh. Okay. But then I tried to get a raw data dump by running

dd if=/dev/sdb of=/home/erik/brokenhd skip=31492 count=38956987

But the file got up to 59885568 bytes, and made the same cyclical clicking noises.

Obviously there is a bad sector, but I don't know what to do about it!

The data is still there... if I view that 57MB file in textpad... I can see raw data from files.

How can I get my data back?

Thanks for any suggestions,

Solution:

I was able to recover about 90% of my data:

  1. Froze harddrive in freezer
  2. Used Ddrescue to make a copy of the drive
  3. Since Ddrescue wasn't able to get enough of my drive to use testdisk to recover my partitions/file system, I ended up using photorec to recover most of my files

Source: (StackOverflow)

Is my OCZ SSD aligned correctly?

I have an OCZ Agility 2 SSD with 40 GB of space. I use it as a system drive in Debian Linux ("Squeeze") and in my opinion it's really fast. I've read a lot on aligning partitions and file systems, and I'm not sure if I succeeded in aligning the partitions correctly. Maybe the SSD could be even faster?

I use ext4 and here is the output of fdisk -cul:

Disk /dev/sda: 40.0 GB, 40018599936 bytes
255 heads, 63 sectors/track, 4865 cylinders, total 78161328 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: [...]

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    73242623    36620288   83  Linux
/dev/sda2        73244670    78159871     2457601    5  Extended
/dev/sda5        73244672    78159871     2457600   82  Linux swap / Solaris

My partitions were created just by the Debian Squeeze setup assistant. So I didn't care about the details of partitioning. But now I think that maybe the installer didn't align it correctly? Actually, 2048 looks good to me (better than odd values like 63 or something like that) but I've no idea.

According to some "SSD Alignment Calculator" I found on the web, the OCZ SSDs have a NAND Erase Block Size of 512kB and their NAND Page Size is 4kB.

2048 is divisible by 4 and 512. So are the partitions aligned correctly?


Source: (StackOverflow)

Re-reading the partition table failed with error 22: invalid argument

I have Oracle Linux on a VM and I'm trying to create partitions on /dev/sda2 of size 30 gigs using fdisk utility. I made four partitions each of size 512M and they appear in the partition table. However, when i try to write (w) table to disk, i get the error as above.

Here's what i've tried so far

  • Reboot does not change anything.
  • fdisk -u -l /dev/sda2 shows the 4 created partitions (p1,p2,p3,p4), but fdisk -l doesn't.
  • kpartx -a /dev/sda2px shows failed to stat() /dev/sda2px
  • partprobe /dev/sda2 shows:

Error: Error informing the kernel about modifications to partition /dev/sda2px - invalid argument. This means Linux won't know about any changes you made to /dev/sda2p1 until you reboot -- so you shouldn't mount it or use it in any way before rebooting

Any ideas will be much appreciated. Thanks in advance.


Source: (StackOverflow)

What is the "the dos compatibility flag" in fdisk?

I fired up fdisk and got this warning:

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

I didn't even know that my previous Linux installs where DOS-compatible in any way!

What the hell does changes?! The man page says nothing about it.

Thanks for answering.


Source: (StackOverflow)

How to create NTFS partition in Linux to install Windows 7 from USB?

I messed up with my computer and need help.

Generally: install Windows 7 from USB.

Problem: "setup was unable to create a new system partition"

When first attempt to install Windows 7 failed I tried Linux live USB, installed distro to HDD, and erased all the existing partitions. Current state (fdisk -l): [writing from other computer so no copy and paste]

/dev/sda1   305GB   Linux
/dev/sda2   7GB Extended
/dev/sda5   7GB Linux Swam / Solaris

To create a new, NTFS partition:

fdisk /dev/sda
n (for new)
p (for primary)
3 (for partintion number)
"No free sectors available"

All the HDD was formatted couple of minutes before so there is a lot of free space but how to resize a parition?

I cannot find an option for resizing in man fdisk. Some people say I should use gparted but my distro doesn't not contain this package. And my distro doesn't support wireless drivers so I have serious problems with downloading stuff.

I tried also using cfdisk but any command results in:

"cfdisk bad primary partition 1 partition ends in the final partial cylinder"

I tried also removing partition 1 and then creating a new one (so there is no "no free sectors"). I'm receiving a 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."

After restarting: grub rescue, no known filesystem

It may indicate that some changes have been made BUT when running Windows 7 installed some another error: Windows cannot be installed to Disk 0 Partition 1

More detailed: Windows cannot be installed to this hard disk space. Windows must be installed to a partition formatted as NTFS.

So formatting drive using Windows 7 installer

BUT this time yet another error: "Setup was unable to create a new system partition or locate an existing system partition. See the setup log files for more information"

Apparently I cannot access logs (how?) and I am back to drawing board with my live USB (this time showing partition as HPFS/NTFS).

Any suggestions how to install Windows 7? Should I reinstall Linux to HDD, erase existing partitions once again, and use Parted rather than gparted (parted is included in the distro). Or maybe should I create another bootable USB such as PartedMagic to painlessly create partitions?

I just want to install Windows 7 from USB, my laptop is semi-operational and I am ready to receive some help regarding fdisk and creating NTFS partitions.

UPDATE: I did as suggested (removed all the partitions) and tried to install in unallocated space. Tried to create a new partition and format it. Same error: "setup was unable to create a new system partition"

Came to the conclusion it may have something to do with TrueCrypt I have recently installed. Right now trying to FIX MBR (as I haven't got possibility to create rescue disc without optical drive)


Source: (StackOverflow)

Partition Not Showing up in /dev

I recently unmounted a 4TB hard drive from one computer in order to access the files directly from another computer. It seemed like there were no problems with the unmounting process. When connecting the hard drive to the other computer, the hard drive is recognized in "/dev" as sdb, but the partition "sdb1" is not appearing, therefore I cannot mount it. If I run

fdisk -l /dev/sdb


WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 cylinders, total 7814037168 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: 0x00000000

Device Boot          Start     End      Blocks      Id  System
/dev/sdb1               1  4294967295  2147483647+  ee  GPT

The sdb1 partition shows up. Since this is a 4TB partition, I also ran the command

parted /dev/sdb

GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ASMT 2105 (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

Then typed "print". In this case, the sdb1 partition does NOT show up.

Why is there a mismatch of information here? Does this mean that the partition has been deleted? Is there any way to possibly recover this partition and mount it?

Thank you very much in advance


Source: (StackOverflow)

How do you create and partition a raw disk image?

I need to create a raw disk image for use in a virtual machine, but I need to create the partitions before creating the file system or installing the operating system.

Can anyone describe a process to do this?


Source: (StackOverflow)

After doubling virtual disk size in VirtualBox, fdisk -l still shows old disk size in guest CentOS

I'm running CentOS 6.1 as a guest in VirtualBox 4.1.18 on a Mac OS X (Snow Leopard) host. Since 50 GB for my CentOS guest proved to be insufficient, I resolved to double its available disk space. After extensively searching the internet for a viable course of action, I settled on the following:

  1. Double size of VDI file through "vboxmanage modifyhd centos6.1.vdi --resize 102400"
  2. Verify in VirtualBox GUI that disk size is now indeed 100 GB
  3. Download Parted Magic ISO file and boot VM into Parted Magic
  4. In Parted Magic, fire up Partition Editor
  5. In Partition Editor, see ~ 50 GB of "unallocated" space
  6. In Partition Editor, resize /dev/sda2 (managed by LVM in my case) to use up all unallocated space, effectively increasing its size by 50 GB
  7. Shut down VM
  8. Boot VM into CentOS 6.1 and use lvm tools to grow existing volumes.

However, I fail at step 5. Partition Editor shows /dev/sda's size to still be 50 GB, NOT 100 GB. There is no "unallocated" space I could use to grow /dev/sda2's size. This is consistent with the output of fdisk -l, run either in Parted Magic or CentOS:

[root@dev ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes  
255 heads, 63 sectors/track, 6527 cylinders  
Units = cylinders of 16065 * 512 = 8225280 bytes  
Sector size (logical/physical): 512 bytes / 512 bytes  
I/O size (minimum/optimal): 512 bytes / 512 bytes  
Disk identifier: 0x0006702c

Device Boot Start End Blocks Id System  
/dev/sda1 * 1 32 256000 83 Linux  
Partition 1 does not end on cylinder boundary.  
/dev/sda2 32 6528 52171776 8e Linux LVM

In step 2 above, I verified that VirtualBox' GUI does indeed show my VM's virtual hard drive to be 100 GB in size. Could someone explain why neither fdisk nor Parted Magic see those extra 50 GB?


Source: (StackOverflow)

Partitioning a disk with already existing partitions

On a Linux Virtual Machine that I recently setup, I had a disk (/dev/sdb) of size 20G in which I created 8 partitions (3 primary, 1 extended containing 5 logical partitions), using up to 10G of space. So there's 10G unpartitioned.

I can't use fdisk as the maximum allowable partitions 4 already created. Is there any other way to create new partitions on the remaining 10G space, without modifying or deleting existing partitions?

I could add a new disk /dev/sdc and use it, but I want to see what else can be done on /dev/sdb.


Source: (StackOverflow)

Update udev after fdisk run

How to update /dev directory after creation of new partition on a disk? I have the udev installed, it works perfectly except this. The new devices appear only on reboot.


Source: (StackOverflow)