7

I just changed around the partition table of an Ubuntu 12.04 Desktop and everything seems to be working fine. I want to perform similar changes on another (more important) system.

The machine boots so I'm guessing everything worked well.

Is there a more comprehensive way to check that the partition table is ok and the filesystem is consistent?

2 Answers 2

9

If you have a MBR partition table, you can use fdisk:

sudo fdisk -l

This command will print out the partition table and will also automatically perform some consistency checks. If instead you have a GPT partition table, you can use gdisk (thanks Rod Smith for pointing that out):

sudo gdisk /dev/something

where /dev/something is the path to your disk device file (e.g. /dev/sda). From the gdisk interface you will be able to press v to run consistency checks.


About the filesystem, there are many ways to perform the check, the one I prefer is this:

sudo touch /forcefsck

This way, once you reboot the computer, the filesystem is checked for errors. This is a nice way of doing it because you don't need to worry about the dangers of running fsck.

It's worth noting that the file /forcefsck will be automatically deleted as soon as the check has completed.

2
  • Note that until very recently, fdisk has worked only on MBR disks, and Ubuntu isn't yet shipping the version that works on GPT disks. (GPT is used on EFI-based computers, and sometimes on BIOS-based computers.) Use gdisk or parted on GPT disks. gdisk in particular has a v option to check the integrity of the partition table.
    – Rod Smith
    Aug 22, 2013 at 14:29
  • @RodSmith: thank you for pointing that out. I've included gdisk in my answer. Aug 22, 2013 at 14:39
2

You can use the fsck command. Make sure to execute the fsck on an unmounted file systems to avoid any data corruption issues.

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

fsck /dev/sdaX

Make sure to replace the X with you device number.

The following are the possible exit codes for fsck command.

0 – No errors
1 – Filesystem errors corrected
2 – System should be rebooted
4 – Filesystem errors left uncorrected
8 – Operational error
16 – Usage or syntax error
32 – Fsck canceled by user request
128 – Shared-library error

You may also take a look at 10 Linux Fsck Command Examples to Check and Repair Filesystem

Source:fsck Man Page

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .