posted on 2016-08-24 20:58
Don't overwrite your devices via
But we've all been there, done that.
If you don't want to reinstall 'just because', an idea might be to use
testdisk depending on what you did.
Getting nice partition layout I tend to use
parted (see below), for creating partitions
cgdisk (for GPT stuff) or
cfdisk (for MBR creation only IIRC) are decent choices.
Back on topic.
Partitions were still present in my cause, so no need create them anew.
If you have to, do
parted /dev/sda p and
parted /dev/sdX u b p and use your phone to make photos, in case you have to redo something.
Create and open the cryptocontainer to hold the complete partition, wherein the LVM and your filesystems will lie.
cryptsetup --cipher=aes-xts-plain64 luksFormat /dev/sdXN --force-password cryptsetup open /dev/sdXN sdXN_crypt
Did you really type an uppercased YES when you were promted? The password you were prompted for is the one you will have to enter in the future.
In case you did something wrong:
cryptsetup close cryptsetup erase /dev/sdaX
Then start by recreating the container. Did you really type an uppercased YES when you were promted?
After the crypto device was opened, you can reference it through the device mapper. Now create the physical volume (PV), volume group (VG) and logical volumes (LV's) where your system will be installed later on:
pvcreate /dev/mapper/sdXN_crypt vgcreate `hostname` /dev/mapper/sdXN_crypt lvcreate -L 2G -n swap `hostname` lvcreate -l 100%FREE -n root `hostname`
Here is a catch: I did not have to recreate a separate
/boot partition, as I already had one.
If you don't create one first.
It has to be located outside the crypto container, else you won't be able too boot after your installation.
If something went wrong, here's how to delete things, too. Choose what you need in particular:
pvremove /dev/sdXN_crypt vgremove `hostname` lvremove /dev/`hostname`/<LVname>
Create root filesystem:
mkfs -t ext4 /dev/mapper/`hostname`-root
This is pretty much it.
From here on you can
chroot or do whatever else you want.
Maybe you only want the container for data but for installing a system on there. In that case not calling the LV 'root' and omitting the swap partition up there would have been a wise choice.
posted on 2014-10-11 15:27:56
Sometimes you have to partition disks by hand.
For some people,
parted is the weapon of choice.
If so, keep in mind you only use it for partitioning.
Filesystems are not implemented and parted may tell you so, too.
Besides you won't get filesystems created by it.
Just use the
mkfs.xxx tools at hand.
It's just sad that half finished programs are distributed...
banana software - it matures in the works of the customer. :(
Back to the posts intention: There are two ways to use
Either via the interactive parted-shell, or directly from the commandline.
Most needed commands in the shell might be:
a = align-check = check alignment to sectors (min or opt as params) p = print = show info for chosen disk sel = select = choose disk (i.e. /dev/sdb) u = unit = measuring of sizes (i.e. %,MB,GB,...) mkl = mklabel = create disk label (i.e. gpt) (mktable = mkt = the same) mkp = mkpart = create partitions rm = remove = delete a partition q = quit = exit parted
An overview on the possible sizes you'd most likely use:
MiB Mebibyte (1048576 bytes) GiB Gibibyte (1073741824 bytes) MB Megabyte (1000000 bytes) GB Gigabyte (1000000000 bytes) % procentual (between 0% and 100%) s sectors (logical sector size)
So usually you would want MiB and GiB, I guess.
Sadly, I haven't found out yet how to optimally align the partition onto the harddisks (so it matches it's sectors best).
For this I actually used to use
parted from the regular bash shell:
parted /dev/sdb mklabel gpt parted -a optimal /dev/sdb unit gb mkpart primary ext4 2 100%
Nowadays I mostly use
parted interactive with procentual parameters.
But for when I don't, here two example workflows
# create a single MBR partition with an ext4 on the usb stick /dev/sdb lsblk -f ## make sure the stick is really on /dev/sdb parted /dev/sdb p ## check whats already on the stick parted /dev/sdb mkl ms y ## create MBR not GPT parted /dev/sdb mkp p 0% 100% ## single primary partition, percentages are used for proper alignment mkfs.ext4 /dev/sdb1 ## create filesystem at last parted /dev/sdb a opt 1 ## check alignment to be optimal for partition 1 # create the same, but with gpt lsblk -f parted /dev/sdb p parted /dev/sdb mkl g y ## create GPT parted /dev/sdb mkp asdf 0% 100% ## creates partition with name 'asdf', a name must be specified, ext4 already on it
It seems that currently creating the filesystem only works when using GPT's, and only ext4's can be created.
But somewhere I heard that it was officially said that you should use
mkfs anyway, and not let
parted create filesystems.
View posts from 2017-05, 2017-04, 2017-03, 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10