Linux Disk Management: Difference between revisions

From miki
Jump to navigation Jump to search
(→‎Partitions: fix typos / comments)
Line 17: Line 17:
$ sudo parted /dev/sda unit s print # ... using sector as unit (more accurate)
$ sudo parted /dev/sda unit s print # ... using sector as unit (more accurate)
$ sudo sfdisk -l -uS /dev/sda # Show partition table for device /dev/sda
$ sudo sfdisk -l -uS /dev/sda # Show partition table for device /dev/sda
$ sudo sfdisk -d /dev/sda >sda-sfidk.dump # Dump partition in a format that can be understood by sfdisk
$ sudo sfdisk -d /dev/sda >sda-sfdisk.dump # Dump partition in a format that can be understood by sfdisk
$ sudo sfdisk /dev/sda <sda-sfdisk.dump # Restore a dumped partition table
$ sudo sfdisk /dev/sda <sda-sfdisk.dump # Restore a dumped partition table
$ sudo dd if=/dev/sda of=sda.mbr bs=512 count=1 # Save the complete MBR (table + boot code)
$ sudo dd if=/dev/sda of=sda.mbr bs=512 count=1 # Save the complete MBR (table + boot code)
Line 34: Line 34:
$ sudo sfdisk -R /dev/sda
$ sudo sfdisk -R /dev/sda
</source>
</source>

== Resizing Partitions ==
=== Reiserfs ===
<ol>
<li>Use <tt>resize_reiserfs</tt> to resize the partition, and get the new partition size</li>
<source lang="bash">
resize_reiserfs -s -4G /dev/sda6 #Must be unmount
df
</source>
<li>Change the partition table</li>
<source lang="bash">
sudo sfdisk -d /dev/sda >sda-sfdisk.dump # Edit sda-sfdisk.dump
</source>
<li>Run <tt>reiserfsck</tt></li>
<source lang="bash">
sudo reiserfsck --rebuild-sb
sudo reiserfsck --fix-fixable
</source>
</ol>

Revision as of 01:23, 10 December 2010

References

Partitions

Some CLI software:

  • fdisk
  • sfdisk
  • parted

Some examples:

$ sudo fdisk -l /dev/sda                            # Show partition table for device /dev/sda
$ sudo fdisk -l -u /dev/sda                         # ... using sector as unit
$ sudo parted -l                                    # Show partition table of all devices
$ sudo parted /dev/sda print                        # ... of only device /dev/sda
$ sudo parted /dev/sda unit cyl print               #     ... using cylinder as unit
$ sudo parted /dev/sda unit s print                 #     ... using sector as unit (more accurate)
$ sudo sfdisk -l -uS /dev/sda                       # Show partition table for device /dev/sda
$ sudo sfdisk -d /dev/sda >sda-sfdisk.dump          # Dump partition in a format that can be understood by sfdisk
$ sudo sfdisk /dev/sda <sda-sfdisk.dump             # Restore a dumped partition table
$ sudo dd if=/dev/sda of=sda.mbr bs=512 count=1     # Save the complete MBR (table + boot code)

Use partprobe to force the kernel to re-read the MBR (re-read the partition table, see [1]). Or alternatively one can use fdisk to re-rewrite the same partition and force a re-read. And that are more solutions too ([2]):

$ sudo partprobe
# Or use fdisk
$ sudo fdisk /dev/sda
Command: v
Command: w
# Or use blockdev
$ sudo /sbin/blockdev --rereadpt /dev/hda
# Or use sfdisk
$ sudo sfdisk -R /dev/sda

Resizing Partitions

Reiserfs

  1. Use resize_reiserfs to resize the partition, and get the new partition size
  2. resize_reiserfs -s -4G /dev/sda6               #Must be unmount
    df
    
  3. Change the partition table
  4. sudo sfdisk -d /dev/sda >sda-sfdisk.dump          # Edit sda-sfdisk.dump
    
  5. Run reiserfsck
  6. sudo reiserfsck --rebuild-sb
    sudo reiserfsck --fix-fixable