Skip to content

Instantly share code, notes, and snippets.

@jaxxzer
Last active August 29, 2018 23:09
Show Gist options
  • Save jaxxzer/e7564ec27d3d802c7196c01f10424447 to your computer and use it in GitHub Desktop.
Save jaxxzer/e7564ec27d3d802c7196c01f10424447 to your computer and use it in GitHub Desktop.

check the disk

lsblk -f

unmount the disk

umount /dev/sdX?*

fdisk the disk

fdisk /dev/sdX

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Make a new GPT partition table

Command (m for help): g
Created a new GPT disklabel (GUID: B779579E-306A-450F-A9BC-8147FA537086).

make a new partition(1) at the beginning of the disk, 2MB in size

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-7626718, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-7626718, default 7626718): +2M

Created a new partition 1 of type 'Linux filesystem' and of size 2 MiB.

make a new partition(2) at the end of partition(1), 4MB in size

Command (m for help): n
Partition number (2-128, default 2): 
First sector (6144-7626718, default 6144): 
Last sector, +sectors or +size{K,M,G,T,P} (6144-7626718, default 7626718): +4M

Created a new partition 2 of type 'Linux filesystem' and of size 4 MiB.

write the changes

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

check the disk

lsblk -f

make a filesystem on partition(1)

mkfs.ext4 /dev/sdX1

Creating filesystem with 2048 1k blocks and 256 inodes

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

mount partition(1)

mkdir /mnt/p1
mount /dev/sdX1 /mnt/p1

make a file on partition(1)

touch /mnt/p1/testfile

unmount partition(1)

umount /mnt/p1

create an image of partition(1)

dd if=/dev/sdX1 of=p1.img

copy the image of partition(1) to partition(2)

dd if=p1.img of=/dev/sdX2

mount partition(2)

mkdir /mnt/p2
mount /dev/sdX2 /mnt/p2

check the file

ls /mnt/p2

unmount partition(2)

umount /mnt/p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment