Last active
March 21, 2023 08:01
-
-
Save Mausy5043/783b3fcc3b775e658a66087e51bb89b4 to your computer and use it in GitHub Desktop.
Commands used to initialise a harddisk for use on Raspberry Pi (debian)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Connect the harddrive via USB | |
# 2. Find out the allocated device name | |
$ lsblk | |
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT | |
sda 8:0 0 931.5G 0 disk | |
└─sda1 8:1 0 931.5G 0 part | |
mmcblk0 179:0 0 3.8G 0 disk | |
├─mmcblk0p1 179:1 0 128M 0 part /boot | |
└─mmcblk0p2 179:2 0 3.6G 0 part / | |
# ^^^^ note that the device name is /dev/sda | |
# 3. Create a new partition table and add partition(s) | |
$ sudo fdisk /dev/sda | |
# delete all partitions | |
Command (m for help): d | |
Selected partition 1 | |
Partition 1 has been deleted. | |
# create a new GPT partition table | |
Command (m for help): g | |
Created a new GPT disklabel (GUID: 9E9FFB58-63A8-43DB-A0CC-EFE6A5D301A6). | |
# create a new partition (iterate for each next partition | |
Command (m for help): n | |
Partition number (1-128, default 1): ##use default## | |
First sector (2048-1953525134, default 2048): ###use default### | |
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525134, default 1953525134): ###use default or enter size### | |
Created a new partition 1 of type 'Linux filesystem' and of size 931.5 GiB. | |
# display the result | |
Command (m for help): p | |
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 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 | |
Disklabel type: gpt | |
Disk identifier: 9E9FFB58-63A8-43DB-A0CC-EFE6A5D301A6 | |
Device Start End Sectors Size Type | |
/dev/sda1 2048 1953525134 1953523087 931.5G Linux filesystem | |
# write the table to disk | |
Command (m for help): w | |
The partition table has been altered. | |
Calling ioctl() to re-read partition table. | |
Syncing disks. | |
# We can check the partition for badblocks now or we let fsck do it after the filesystem is created or during the fs creation. | |
$ sudo badblocks -nsv /dev/sda -o bad-blocks-sda | |
# -nsv : non-destructive read-write mode; be verbose | |
# -o <file> : dump badblocks to a file | |
# Create a filesystem on the new partition | |
$ sudo mkfs.ext4 -cc /dev/sda1 | |
# -cc read/write test for badblocks | |
# or using the badblocks output file: | |
$ sudo mkfs.ext4 -l bad-blocks-sda /dev/sda | |
# -l <file> : store results in the named file | |
mke2fs 1.42.12 (29-Aug-2014) | |
Creating filesystem with 244190385 4k blocks and 61054976 inodes | |
Filesystem UUID: 48364ce0-9d1e-4a97-ae31-d7fd86cbabd0 | |
Superblock backups stored on blocks: | |
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, | |
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, | |
102400000, 214990848 | |
Allocating group tables: done | |
Writing inode tables: done | |
Creating journal (32768 blocks): done | |
Writing superblocks and filesystem accounting information: done | |
$ sudo fsck -fpv -kcc /dev/sda1 |logger -t fsck -p 7 | |
# -f : force checking | |
# -k : preserve old bad block mappings | |
# -p : automatically repair the fs | |
# -cc: scan for badblocks and map them out. 2nd `c` = Non-destructively. | |
# -v : verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://wiki.archlinux.org/index.php/badblocks