The exact output from the fdisk and parted commands will vary depending on how your system is equipped and configured.
Solution for exercise 1. Work with fdisk commands
Listing 1 provides the code response:
Listing 1. fdisk commands in interactive modes
[tbost@linux ~]$ sudo fdisk /dev/sdb1 Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): l ... 82 Linux swap / Solaris 83 Linux ... |
The sequence of steps in exercise 1 is as follows:
- As sudo user, use the
fdisk /dev/sdb1command to enterfdiskinteractive mode.Your hard disk mount point may differ.
- In interactive mode, type
mto obtain a listing of available commands.
Solution for exercise 2. Use fdisk to create partitions
Listing 2 shows how to proceed and lists typical output:
Listing 2. Using fdisk to design partitions
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1):
First sector (2048-7831543, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G}
(2048-7831543, default 7831543): +100M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 2):
Using default value 2
First sector (206848-7831543, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G}
(206848-7831543, default 7831543): +2G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 3):
Using default value 3
First sector (4401152-7831543, default 4401152):
Using default value 4401152
Last sector, +sectors or +size{K,M,G}
(4401152-7831543, default 7831543): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First sector (6498304-7831543, default 6498304):
Using default value 6498304
Last sector, +sectors or +size{K,M,G}
(6498304-7831543, default 7831543): +500M
Command (m for help): p
Disk /dev/sdb1: 4009 MB, 4009750528 bytes
124 heads, 62 sectors/track, 1018 cylinders, total 7831544 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: 0x6f20736b
Device Boot Start End Blocks Id System
/dev/sdb1p1 2048 206847 102400 83 Linux
/dev/sdb1p2 206848 4401151 2097152 83 Linux
/dev/sdb1p3 4401152 6498303 1048576 83 Linux
/dev/sdb1p4 6498304 7522303 512000 83 Linux
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 82
Changed system type of partition 4 to 82 (Linux swap / Solaris)
Command (m for help): n
Disk /dev/sdb1: 4009 MB, 4009750528 bytes
124 heads, 62 sectors/track, 1018 cylinders, total 7831544 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: 0x6f20736b
Device Boot Start End Blocks Id System
/dev/sdb1p1 2048 206847 102400 83 Linux
/dev/sdb1p2 206848 4401151 2097152 83 Linux
/dev/sdb1p3 4401152 6498303 1048576 83 Linux
/dev/sdb1p4 6498304 7522303 512000 82 Linux swap / Solaris
Command (m for help): w
|
The sequence of steps in exercise 2 is as follows:
- For each new partition, type
nto create a new partition. - Enter
pfor a primary partition.If you intend to create more than four partitions, type
eat the number 4 partition for extended. The remaining will be logical partitions. - Enter the appropriate partition number (1 through 4 ).
- Accept the default start sector for each partition.
- For the ending sector, enter the appropriate size in either megabytes or
gigabytes, preceded with the plus sign (
+).For example, on partition 1, type
+100M. - Type
tto change a partition file system type. - Enter
4for partition 4, and then82to change toLinux Swap. - Type
wto write to the partition table and exit.
Solution for exercise 3. Use fdisk to toggle bootable flag
Listing 3 shows how to proceed for exercise 3:
Listing 3. Toggle the bootable flag with fdisk
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb1: 4009 MB, 4009750528 bytes
124 heads, 62 sectors/track, 1018 cylinders, total 7831544 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: 0x6f20736b
Device Boot Start End Blocks Id System
/dev/sdb1p1 * 2048 206847 102400 83 Linux
/dev/sdb1p2 206848 4401151 2097152 83 Linux
/dev/sdb1p3 4401152 6498303 1048576 83 Linux
/dev/sdb1p4 6498304 7522303 512000 82 Linux swap / Solaris
Command (m for help):
|
The sequence of steps in exercise 3 is as follows:
- Enter
ato denote that you want to set a bootable flag partition. - Type
1for partition 1. - Type
pto verify the change.
Solution for exercise 4. Work with parted commands
Listing 4 provides the code response:
Listing 4. parted commands in interactive mode
[tbost@linux ~]$ sudo parted /dev/sdb1
GNU Parted 2.3
Using /dev/sdb1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)help
align-check TYPE N check partition N for TYPE(min|opt)
alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on
COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition
table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on
partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
...
...
...
(parted) p
Model: Unknown (unknown)
Disk /dev/sdb1: 4010MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 106MB 105MB primary boot
2 106MB 2253MB 2147MB primary
3 2253MB 3327MB 1074MB primary
4 3327MB 3851MB 524MB primary
|
The sequence of steps in exercise 4 is as follows:
- As sudo user, use the
parted/dev/sdb1command to enterpartedinteractive mode.Your hard disk mount point may differ.
- Type
helpto display available commands.Listing 4 shows a partial list of available commands.
- Type
pto print the partition table to screen.
Solution for exercise 5. Use parted to change the mode of unit display
Listing 5 shows expected inputs and typical outputs:
Listing 5. Unit display in terabytes
(parted) help u unit UNIT set the default unit to UNIT UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %, kiB, MiB, GiB, TiB (parted) u TB (parted)p Model: Unknown (unknown) Disk /dev/sdb1: 0.00TB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 0.00TB 0.00TB 0.00TB primary boot 2 0.00TB 0.00TB 0.00TB primary 3 0.00TB 0.00TB 0.00TB primary 4 0.00TB 0.00TB 0.00TB primary |
The sequence of steps in exercise 5 is as follows:
- Type
help uto display available unit display types. - Type
u TBto change the unit display mode to terabyte. - Enter
pto print the partition table to screen.Listing 5 shows all zeros for
TB, because the hard disk is only 4GB in size. Your display results may differ.